# Read configuration file.
self.config = self.read_config(config_file)
+ # Fetch the base path
+ self.basepath = self.config.get("DEFAULT", "basepath") or "/pub/pakfire"
+
# Global pakfire settings (from database).
self.settings = settings.Settings(self)
return database.Connection(hostname, name, user=user, password=password)
+ def path(self, *args):
+ """
+ Takes a relative path and makes it absolute
+ """
+ return os.path.join(self.basepath, *args)
+
def path_to_url(self, path):
"""
Takes a path to a file on the file system and converts it into a URL
# Path to package
path = os.path.join(
- "files", os.path.relpath(path, PAKFIRE_DIR),
+ "files", os.path.relpath(path, self.basepath),
)
# Join it all together
"--delay-updates",
# Add source & target
- "%s/" % PAKFIRE_DIR,
+ "%s/" % self.basepath,
target,
]
# Add all mirrored repositories
for repo in self.repos.mirrored:
- path = os.path.relpath(repo.local_path(), PAKFIRE_DIR)
+ path = os.path.relpath(repo.local_path(), self.basepath)
commandline.append("--include=%s***" % path)
TEMPLATESDIR = "@templatesdir@"
STATICDIR = "@staticdir@"
-PAKFIRE_DIR = "/pub/pakfire"
-LOGS_DIR = os.path.join(PAKFIRE_DIR, "logs")
-PACKAGES_DIR = os.path.join(PAKFIRE_DIR, "packages")
-REPOS_DIR = os.path.join(PAKFIRE_DIR, "repos")
-SOURCES_DIR = os.path.join(PAKFIRE_DIR, "sources")
-UPLOADS_DIR = os.path.join(PAKFIRE_DIR, "tmp/uploads")
-
BUFFER_SIZE = 1024 * 100 # 100kb
FILE_EXTENSIONS_VIEWABLE = (
# Remove all logfiles
for logfile in self.logfiles:
- self.backend.delete_file(os.path.join(PACKAGES_DIR, logfile.path))
+ path = self.backend.path("packages", logfile.path)
+ self.backend.delete_file(path)
self.db.execute("DELETE FROM logfiles WHERE job_id = %s", self.id)
async def _import_log(self, upload):
# Create some destination path
- path = os.path.join(
- LOGS_DIR,
+ path = self.backend.path(
+ "logs",
"jobs",
self.uuid[0:2],
self.uuid[2:4],
Imports the package into the filesystem
"""
# Determine the new path
- path = os.path.join(
- PACKAGES_DIR,
+ path = self.backend.path(
+ "packages",
self.uuid[0:2],
self.uuid[2:4],
self.uuid[4:],
"""
Path to the repository
"""
- path = os.path.join(
- REPOS_DIR,
- self.path,
- )
+ path = self.backend.path("repos", self.path)
if arch:
path = os.path.join(path, arch)
"""
Returns a file handle which can be used to write temporary data to.
"""
- return tempfile.NamedTemporaryFile(dir=UPLOADS_DIR, delete=False)
+ path = self.backend.path("tmp", "uploads")
+
+ return tempfile.NamedTemporaryFile(dir=path, delete=False)
def create(self, filename, path, size=None, builder=None, user=None):
# Check if either builder or user are set
}
async def asyncSetUp(self):
+ # Create a new temporary directory
+ self.testdir = tempfile.TemporaryDirectory()
+
# Create a configuration file
conf = configparser.ConfigParser()
+ # Set the base path
+ conf["DEFAULT"] = {
+ "basepath" : self.testdir.name,
+ }
+
# Setup the database
conf["database"] = self._setup_database()
# Create some default objects
await self._create_default_objects()
+ async def asyncTearDown(self):
+ # Dump a listing of all temporary files
+ with os.scandir(self.testdir.name) as listing:
+ for entry in sorted(listing):
+ print(" %s" % entry.path)
+
+ # Removing any temporary files
+ self.testdir.cleanup()
+
async def _create_default_objects(self):
"""
Creates some random objects that are created by default so