From 92edc2a33e9e53ae0d8a4e46f5a83353d61988c7 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 8 Sep 2012 09:39:39 +0100 Subject: [PATCH] Updated to new 0install API --- 0release | 14 ++++++++------ 0release.xml | 2 +- release.py | 44 ++++++++++++++++++++++---------------------- scm.py | 4 ++-- setup.py | 8 ++++---- support.py | 12 +++++++----- 6 files changed, 44 insertions(+), 40 deletions(-) diff --git a/0release b/0release index 618ee55..e45e079 100755 --- a/0release +++ b/0release @@ -11,7 +11,7 @@ if zi is not None: # (and we want our setup.py, not 0install's) sys.path.insert(1, zi) from zeroinstall import SafeException -from zeroinstall.injector import reader, model +from zeroinstall.injector import reader, model, qdom version = '0.13' @@ -64,21 +64,23 @@ if len(args) != 1: parser.print_help() sys.exit(1) -local_feed_path = args[0] +local_feed_path = os.path.abspath(args[0]) try: if not os.path.exists(local_feed_path): raise SafeException("Local feed file '%s' does not exist" % local_feed_path) - iface = model.Interface(model.canonical_iface_uri(local_feed_path)) - reader.update(iface, local_feed_path, local = True) + with open(local_feed_path, 'rb') as stream: + root = qdom.parse(stream) + + feed = model.ZeroInstallFeed(root, local_path = local_feed_path) if options.release: import release - release.do_release(iface, options) + release.do_release(feed, options) else: import setup - setup.init_releases_directory(iface) + setup.init_releases_directory(feed) except KeyboardInterrupt, ex: print >>sys.stderr, "Interrupted" sys.exit(1) diff --git a/0release.xml b/0release.xml index ffb1ce7..ed1ba10 100644 --- a/0release.xml +++ b/0release.xml @@ -34,7 +34,7 @@ - + diff --git a/release.py b/release.py index 865cc46..38f2e67 100644 --- a/release.py +++ b/release.py @@ -127,28 +127,28 @@ def upload_archives(options, status, uploads): if 'N' in new_stat and cmd: raw_input('Press Return to try again.') -def do_release(local_iface, options): +def do_release(local_feed, options): assert options.master_feed_file options.master_feed_file = os.path.abspath(options.master_feed_file) if not options.archive_dir_public_url: raise SafeException("Downloads directory not set. Edit the 'make-release' script and try again.") - if not local_iface.feed_for: - raise SafeException("Feed %s missing a element" % local_iface.uri) + if not local_feed.feed_for: + raise SafeException("Feed %s missing a element" % local_feed.local_path) status = support.Status() - local_impl = support.get_singleton_impl(local_iface) + local_impl = support.get_singleton_impl(local_feed) local_impl_dir = local_impl.id assert local_impl_dir.startswith('/') local_impl_dir = os.path.realpath(local_impl_dir) assert os.path.isdir(local_impl_dir) - assert local_iface.uri.startswith(local_impl_dir + '/') + assert local_feed.local_path.startswith(local_impl_dir + '/') # From the impl directory to the feed # NOT relative to the archive root (in general) - local_iface_rel_path = local_iface.uri[len(local_impl_dir) + 1:] + local_iface_rel_path = local_feed.local_path[len(local_impl_dir) + 1:] assert not local_iface_rel_path.startswith('/') assert os.path.isfile(os.path.join(local_impl_dir, local_iface_rel_path)) @@ -157,7 +157,7 @@ def do_release(local_iface, options): phase_actions[phase] = [] # List of elements add_toplevel_dir = None - release_management = local_iface.get_metadata(XMLNS_RELEASE, 'management') + release_management = local_feed.get_metadata(XMLNS_RELEASE, 'management') if len(release_management) == 1: info("Found element.") release_management = release_management[0] @@ -165,21 +165,21 @@ def do_release(local_iface, options): if x.uri == XMLNS_RELEASE and x.name == 'action': phase = x.getAttribute('phase') if phase not in valid_phases: - raise SafeException("Invalid action phase '%s' in local feed %s. Valid actions are:\n%s" % (phase, local_iface.uri, '\n'.join(valid_phases))) + raise SafeException("Invalid action phase '%s' in local feed %s. Valid actions are:\n%s" % (phase, local_feed.local_path, '\n'.join(valid_phases))) phase_actions[phase].append(x.content) elif x.uri == XMLNS_RELEASE and x.name == 'add-toplevel-directory': - add_toplevel_dir = local_iface.get_name() + add_toplevel_dir = local_feed.get_name() else: warn("Unknown element: %s", x) elif len(release_management) > 1: - raise SafeException("Multiple sections in %s!" % local_iface) + raise SafeException("Multiple sections in %s!" % local_feed) else: info("No element found in local feed.") - scm = get_scm(local_iface, options) + scm = get_scm(local_feed, options) # Path relative to the archive / SCM root - local_iface_rel_root_path = local_iface.uri[len(scm.root_dir) + 1:] + local_iface_rel_root_path = local_feed.local_path[len(scm.root_dir) + 1:] def run_hooks(phase, cwd, env): info("Running hooks for phase '%s'" % phase) @@ -205,7 +205,7 @@ def do_release(local_iface, options): run_hooks('commit-release', cwd = working_copy, env = {'RELEASE_VERSION': release_version}) print "Releasing version", release_version - support.publish(local_iface.uri, set_released = 'today', set_version = release_version) + support.publish(local_feed.local_path, set_released = 'today', set_version = release_version) support.backup_if_exists(release_version) os.mkdir(release_version) @@ -218,7 +218,7 @@ def do_release(local_iface, options): def set_to_snapshot(snapshot_version): assert snapshot_version.endswith('-post') - support.publish(local_iface.uri, set_released = '', set_version = snapshot_version) + support.publish(local_feed.local_path, set_released = '', set_version = snapshot_version) scm.commit('Start development series %s' % snapshot_version, branch = TMP_BRANCH_NAME, parent = TMP_BRANCH_NAME) status.new_snapshot_version = scm.get_head_revision() status.save() @@ -228,7 +228,7 @@ def do_release(local_iface, options): raise SafeException("Master feed file not set! Check your configuration") scm.ensure_committed() - scm.ensure_versioned(os.path.abspath(local_iface.uri)) + scm.ensure_versioned(os.path.abspath(local_feed.local_path)) info("No uncommitted changes. Good.") # Not needed for GIT. For SCMs where tagging is expensive (e.g. svn) this might be useful. #run_unit_tests(local_impl) @@ -345,8 +345,8 @@ def do_release(local_iface, options): upload_archives(options, status, uploads) - assert len(local_iface.feed_for) == 1 - feed_base = os.path.dirname(local_iface.feed_for.keys()[0]) + assert len(local_feed.feed_for) == 1 + feed_base = os.path.dirname(list(local_feed.feed_for)[0]) feed_files = [options.master_feed_file] print "Upload %s into %s" % (', '.join(feed_files), feed_base) cmd = options.master_feed_upload_command.strip() @@ -367,9 +367,9 @@ def do_release(local_iface, options): if status.head_before_release: head = scm.get_head_revision() if status.release_version: - print "RESUMING release of %s %s" % (local_iface.get_name(), status.release_version) + print "RESUMING release of %s %s" % (local_feed.get_name(), status.release_version) elif head == status.head_before_release: - print "Restarting release of %s (HEAD revision has not changed)" % local_iface.get_name() + print "Restarting release of %s (HEAD revision has not changed)" % local_feed.get_name() else: raise SafeException("Something went wrong with the last run:\n" + "HEAD revision for last run was " + status.head_before_release + "\n" + @@ -377,7 +377,7 @@ def do_release(local_iface, options): "You should revert your working copy to the previous head and try again.\n" + "If you're sure you want to release from the current head, delete '" + support.release_status_file + "'") else: - print "Releasing", local_iface.get_name() + print "Releasing", local_feed.get_name() ensure_ready_to_release() @@ -407,7 +407,7 @@ def do_release(local_iface, options): # May be needed by the upload command os.environ['RELEASE_VERSION'] = status.release_version - archive_name = support.make_archive_name(local_iface.get_name(), status.release_version) + archive_name = support.make_archive_name(local_feed.get_name(), status.release_version) archive_file = archive_name + '.tar.bz2' export_prefix = archive_name @@ -518,7 +518,7 @@ def do_release(local_iface, options): while True: choice = support.get_choice(['Publish', 'Fail'] + maybe_diff) if choice == 'Diff': - previous_archive_name = support.make_archive_name(local_iface.get_name(), previous_release) + previous_archive_name = support.make_archive_name(local_feed.get_name(), previous_release) previous_archive_file = '../%s/%s.tar.bz2' % (previous_release, previous_archive_name) # For archives created by older versions of 0release diff --git a/scm.py b/scm.py index 1c70d77..1a8e96d 100644 --- a/scm.py +++ b/scm.py @@ -155,8 +155,8 @@ class GIT(SCM): def has_submodules(self): return os.path.isfile(os.path.join(self.root_dir, '.gitmodules')) -def get_scm(local_iface, options): - start_dir = os.path.dirname(os.path.abspath(local_iface.uri)) +def get_scm(local_feed, options): + start_dir = os.path.dirname(os.path.abspath(local_feed.local_path)) current = start_dir while True: if os.path.exists(os.path.join(current, '.git')): diff --git a/setup.py b/setup.py index 6892c6b..6b8f4a0 100644 --- a/setup.py +++ b/setup.py @@ -10,14 +10,14 @@ release_uri = 'http://0install.net/2007/interfaces/0release.xml' umask = os.umask(0) os.umask(umask) -def init_releases_directory(iface): +def init_releases_directory(feed): files = os.listdir('.') if files: raise SafeException("This command must be run from an empty directory!\n(this one contains %s)" % (', '.join(files[:5]))) - print "Setting up releases directory for %s" % iface.get_name() + print "Setting up releases directory for %s" % feed.get_name() - master_feed_name = iface.get_name().replace(' ', '-') + '.xml' + master_feed_name = feed.get_name().replace(' ', '-') + '.xml' make_release = file('make-release', 'w') make_release.write("""#!/bin/sh @@ -60,7 +60,7 @@ exec 0launch %s --release %s \\ --master-feed-upload-command="$MASTER_FEED_UPLOAD_COMMAND" \\ --public-scm-repository="$PUBLIC_SCM_REPOSITORY" \\ "$@" -""" % (master_feed_name, release_uri, iface.uri)) +""" % (master_feed_name, release_uri, feed.local_path)) make_release.close() os.chmod('make-release', 0775 & ~umask) print "Success - created script:\n %s\nNow edit it with your local settings." % os.path.abspath('make-release') diff --git a/support.py b/support.py index 4daea30..b92a072 100644 --- a/support.py +++ b/support.py @@ -45,7 +45,7 @@ def suggest_release_version(snapshot_version): version[-1] = 0 # Remove the modifier return model.format_version(version) -def publish(iface, **kwargs): +def publish(feed_path, **kwargs): args = [os.environ['0PUBLISH']] for k in kwargs: value = kwargs[k] @@ -53,14 +53,16 @@ def publish(iface, **kwargs): args += ['--' + k.replace('_', '-')] elif value is not None: args += ['--' + k.replace('_', '-'), value] - args.append(iface) + args.append(feed_path) info("Executing %s", args) check_call(args) -def get_singleton_impl(iface): - impls = iface.implementations +def get_singleton_impl(feed): + if isinstance(feed, model.Interface): + feed = feed._main_feed + impls = feed.implementations if len(impls) != 1: - raise SafeException("Local feed '%s' contains %d versions! I need exactly one!" % (iface.uri, len(impls))) + raise SafeException("Local feed '%s' contains %d versions! I need exactly one!" % (feed.url, len(impls))) return impls.values()[0] def backup_if_exists(name): -- 2.11.4.GIT