Rev 54: Draft based on the sample ppa code Cody provided. in http://people.canonical.com/~robertc/baz2.0/plugins/builder/blocking

Robert Collins robertc at robertcollins.net
Thu Oct 22 06:17:05 BST 2009


At http://people.canonical.com/~robertc/baz2.0/plugins/builder/blocking

------------------------------------------------------------
revno: 54
revision-id: robertc at robertcollins.net-20091022051701-3i7ob17on0uaadds
parent: robertc at robertcollins.net-20091022032456-sos9zvc8e50g0ga1
committer: Robert Collins <robertc at robertcollins.net>
branch nick: blocking
timestamp: Thu 2009-10-22 16:17:01 +1100
message:
  Draft based on the sample ppa code Cody provided.
=== modified file '__init__.py'
--- a/__init__.py	2009-09-25 19:50:30 +0000
+++ b/__init__.py	2009-10-22 05:17:01 +0000
@@ -249,17 +249,23 @@
                 Option("key-id", type=str, short_name="k",
                        help="Sign the packages with the specified GnuPG key, "
                             "must be specified if you use --dput."),
+                Option("watch-ppa", help="Watch the PPA the package was "
+                    "dput to and exit with 0 only if it builds and "
+                    "publishes successfully."),
             ]
 
     takes_args = ["recipe_file", "working_directory?"]
 
     def run(self, recipe_file, working_directory=None, manifest=None,
             if_changed_from=None, package=None, distribution=None,
-            dput=None, key_id=None):
+            dput=None, key_id=None, watch_ppa=False):
 
         if dput is not None and key_id is None:
             raise errors.BzrCommandError("You must specify --key-id if you "
                     "specify --dput.")
+        if not dput and watch_ppa:
+            raise errors.BzrCommandError(
+                "cannot watch a ppa without doing dput.")
 
         base_branch = self._get_branch_from_recipe_file(recipe_file)
         time = datetime.datetime.utcnow()
@@ -297,6 +303,10 @@
                 self._sign_source_package(package_dir, key_id)
             if dput is not None:
                 self._dput_source_package(package_dir, dput)
+                if watch_ppa:
+                    from bzrlib.plugins.builder.ppa import watch
+                    watch(dput, package or recipe_name,
+                        base_branch.deb_version)
             if manifest is not None:
                 self._write_manifest_to_path(manifest, base_branch)
         finally:

=== added file 'ppa.py'
--- a/ppa.py	1970-01-01 00:00:00 +0000
+++ b/ppa.py	2009-10-22 05:17:01 +0000
@@ -0,0 +1,72 @@
+# ppa support for bzr builder.
+#
+# Copyright: Canonical Ltd. (C) 2009
+#
+# This program is free software: you can redistribute it and/or modify it 
+# under the terms of the GNU General Public License version 3, as published 
+# by the Free Software Foundation.
+
+# This program is distributed in the hope that it will be useful, but 
+# WITHOUT ANY WARRANTY; without even the implied warranties of 
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
+# PURPOSE.  See the GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License along 
+# with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from optparse import OptionParser
+import os
+import sys
+import time
+
+from launchpadlib.launchpad import (
+    Launchpad, STAGING_SERVICE_ROOT, EDGE_SERVICE_ROOT)
+from launchpadlib.credentials import Credentials
+
+def watch(target, package_name, version):
+    """Watch a package build.
+
+    :return: True once the package built and published completely ok or False
+        otherwise.
+    """
+    # See https://help.launchpad.net/API
+    credentials = Credentials()
+    oauth_file = os.path.expanduser('~/.cache/edge_oauth.txt')
+    try:
+        credentials.load(open(oauth_file))
+        launchpad = Launchpad(credentials, EDGE_SERVICE_ROOT)
+    except:
+        cachedir = os.path.expanduser("~/.launchpadlib/cache/")
+        launchpad = Launchpad.get_token_and_login('get-build-status', EDGE_SERVICE_ROOT, cachedir)
+        launchpad.credentials.save(file(oauth_file, "w"))
+    
+    try:
+        owner_name, archive_name = target.split('/', 2)
+    except ValueError:
+            print "E: Failed to parse archive identifier."
+            print "Syntax of target archive: <owner>/<archive>"
+            sys.exit(1)
+    
+    owner = launchpad.people[owner_name]
+    archive = owner.getPPAByName(name=archive_name)
+    end_states = ['failedtobuild', 'fullybuilt']
+    while True:
+        sourceRecords = [s for s in
+            archive.getPublishedSources(source_name=package_name)
+            if s.source_package_version == version]
+        if not sourceRecords:
+            time.sleep(60)
+            continue
+        pkg = sourceRecords[0]
+        if pkg.status.lower() not in ('published', 'pending'):
+            time.sleep(60)
+            continue
+        source_id = str(pkg.self).rsplit('/', 1)[1]
+        buildSummaries = archive.getBuildSummariesForSourceIds(
+            source_ids=[source_id])[source_id]
+        print "%s: %s" % (pkg.display_name, buildSummaries['status'])
+        if buildSummaries['status'] in end_states:
+            break
+        time.sleep(60)
+    return (buildSummaries['status'] == 'fullybuilt' and 
+        pkg.status.lower() == 'published')




More information about the bazaar-commits mailing list