]> git.ipfire.org Git - pbs.git/commitdiff
backend: Take a basepath
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Oct 2022 15:19:43 +0000 (15:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Oct 2022 15:19:43 +0000 (15:19 +0000)
The entire filesystem structure will be based on this path, so that we
will be able to create test environments which we can easily destroy
again.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/__init__.py
src/buildservice/constants.py.in
src/buildservice/jobs.py
src/buildservice/packages.py
src/buildservice/repository.py
src/buildservice/uploads.py
tests/test.py

index 0ad5d82acac314037e2474b1281de723aad9a8a5..5b122e631d466e724beee744f6b331e81fdb3f8a 100644 (file)
@@ -52,6 +52,9 @@ class Backend(object):
                # 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)
 
@@ -132,6 +135,12 @@ class Backend(object):
 
                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
@@ -141,7 +150,7 @@ class Backend(object):
 
                # 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
@@ -359,13 +368,13 @@ class Backend(object):
                        "--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)
 
index 96bc2a93ff805a3538c7e3326642780c243c60e3..8014aa6f0ee8c4383ea9b31228c9e61f3c282ad7 100644 (file)
@@ -13,13 +13,6 @@ LOCALEDIR    = "@localedir@"
 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 = (
index dc5b41a3cd1db90668962fb45ce21f5cec7e7789..9b74f4b9a74c8e1ef292dd623cd12c9bc2ffee82 100644 (file)
@@ -300,7 +300,8 @@ class Job(base.DataObject):
 
                # 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)
 
@@ -348,8 +349,8 @@ class Job(base.DataObject):
 
        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],
index 506778845a4cf4982b33049213888998902ef5a8..f5985e1ed0f652806672586547ff845142782efb 100644 (file)
@@ -355,8 +355,8 @@ class Package(base.DataObject):
                        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:],
index baa17c53627f1e96e25e2893bdfd7edccffcebf4..506eda8713fba5aa79ce7af9fc3245654bde0848 100644 (file)
@@ -260,10 +260,7 @@ class Repository(base.DataObject):
                """
                        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)
index 64c1eef77c5a0f1483155b2fdd931b1bf0e50fb5..52ad35d597074a2317b4c307cf9dff09aa972c5c 100644 (file)
@@ -38,7 +38,9 @@ class Uploads(base.Object):
                """
                        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
index c7359215a887c1987646e25f40da94c54ea26c37..22ebf5e0ba54155ce5cb987c89c35c40a94fbd3a 100644 (file)
@@ -62,9 +62,17 @@ class TestCase(unittest.IsolatedAsyncioTestCase):
                }
 
        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()
 
@@ -84,6 +92,15 @@ class TestCase(unittest.IsolatedAsyncioTestCase):
                # 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