]> git.ipfire.org Git - pakfire.git/commitdiff
Another bunch of changes of the communication betweeen the master server and the...
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 16 Apr 2011 14:27:34 +0000 (16:27 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 16 Apr 2011 14:27:34 +0000 (16:27 +0200)
pakfire/cli.py
pakfire/server/master.py

index a860e1c93686aef9126cf951bc76427e37a2ca3a..ecc03d63054b966d777123eb300ae1d7a094290f 100644 (file)
@@ -442,6 +442,7 @@ 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.
@@ -450,9 +451,16 @@ 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",
@@ -462,6 +470,9 @@ 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 9b911f33fb33067b9374a9d63e7daec40d53820c..c465ed9daef29bcaccf33b8bfd7f1e1db63c9b6b 100644 (file)
@@ -66,7 +66,7 @@ class Source(object):
        def _git_checkout_revision(self, revision):
                self._git("checkout %s" % revision)
 
-       def update_revision(self, (revision, merge)):
+       def update_revision(self, (revision, merge), **pakfire_args):
                if not merge:
                        self._git_checkout_revision(revision)
 
@@ -74,12 +74,13 @@ class Source(object):
                        # the previous one.
                        files = self._git_changed_files("HEAD^", "HEAD")
 
-                       self.update_files([f for f in files if f.endswith(".%s" % MAKEFILE_EXTENSION)])
+                       self.update_files([f for f in files if f.endswith(".%s" % MAKEFILE_EXTENSION)],
+                               **pakfire_args)
 
                # Send update to the server.
                self.master.update_revision(self, revision)
 
-       def update_files(self, files):
+       def update_files(self, files, **pakfire_args):
                rnd = random.randint(0, 1024**2)
                tmpdir = "/tmp/pakfire-source-%s" % rnd
 
@@ -98,7 +99,7 @@ class Source(object):
 
                # XXX This totally ignores the local configuration.
                for pkg in pkgs:
-                       pakfire.api.dist(pkg, resultdirs=[tmpdir,])
+                       pakfire.api.dist(pkg, resultdirs=[tmpdir,], **pakfire_args)
 
                # Create a kind of dummy repository to link the packages against it.
                repo = repository.LocalSourceRepository(self.pakfire,
@@ -125,8 +126,17 @@ class Source(object):
                if not self.revision:
                        self.update_all()
 
-               for rev in self._git_rev_list():
-                       self.update_revision(rev)
+               # Update the revisions on the server.
+               for revision, merge in self._git_rev_list():
+                       if merge:
+                               continue
+
+                       logging.info("Sending revision to server: %s" % revision)
+                       self.master.conn.source_add_revision(self.id, revision)
+
+               # Get all pending revisions from the server and process them.
+               #for rev in self.master.conn.source_get_pending_revisions(self.id):
+               #       self.update_revision(rev)
 
        def update_all(self):
                _files = []
@@ -158,6 +168,18 @@ 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)