]> git.ipfire.org Git - pakfire.git/commitdiff
Merge branch 'master' of ssh://git.ipfire.org/pub/git/oddments/pakfire
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Apr 2011 10:49:40 +0000 (12:49 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Apr 2011 10:49:40 +0000 (12:49 +0200)
pakfire/api.py
pakfire/base.py
pakfire/builder.py
pakfire/cli.py
pakfire/server/base.py
pakfire/server/master.py
pakfire/server/slave.py
po/pakfire.pot

index ff6a070fa810140b63cb2037fb1b58ded2b31a21..6757e52f662468034df292066de6391ebb92f272 100644 (file)
@@ -47,8 +47,8 @@ def build(pkg, **kwargs):
 def shell(pkg, **kwargs):
        return Pakfire.shell(pkg, **kwargs)
 
-def dist(pkg, **kwargs):
-       return Pakfire.dist(pkg, **kwargs)
+def dist(pkgs, **kwargs):
+       return Pakfire.dist(pkgs, **kwargs)
 
 def provides(patterns, **pakfire_args):
        # Create pakfire instance.
index 79caf70934e0fba3d9705715d8121fe6bc8583ac..6412a842801792c87c6f6fe302fe30dcc069ae7a 100644 (file)
@@ -214,8 +214,9 @@ class Pakfire(object):
                        b.destroy()
 
        @staticmethod
-       def dist(pkg, resultdirs=None, **pakfire_args):
-               b = builder.Builder(pkg, **pakfire_args)
+       def dist(pkgs, resultdirs=None, **pakfire_args):
+               # Create a builder with empty package.
+               b = builder.Builder(None, **pakfire_args)
                p = b.pakfire
 
                if not resultdirs:
@@ -226,17 +227,24 @@ class Pakfire(object):
 
                try:
                        b.prepare()
-                       b.extract(build_deps=False)
 
-                       # Run the actual dist.
-                       b.dist()
+                       for pkg in pkgs:
+                               b.pkg = pkg
 
-                       # Copy-out all resultfiles
-                       for resultdir in resultdirs:
-                               if not resultdir:
-                                       continue
+                               b.extract(build_deps=False)
 
-                               b.copy_result(resultdir)
+                               # Run the actual dist.
+                               b.dist()
+
+                               # Copy-out all resultfiles
+                               for resultdir in resultdirs:
+                                       if not resultdir:
+                                               continue
+
+                                       b.copy_result(resultdir)
+
+                               # Cleanup the stuff that the package left.
+                               b.cleanup()
                finally:
                        b.destroy()
 
index 0802dbeb9a6e138211a1aa844dfc300843bb1fcc..d69be2938971a26473192f2c8476cd92af38d559 100644 (file)
@@ -29,7 +29,7 @@ class Builder(object):
        # The version of the kernel this machine is running.
        kernel_version = os.uname()[2]
 
-       def __init__(self, pkg, distro_config=None, build_id=None, **pakfire_args):
+       def __init__(self, pkg=None, distro_config=None, build_id=None, **pakfire_args):
                pakfire_args.update({
                        "builder" : True,
                })
@@ -40,16 +40,7 @@ class Builder(object):
                self.path = self.pakfire.path
 
                # Open the package.
-               if pkg:
-                       self.pkg = packages.open(self.pakfire, None, pkg)
-
-                       # Log the package information.
-                       if not isinstance(self.pkg, packages.Makefile):
-                               dump = self.pkg.dump(long=True)
-                               self.log.info(dump)
-               else:
-                       # No package was given.
-                       self.pkg = None
+               self.pkg = pkg
 
                # XXX need to make this configureable
                self.settings = {
@@ -74,6 +65,25 @@ class Builder(object):
 
                self.build_id = build_id
 
+       def get_pkg(self):
+               return getattr(self, "_pkg", None)
+
+       def set_pkg(self, pkg):
+               if pkg is None:
+                       self.__pkg = None
+                       return
+
+               self._pkg = packages.open(self.pakfire, None, pkg)
+
+               # Log the package information.
+               if not isinstance(self._pkg, packages.Makefile):
+                       dump = self._pkg.dump(long=True)
+                       self.log.info(dump)
+
+               assert self.pkg
+
+       pkg = property(get_pkg, set_pkg)
+
        @property
        def arch(self):
                """
index ecc03d63054b966d777123eb300ae1d7a094290f..a7f8d7e764ff0b9e0ac8f20dadea68dda2ee9087 100644 (file)
@@ -385,9 +385,8 @@ class CliBuilder(Cli):
                        else:
                                raise FileNotFoundError, pkg
 
-               for pkg in pkgs:
-                       pakfire.dist(pkg, resultdirs=[self.args.resultdir,],
-                               **self.pakfire_args)
+               pakfire.dist(pkgs, resultdirs=[self.args.resultdir,],
+                       **self.pakfire_args)
 
 
 class CliRepo(Cli):
@@ -442,7 +441,6 @@ class CliMaster(Cli):
                # Add sub-commands.
                self.sub_commands = self.parser.add_subparsers()
 
-               self.parse_command_build()
                self.parse_command_update()
 
                # Finally parse all arguments from the command line and save them.
@@ -451,16 +449,9 @@ class CliMaster(Cli):
                self.master = server.master.Master()
 
                self.action2func = {
-                       "build"       : self.handle_build,
                        "update"      : self.handle_update,
                }
 
-       def parse_command_build(self):
-               # Implement the "build" command.
-               sub_build = self.sub_commands.add_parser("build",
-                       help=_("Build one or more packages."))
-               sub_build.add_argument("action", action="store_const", const="build")
-
        def parse_command_update(self):
                # Implement the "update" command.
                sub_update = self.sub_commands.add_parser("update",
@@ -470,9 +461,6 @@ class CliMaster(Cli):
        def handle_update(self):
                self.master.update_sources()
 
-       def handle_build(self):
-               self.master.build()
-
 
 class CliSlave(Cli):
        def __init__(self):
index 2df0e72b14890a85b16e5ac93cf6f034216204a9..9490dce18c5e8442c61026d1b007466f049f2aa8 100644 (file)
@@ -85,3 +85,27 @@ class MasterSlave(object):
 
        def upload_log_file(self):
                pass # XXX TO BE DONE
+
+       def package_add(self, source, pkg):
+               logging.info("Adding package: %s" % pkg.friendly_name)
+
+               # Collect data that is sent to the database...
+               info = {
+                       "name"             : pkg.name,
+                       "epoch"            : pkg.epoch,
+                       "version"          : pkg.version,
+                       "release"          : pkg.release,
+                       "groups"           : " ".join(pkg.groups),
+                       "maintainer"       : pkg.maintainer,
+                       "license"          : pkg.license,
+                       "url"              : pkg.url,
+                       "summary"          : pkg.summary,
+                       "description"      : pkg.description,
+                       "supported_arches" : pkg.supported_arches,
+                       "source_id"        : source.id,
+               }
+
+               return self.conn.package_add(info)
+
+       def package_remove(self, source, pkg):
+               logging.info("Package '%s' has been removed." % pkg)
index c465ed9daef29bcaccf33b8bfd7f1e1db63c9b6b..faa8829dbebf46fc777080bb2b4c893335cc404f 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import logging
+import hashlib
 import os
 import random
 import shutil
@@ -19,21 +20,46 @@ from pakfire.constants import *
 from base import MasterSlave
 
 class Source(object):
-       def __init__(self, master, id, name, path, targetpath, revision, branch):
+       def __init__(self, master, id, name, url, path, targetpath, revision, branch):
                self.master = master
                self.id = id
                self.name = name
-               self.path = path
+               self.url = url
                self.targetpath = targetpath
                self.revision = revision
                self.branch = branch
 
+               # If the repository is not yet checked out, we create a local clone
+               # from it to work with it.
+               if not os.path.exists(self.path):
+                       dirname = os.path.dirname(self.path)
+                       basename = os.path.basename(self.path)
+
+                       if not os.path.exists(dirname):
+                               os.makedirs(dirname)
+
+                       self._git("clone %s %s" % (self.url, basename), path=dirname)
+
+               else:
+                       # Always refresh the repository to have the recent commits.
+                       self._git("fetch")
+
+       @property
+       def path(self):
+               h = hashlib.sha1(self.url)
+
+               # XXX path is to be changed
+               return "/var/cache/pakfire/sources/%s" % h.hexdigest()
+
        @property
        def pakfire(self):
                return self.master.pakfire
 
-       def _git(self, cmd):
-               cmd = "cd %s; git %s" % (self.path, cmd)
+       def _git(self, cmd, path=None):
+               if not path:
+                       path = self.path
+
+               cmd = "cd %s && git %s" % (path, cmd)
 
                logging.debug("Running command: %s" % cmd)
 
@@ -78,7 +104,7 @@ class Source(object):
                                **pakfire_args)
 
                # Send update to the server.
-               self.master.update_revision(self, revision)
+               #self.master.update_revision(self, revision)
 
        def update_files(self, files, **pakfire_args):
                rnd = random.randint(0, 1024**2)
@@ -98,8 +124,7 @@ class Source(object):
                        return
 
                # XXX This totally ignores the local configuration.
-               for pkg in pkgs:
-                       pakfire.api.dist(pkg, resultdirs=[tmpdir,], **pakfire_args)
+               pakfire.api.dist(pkgs, resultdirs=[tmpdir,], **pakfire_args)
 
                # Create a kind of dummy repository to link the packages against it.
                repo = repository.LocalSourceRepository(self.pakfire,
@@ -118,9 +143,6 @@ class Source(object):
                util.rm(tmpdir)
 
        def update(self):
-               # Update files from server.
-               self._git("fetch")
-
                # If there has been no data, yet we need to import all packages
                # that are currently checked out.
                if not self.revision:
@@ -168,42 +190,5 @@ class Master(MasterSlave):
 
                        source.update()
 
-       def build(self):
-               build = self.conn.build_job(self.hostname)
-
-               if not build:
-                       return
-
-               print build
-
-               source = Source(self, **build["source"])
-
-               source.update_revision((build["revision"], False), build_id=build["id"])
-
        def update_revision(self, source, revision):
                self.conn.sources_update_revision(source.id, revision)
-
-       def package_add(self, source, pkg):
-               logging.info("Adding package: %s" % pkg.friendly_name)
-
-               # Collect data that is sent to the database...
-               info = {
-                       "name"             : pkg.name,
-                       "epoch"            : pkg.epoch,
-                       "version"          : pkg.version,
-                       "release"          : pkg.release,
-                       "groups"           : " ".join(pkg.groups),
-                       "maintainer"       : pkg.maintainer,
-                       "license"          : pkg.license,
-                       "url"              : pkg.url,
-                       "summary"          : pkg.summary,
-                       "description"      : pkg.description,
-                       "supported_arches" : pkg.supported_arches,
-                       "source_id"        : source.id,
-               }
-
-               return self.conn.package_add(info)
-
-       def package_remove(self, source, pkg):
-               logging.info("Package '%s' has been removed." % pkg)
-
index cb86b4e794ad4ddb71cd615477062d3d0f2100e4..8fde679e09a0fdc3a22132b9af0e0f0ddaa82513 100644 (file)
@@ -3,6 +3,7 @@
 import logging
 import os
 import socket
+import tempfile
 import xmlrpclib
 
 import pakfire.api
@@ -14,6 +15,7 @@ import pakfire.util
 from pakfire.constants import *
 
 from base import MasterSlave
+from master import Source
 
 class Slave(MasterSlave):
        def __init__(self, **pakfire_args):
@@ -50,39 +52,71 @@ class Slave(MasterSlave):
                if not build:
                        return
 
-               build_id = build["id"]
+               print build
+
+               job_types = {
+                       "binary" : self.build_binary_job,
+                       "source" : self.build_source_job,
+               }
+
+               build_id   = build["id"]
+               build_type = build["type"]
+
+               try:
+                       func = job_types[build_type]
+               except KeyError:
+                       raise Exception, "Build type not supported: %s" % type
+
+               # Call the function that processes the build and try to catch general
+               # exceptions and report them to the server.
+               # If everything goes okay, we tell this the server, too.
+               try:
+                       func(build_id, build)
+
+               except Exception, e:
+                       message = "%s: %s" % (e.__class__.__name__, e)
+                       self.update_build_status(build_id, "failed", message)
+                       raise
+
+               else:
+                       self.update_build_status(build_id, "finished")
+
+       def build_binary_job(self, build_id, build):
                filename = build["name"]
-               data     = build["data"].data
+               download = build["download"]
                hash1    = build["hash1"]
 
-               # XXX need to find a better temp dir.
-               tempfile = os.path.join("/var/tmp", filename)
-               resultdir = os.path.join("/var/tmp", build_id)
+               # Create a temporary file and a directory for the resulting files.
+               tmpdir = tempfile.mkdtemp()
+               tmpfile = os.path.join(tmpdir, filename)
+
+               # Get a package grabber and add mirror download capabilities to it.
+               grabber = pakfire.downloader.PackageDownloader()
 
                try:
+                       # Download the source.
+                       grabber.urlgrab(download, filename=tmpfile)
+
                        # Check if the download checksum matches.
-                       if pakfire.util.calc_hash1(data=data) == hash1:
+                       if pakfire.util.calc_hash1(tmpfile) == hash1:
                                print "Checksum matches: %s" % hash1
                        else:
                                raise DownloadError, "Download was corrupted"
 
-                       # Save the data to a temporary directory.
-                       f = open(tempfile, "wb")
-                       f.write(data)
-                       f.close()
-
                        # Update the build status on the server.
                        self.update_build_status(build_id, "running")
 
                        # Run the build.
-                       pakfire.api.build(tempfile, build_id=build_id,
-                               resultdirs=[resultdir,])
+                       pakfire.api.build(tmpfile, build_id=build_id,
+                               resultdirs=[tmpdir,])
 
                        self.update_build_status(build_id, "uploading")
 
-                       for dir, subdirs, files in os.walk(resultdir):
+                       for dir, subdirs, files in os.walk(tmpdir):
                                for file in files:
                                        file = os.path.join(dir, file)
+                                       if file == tmpfile:
+                                               continue
 
                                        pkg = pakfire.packages.open(self.pakfire, None, file)
 
@@ -92,14 +126,14 @@ class Slave(MasterSlave):
                        message = "%s: %s" % (e.__class__.__name__, e)
                        self.update_build_status(build_id, "dependency_error", message)
 
-               except Exception, e:
-                       message = "%s: %s" % (e.__class__.__name__, e)
-                       self.update_build_status(build_id, "failed", message)
-                       raise
+               finally:
+                       # Cleanup the files we created.
+                       pakfire.util.rm(tmpdir)
 
-               else:
-                       self.update_build_status(build_id, "finished")
+       def build_source_job(self, build_id, build):
+               # Update the build status on the server.
+               self.update_build_status(build_id, "running")
 
-               finally:
-                       #pakfire.util.rm(tempfile)
-                       pass
+               source = Source(self, **build["source"])
+
+               source.update_revision((build["revision"], False), build_id=build_id)
index 176e4d3f08b222a1ae6fbb835aa9db29c79072f4..b16a365c5b1639a9cc3064ecb00c2cf7308fb901 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-04-13 21:57+0200\n"
+"POT-Creation-Date: 2011-04-23 12:44+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -21,7 +21,7 @@ msgstr ""
 msgid "Is this okay?"
 msgstr ""
 
-#: ../pakfire/builder.py:198
+#: ../pakfire/builder.py:208
 #, python-format
 msgid "Extracting: %s (source)"
 msgstr ""
@@ -179,43 +179,43 @@ msgstr ""
 msgid "Give name(s) of a package(s)."
 msgstr ""
 
-#: ../pakfire/cli.py:396
+#: ../pakfire/cli.py:395
 msgid "Pakfire repo command line interface."
 msgstr ""
 
-#: ../pakfire/cli.py:415
+#: ../pakfire/cli.py:414
 msgid "Repository management commands."
 msgstr ""
 
-#: ../pakfire/cli.py:423
+#: ../pakfire/cli.py:422
 msgid "Create a new repository index."
 msgstr ""
 
-#: ../pakfire/cli.py:424
+#: ../pakfire/cli.py:423
 msgid "Path to the packages."
 msgstr ""
 
-#: ../pakfire/cli.py:425
+#: ../pakfire/cli.py:424
 msgid "Path to input packages."
 msgstr ""
 
-#: ../pakfire/cli.py:437
+#: ../pakfire/cli.py:436
 msgid "Pakfire master command line interface."
 msgstr ""
 
-#: ../pakfire/cli.py:459
+#: ../pakfire/cli.py:458
 msgid "Update the sources."
 msgstr ""
 
-#: ../pakfire/cli.py:469
+#: ../pakfire/cli.py:468
 msgid "Pakfire slave command line interface."
 msgstr ""
 
-#: ../pakfire/cli.py:493
+#: ../pakfire/cli.py:492
 msgid "Request a build job from the server."
 msgstr ""
 
-#: ../pakfire/cli.py:499
+#: ../pakfire/cli.py:498
 msgid "Send a keepalive to the server."
 msgstr ""