def handle(config, options, args): if len(args) != 1: raise UsageError() app = config.app_mgr.lookup_app(args[0], missing_ok=True) if app is not None: sels = app.get_selections() r = app.get_requirements() if r.extra_restrictions and not options.xml: print("User-provided restrictions in force:") for uri, expr in r.extra_restrictions.items(): print(" {uri}: {expr}".format(uri=uri, expr=expr)) print() elif os.path.exists(args[0]): with open(args[0], 'rb') as stream: sels = selections.Selections(qdom.parse(stream)) else: raise SafeException(_("Neither an app nor a file: '%s'") % args[0]) if options.root_uri: print(sels.interface) elif options.xml: select.show_xml(sels) else: select.show_human(sels, config.stores)
def handle(config, options, args): if args: raise UsageError() if options.offline: config.network_use = model.network_offline def slave_raw_input(prompt=""): ticket = take_ticket() send_json(["invoke", ticket, ["input", prompt]]) while True: message = recv_json() if message[0] == 'return' and message[1] == ticket: reply = message[2] assert reply[0] == 'ok', reply return reply[1] else: handle_message(config, options, message) support.raw_input = slave_raw_input @tasks. async def handle_events(): while True: logger.debug("waiting for stdin") yield tasks.InputBlocker(stdin, 'wait for commands from master') logger.debug("reading JSON") message = recv_json() logger.debug("got %s", message) if message is None: break handle_message(config, options, message) tasks.wait_for_blocker(handle_events())
def handle(config, options, args): """@type config: L{zeroinstall.injector.config.Config} @type args: [str]""" if len(args) != 1: raise UsageError() app = config.app_mgr.lookup_app(args[0], missing_ok = True) if app is not None: sels = app.get_selections() r = app.get_requirements() do_select = r.parse_update_options(options) or options.refresh iface_uri = sels.interface else: iface_uri = model.canonical_iface_uri(args[0]) r = None do_select = True if do_select or options.gui: sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = True, test_callback = None, requirements = r) if not sels: sys.exit(1) # Aborted by user else: dl = app.download_selections(sels) if dl: tasks.wait_for_blocker(dl) tasks.check(dl) if options.xml: select.show_xml(sels) if options.show: select.show_human(sels, config.stores) if app is not None and do_select: print(_("(use '0install update' to save the new parameters)"))
def handle(config, options, args): if len(args) == 0: if options.gui is None and os.environ.get('DISPLAY', None): options.gui = True if options.gui: from zeroinstall import helpers return helpers.get_selections_gui(None, []) else: for key, setting_type in settings.iteritems(): value = getattr(config, key) print(key, "=", setting_type.format(value)) return elif len(args) > 2: raise UsageError() option = args[0] if option not in settings: raise SafeException(_('Unknown option "%s"') % option) if len(args) == 1: value = getattr(config, option) print(settings[option].format(value)) else: value = settings[option].parse(args[1]) if option == 'network_use' and value not in model.network_levels: raise SafeException( _("Must be one of %s") % list(model.network_levels)) setattr(config, option, value) config.save_globals()
def handle(config, options, args): if len(args) == 0: raise UsageError() url = config.mirror + '/search/?q=' + quote(' '.join(args)) logger.info("Fetching %s...", url) root = qdom.parse(urllib2.urlopen(url)) assert root.name == 'results' first = True for child in root.childNodes: if child.name != 'result': continue if first: first = False else: print() print(child.attrs['uri']) score = child.attrs['score'] details = {} for detail in child.childNodes: details[detail.name] = detail.content print(" {name} - {summary} [{score}%]".format( name=child.attrs['name'], summary=details.get('summary', ''), score=score))
def handle(config, options, args): """@type config: L{zeroinstall.injector.config.Config} @type args: [str]""" if len(args) < 1: raise UsageError() prog_args = args[1:] def test_callback(sels): from zeroinstall.injector import run return run.test_selections(sels, prog_args, False, # dry-run options.main) app = config.app_mgr.lookup_app(args[0], missing_ok = True) if app is not None: sels = app.get_selections(may_update = True, use_gui = options.gui) r = app.get_requirements() do_select = r.parse_update_options(options) or options.refresh iface_uri = sels.interface else: iface_uri = model.canonical_iface_uri(args[0]) r = None do_select = True if do_select or options.gui: sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = False, test_callback = test_callback, requirements = r) if not sels: sys.exit(1) # Aborted by user from zeroinstall.injector import run run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)
def handle(config, options, args): if len(args) != 1: raise UsageError() app = config.app_mgr.lookup_app(args[0], missing_ok=True) if app is not None: sels = app.get_selections() r = app.get_requirements() do_select = r.parse_update_options(options) iface_uri = sels.interface else: iface_uri = model.canonical_iface_uri(args[0]) do_select = True if do_select or options.gui: sels = get_selections(config, options, iface_uri, select_only=True, download_only=False, test_callback=None) if not sels: sys.exit(1) # Aborted by user if options.xml: show_xml(sels) else: show_human(sels, config.stores) if app is not None and do_select: print(_("(use '0install update' to save the new parameters)"))
def handle(config, options, args): if len(args) == 0: from zeroinstall import helpers if helpers.get_selections_gui(None, [], use_gui = options.gui) == helpers.DontUseGUI: for key, setting_type in settings.items(): value = getattr(config, key) print(key, "=", setting_type.format(value)) # (else we displayed the preferences dialog in the GUI) return elif len(args) > 2: raise UsageError() option = args[0] if option not in settings: raise SafeException(_('Unknown option "%s"') % option) if len(args) == 1: value = getattr(config, option) print(settings[option].format(value)) else: value = settings[option].parse(args[1]) if option == 'network_use' and value not in model.network_levels: raise SafeException(_("Must be one of %s") % list(model.network_levels)) setattr(config, option, value) config.save_globals()
def handle(config, options, args): if len(args) != 1: raise UsageError() pet_name = args[0] app = config.app_mgr.lookup_app(pet_name) app.destroy()
def handle(config, options, args): if len(args) != 1: raise UsageError() uri = model.canonical_iface_uri(args[0]) iface = config.iface_cache.get_interface(uri) if iface.extra_feeds: for f in iface.extra_feeds: print f.uri else: print _("(no feeds)")
def handle(config, options, args): if len(args) != 1: raise UsageError() assert not options.offline iface_uri = model.canonical_iface_uri(args[0]) old_gui = options.gui # Select once in offline console mode to get the old values options.offline = True options.gui = False options.refresh = False try: old_sels = select.get_selections(config, options, iface_uri, select_only = True, download_only = False, test_callback = None) except SafeException: old_selections = {} else: if old_sels is None: old_selections = {} else: old_selections = old_sels.selections # Download in online mode to get the new values config.network_use = model.network_full options.offline = False options.gui = old_gui options.refresh = True sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = True, test_callback = None) if not sels: sys.exit(1) # Aborted by user changes = False for iface, old_sel in old_selections.iteritems(): new_sel = sels.selections.get(iface, None) if new_sel is None: print _("No longer used: %s") % iface changes = True elif old_sel.version != new_sel.version: print _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version) changes = True for iface, new_sel in sels.selections.iteritems(): if iface not in old_selections: print _("%s: new -> %s") % (iface, new_sel.version) changes = True if not changes: print _("No updates found.")
def handle(config, options, args): if len(args) != 1: raise UsageError() iface_uri = model.canonical_iface_uri(args[0]) sels = get_selections(config, options, iface_uri, select_only = True, download_only = False, test_callback = None) if not sels: sys.exit(1) # Aborted by user if options.xml: show_xml(sels) else: show_human(sels, config.stores)
def handle(config, options, args): if len(args) == 0: matches = config.iface_cache.list_all_interfaces() elif len(args) == 1: match = args[0].lower() matches = [ i for i in config.iface_cache.list_all_interfaces() if match in i.lower() ] else: raise UsageError() matches.sort() for i in matches: print(i)
def handle(config, options, args): if len(args) == 2: iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0])) feed_url = args[1] feed_import = add_feed.find_feed_import(iface, feed_url) if not feed_import: raise SafeException(_('Interface %(interface)s has no feed %(feed)s') % {'interface': iface.uri, 'feed': feed_url}) iface.extra_feeds.remove(feed_import) writer.save_interface(iface) elif len(args) == 1: add_feed.handle(config, options, args, add_ok = False, remove_ok = True) else: raise UsageError()
def handle(config, options, args): """@type config: L{zeroinstall.injector.config.Config} @type args: [str]""" if len(args) == 0: matches = config.iface_cache.list_all_interfaces() elif len(args) == 1: match = args[0].lower() matches = [ i for i in config.iface_cache.list_all_interfaces() if match in i.lower() ] else: raise UsageError() matches.sort() for i in matches: print(i)
def handle(config, options, args): """@type config: L{zeroinstall.injector.config.Config} @type args: [str]""" if len(args) != 1: raise UsageError() app = config.app_mgr.lookup_app(args[0], missing_ok=True) if app is not None: old_sels = app.get_selections() requirements = app.get_requirements() changes = requirements.parse_update_options(options) iface_uri = old_sels.interface if requirements.extra_restrictions and not options.xml: print("User-provided restrictions in force:") for uri, expr in requirements.extra_restrictions.items(): print(" {uri}: {expr}".format(uri=uri, expr=expr)) print() else: iface_uri = model.canonical_iface_uri(args[0]) requirements = None changes = False sels = get_selections(config, options, iface_uri, select_only=True, download_only=False, test_callback=None, requirements=requirements) if not sels: sys.exit(1) # Aborted by user if options.xml: show_xml(sels) else: show_human(sels, config.stores) if app is not None: from zeroinstall.cmd import whatchanged changes = whatchanged.show_changes(old_sels.selections, sels.selections) or changes if changes: print( _("(note: use '0install update' instead to save the changes)" ))
def handle(config, options, args): if len(args) < 1: raise UsageError() prog_args = args[1:] def test_callback(sels): from zeroinstall.injector import run return run.test_selections( sels, prog_args, False, # dry-run options.main) app = config.app_mgr.lookup_app(args[0], missing_ok=True) if app is not None: sels = app.get_selections(may_update=True) r = app.get_requirements() do_select = r.parse_update_options(options) iface_uri = sels.interface else: iface_uri = model.canonical_iface_uri(args[0]) do_select = True if do_select or options.gui: sels = select.get_selections(config, options, iface_uri, select_only=False, download_only=False, test_callback=test_callback) if not sels: sys.exit(1) # Aborted by user else: dl = app.download_selections(sels) if dl: tasks.wait_for_blocker(dl) tasks.check(dl) from zeroinstall.injector import run run.execute_selections(sels, prog_args, dry_run=options.dry_run, main=options.main, wrapper=options.wrapper, stores=config.stores)
def handle(config, options, args): if len(args) != 2: raise UsageError() pet_name = args[0] iface_uri = model.canonical_iface_uri(args[1]) sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = True, test_callback = None) if not sels: sys.exit(1) # Aborted by user r = requirements.Requirements(iface_uri) r.parse_options(options) app = config.app_mgr.create_app(pet_name, r) app.set_selections(sels) app.integrate_shell(pet_name)
def handle(config, options, args): if not args: raise UsageError() h = config.handler for x in args: if not os.path.isfile(x): raise SafeException(_("File '%s' does not exist") % x) logging.info(_("Importing from file '%s'"), x) signed_data = file(x) data, sigs = gpg.check_stream(signed_data) doc = minidom.parseString(data.read()) uri = doc.documentElement.getAttribute('uri') if not uri: raise SafeException( _("Missing 'uri' attribute on root element in '%s'") % x) logging.info(_("Importing information about interface %s"), uri) signed_data.seek(0) pending = PendingFeed(uri, signed_data) def run(): keys_downloaded = tasks.Task(pending.download_keys(h), "download keys") yield keys_downloaded.finished tasks.check(keys_downloaded.finished) if not config.iface_cache.update_feed_if_trusted( uri, pending.sigs, pending.new_xml): blocker = config.trust_mgr.confirm_keys(pending) if blocker: yield blocker tasks.check(blocker) if not config.iface_cache.update_feed_if_trusted( uri, pending.sigs, pending.new_xml): raise SafeException( _("No signing keys trusted; not importing")) task = tasks.Task(run(), "import feed") errors = tasks.wait_for_blocker(task.finished) if errors: raise SafeException( _("Errors during download: ") + '\n'.join(errors))
def handle(config, options, args): """@type args: [str]""" if len(args) == 1: extract = None elif len(args) == 2: extract = args[1] else: raise UsageError() source = args[0] alg = manifest.algorithms.get(options.algorithm or 'sha1new', None) if alg is None: raise SafeException(_('Unknown algorithm "%s"') % alg) show_manifest = bool(options.manifest) show_digest = bool(options.digest) or not show_manifest def do_manifest(d): if extract is not None: d = os.path.join(d, extract) digest = alg.new_digest() for line in alg.generate_manifest(d): if show_manifest: print(line) digest.update((line + '\n').encode('utf-8')) if show_digest: print(alg.getID(digest)) if os.path.isdir(source): if extract is not None: raise SafeException("Can't use extract with a directory") do_manifest(source) else: data = None tmpdir = tempfile.mkdtemp() try: data = open(args[0], 'rb') unpack.unpack_archive(source, data, tmpdir, extract) do_manifest(tmpdir) finally: support.ro_rmtree(tmpdir) if data: data.close()
def handle(config, options, args): if len(args) < 1: raise UsageError() iface_uri = model.canonical_iface_uri(args[0]) prog_args = args[1:] def test_callback(sels): from zeroinstall.injector import run return run.test_selections(sels, prog_args, False, # dry-run options.main) sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = False, test_callback = test_callback) if not sels: sys.exit(1) # Aborted by user from zeroinstall.injector import run run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)
def handle(config, options, args): """@type args: [str]""" if len(args) != 2: raise UsageError() pet_name = args[0] iface_uri = model.canonical_iface_uri(args[1]) sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = True, test_callback = None) if not sels: sys.exit(1) # Aborted by user root_feed = config.iface_cache.get_feed(iface_uri) if root_feed: target = root_feed.get_replaced_by() if target is not None: print(_("Warning: interface {old} has been replaced by {new}".format(old = iface_uri, new = target))) r = requirements.Requirements(iface_uri) r.parse_options(options) app = config.app_mgr.create_app(pet_name, r) app.set_selections(sels) app.integrate_shell(pet_name)
def handle(config, options, args): if len(args) != 1: raise UsageError() assert not options.offline old_gui = options.gui app = config.app_mgr.lookup_app(args[0], missing_ok=True) if app is not None: old_sels = app.get_selections() old_selections = old_sels.selections iface_uri = old_sels.interface r = app.get_requirements() r.parse_update_options(options) else: iface_uri = model.canonical_iface_uri(args[0]) r = requirements.Requirements(iface_uri) r.parse_options(options) # Select once in offline console mode to get the old values options.offline = True options.gui = False options.refresh = False try: old_sels = select.get_selections_for(r, config, options, select_only=True, download_only=False, test_callback=None) except SafeException: old_selections = {} else: if old_sels is None: old_selections = {} else: old_selections = old_sels.selections # Download in online mode to get the new values config.network_use = model.network_full options.offline = False options.gui = old_gui options.refresh = True sels = select.get_selections_for(r, config, options, select_only=False, download_only=True, test_callback=None) if not sels: sys.exit(1) # Aborted by user root_feed = config.iface_cache.get_feed(iface_uri) if root_feed: target = root_feed.get_replaced_by() if target is not None: print( _("Warning: interface {old} has been replaced by {new}".format( old=iface_uri, new=target))) from zeroinstall.cmd import whatchanged changes = whatchanged.show_changes(old_selections, sels.selections) root_sel = sels[iface_uri] if not changes: from zeroinstall.support import xmltools # No obvious changes, but check for more subtle updates. if not xmltools.nodes_equal(sels.toDOM(), old_sels.toDOM()): changes = True print( _("Updates to metadata found, but no change to version ({version})." ).format(version=root_sel.version)) root_iface = config.iface_cache.get_interface(iface_uri) # Force a reload, since we may have used the GUI to update it for feed in config.iface_cache.get_feeds(root_iface): config.iface_cache.get_feed(feed, force=True) root_impls = config.iface_cache.get_implementations(root_iface) latest = max((impl.version, impl) for impl in root_impls)[1] if latest.version > model.parse_version(sels[iface_uri].version): print( _("A later version ({name} {latest}) exists but was not selected. Using {version} instead." ).format(latest=latest.get_version(), name=root_iface.get_name(), version=root_sel.version)) if not config.help_with_testing and latest.get_stability( ) < model.stable: print( _('To select "testing" versions, use:\n0install config help_with_testing True' )) elif not changes: print( _("No updates found. Continuing with version {version}.").format( version=root_sel.version)) if app is not None: if changes: app.set_selections(sels) app.set_requirements(r)
def handle(config, options, args): if len(args) != 1: raise UsageError() assert not options.offline iface_uri = model.canonical_iface_uri(args[0]) old_gui = options.gui # Select once in offline console mode to get the old values options.offline = True options.gui = False options.refresh = False try: old_sels = select.get_selections(config, options, iface_uri, select_only=True, download_only=False, test_callback=None) except SafeException: old_selections = {} else: if old_sels is None: old_selections = {} else: old_selections = old_sels.selections # Download in online mode to get the new values config.network_use = model.network_full options.offline = False options.gui = old_gui options.refresh = True sels = select.get_selections(config, options, iface_uri, select_only=False, download_only=True, test_callback=None) if not sels: sys.exit(1) # Aborted by user changes = False for iface, old_sel in old_selections.iteritems(): new_sel = sels.selections.get(iface, None) if new_sel is None: print(_("No longer used: %s") % iface) changes = True elif old_sel.version != new_sel.version: print( _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version)) changes = True for iface, new_sel in sels.selections.iteritems(): if iface not in old_selections: print(_("%s: new -> %s") % (iface, new_sel.version)) changes = True root_sel = sels[iface_uri] root_iface = config.iface_cache.get_interface(iface_uri) latest = max((impl.version, impl) for impl in root_iface.implementations.values())[1] if latest.version > model.parse_version(sels[iface_uri].version): print( _("A later version ({name} {latest}) exists but was not selected. Using {version} instead." ).format(latest=latest.get_version(), name=root_iface.get_name(), version=root_sel.version)) if not config.help_with_testing and latest.get_stability( ) < model.stable: print( _('To select "testing" versions, use:\n0install config help_with_testing True' )) else: if not changes: print( _("No updates found. Continuing with version {version}."). format(version=root_sel.version))
def handle(config, options, args, add_ok = True, remove_ok = False): """@type add_ok: bool @type remove_ok: bool""" if len(args) == 2: iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0])) feed_url = model.canonical_iface_uri(args[1]) feed_import = find_feed_import(iface, feed_url) if feed_import: raise SafeException(_('Interface %(interface)s already has a feed %(feed)s') % {'interface': iface.uri, 'feed': feed_url}) iface.extra_feeds.append(model.Feed(feed_url, arch = None, user_override = True)) writer.save_interface(iface) return elif len(args) != 1: raise UsageError() x = args[0] print(_("Feed '%s':") % x + '\n') x = model.canonical_iface_uri(x) if options.offline: config.network_use = model.network_offline if config.network_use != model.network_offline and config.iface_cache.is_stale(x, config.freshness): blocker = config.fetcher.download_and_import_feed(x, config.iface_cache) print(_("Downloading feed; please wait...")) tasks.wait_for_blocker(blocker) print(_("Done")) candidate_interfaces = config.iface_cache.get_feed_targets(x) assert candidate_interfaces interfaces = [] for i in range(len(candidate_interfaces)): iface = candidate_interfaces[i] if find_feed_import(iface, x): if remove_ok: print(_("%(index)d) Remove as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri}) interfaces.append(iface) else: if add_ok: print(_("%(index)d) Add as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri}) interfaces.append(iface) if not interfaces: if remove_ok: raise SafeException(_("%(feed)s is not registered as a feed for %(interface)s") % {'feed': x, 'interface': candidate_interfaces[0]}) else: raise SafeException(_("%(feed)s already registered as a feed for %(interface)s") % {'feed': x, 'interface': candidate_interfaces[0]}) print() while True: try: i = raw_input(_('Enter a number, or CTRL-C to cancel [1]: ')).strip() except KeyboardInterrupt: print() raise SafeException(_("Aborted at user request.")) if i == '': i = 1 else: try: i = int(i) except ValueError: i = 0 if i > 0 and i <= len(interfaces): break print(_("Invalid number. Try again. (1 to %d)") % len(interfaces)) iface = interfaces[i - 1] feed_import = find_feed_import(iface, x) if feed_import: iface.extra_feeds.remove(feed_import) else: iface.extra_feeds.append(model.Feed(x, arch = None, user_override = True)) writer.save_interface(iface) print('\n' + _("Feed list for interface '%s' is now:") % iface.get_name()) if iface.extra_feeds: for f in iface.extra_feeds: print("- " + f.uri) else: print(_("(no feeds)"))
def handle(config, options, args): """@type args: [str]""" if len(args) != 1: raise UsageError() name = args[0] app = config.app_mgr.lookup_app(name, missing_ok=False) history = app.get_history() if not history: raise SafeException( _("Invalid application: no selections found! Try '0install destroy {name}'" ).format(name=name)) import time last_checked = app.get_last_checked() if last_checked is not None: print( _("Last checked : {date}").format( date=time.ctime(last_checked))) last_attempt = app.get_last_check_attempt() if last_attempt is not None: print( _("Last attempted update: {date}").format( date=time.ctime(last_attempt))) print(_("Last update : {date}").format(date=history[0])) current_sels = app.get_selections(snapshot_date=history[0]) if len(history) == 1: print(_("No previous history to compare against.")) print( _("Use '0install select {name}' to see the current selections."). format(name=name)) return print(_("Previous update : {date}").format(date=history[1])) def get_selections_path(date): return os.path.join(app.path, 'selections-{date}.xml'.format(date=date)) print() if options.full: import difflib, sys def load_lines(date): with open(get_selections_path(date), 'r') as stream: return stream.readlines() old_lines = load_lines(history[1]) new_lines = load_lines(history[0]) for line in difflib.unified_diff(old_lines, new_lines, fromfile=history[1], tofile=history[0]): sys.stdout.write(line) else: changes = show_changes( app.get_selections(snapshot_date=history[1]).selections, current_sels.selections) if not changes: print(_("No changes to versions (use --full to see all changes).")) print() print(_("To run using the previous selections, use:")) print("0install run {path}".format(path=get_selections_path(history[1])))
def main(command_args, config=None): """Act as if 0launch was run with the given arguments. @arg command_args: array of arguments (e.g. C{sys.argv[1:]}) @type command_args: [str] """ # Ensure stdin, stdout and stderr FDs exist, to avoid confusion for std in (0, 1, 2): try: os.fstat(std) except OSError: fd = os.open('/dev/null', os.O_RDONLY) if fd != std: os.dup2(fd, std) os.close(fd) parser = OptionParser( usage=_("usage: %prog [options] interface [args]\n" " %prog --list [search-term]\n" " %prog --import [signed-interface-files]\n" " %prog --feed [interface]")) parser.add_option("", "--before", help=_("choose a version before this"), metavar='VERSION') parser.add_option("", "--command", help=_("command to select"), metavar='COMMAND') parser.add_option("-c", "--console", help=_("never use GUI"), action='store_false', dest='gui') parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU') parser.add_option("-d", "--download-only", help=_("fetch but don't run"), action='store_true') parser.add_option("-D", "--dry-run", help=_("just print actions"), action='store_true') parser.add_option("-f", "--feed", help=_("add or remove a feed"), action='store_true') parser.add_option("", "--get-selections", help=_("write selected versions as XML"), action='store_true', dest='xml') parser.add_option("-g", "--gui", help=_("show graphical policy editor"), action='store_true') parser.add_option("-i", "--import", help=_("import from files, not from the network"), action='store_true') parser.add_option("-l", "--list", help=_("list all known interfaces"), action='store_true') parser.add_option("-m", "--main", help=_("name of the file to execute")) parser.add_option("", "--message", help=_("message to display when interacting with user")) parser.add_option("", "--not-before", help=_("minimum version to choose"), metavar='VERSION') parser.add_option("", "--os", help=_("target operation system type"), metavar='OS') parser.add_option("-o", "--offline", help=_("try to avoid using the network"), action='store_true') parser.add_option("-r", "--refresh", help=_("refresh all used interfaces"), action='store_true') parser.add_option("", "--select-only", help=_("only download the feeds"), action='store_true') parser.add_option("", "--set-selections", help=_("run versions specified in XML file"), metavar='FILE') parser.add_option("", "--show", help=_("show where components are installed"), action='store_true') parser.add_option("-s", "--source", help=_("select source code"), action='store_true') parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count') parser.add_option("-V", "--version", help=_("display version information"), action='store_true') parser.add_option("", "--with-store", help=_("add an implementation cache"), action='append', metavar='DIR') parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND') parser.disable_interspersed_args() (options, args) = parser.parse_args(command_args) if options.verbose: logger = logging.getLogger() if options.verbose == 1: logger.setLevel(logging.INFO) else: logger.setLevel(logging.DEBUG) import zeroinstall logging.info( _("Running 0launch %(version)s %(args)s; Python %(python_version)s" ), { 'version': zeroinstall.version, 'args': repr(args), 'python_version': sys.version }) if options.select_only or options.show: options.download_only = True if config is None: config = load_config() config.handler.dry_run = bool(options.dry_run) if options.with_store: from zeroinstall import zerostore for x in options.with_store: config.stores.stores.append(zerostore.Store(os.path.abspath(x))) logging.info(_("Stores search path is now %s"), config.stores.stores) if options.set_selections: args = [options.set_selections] + args try: if options.list: from zeroinstall.cmd import list list.handle(config, options, args) elif options.version: import zeroinstall print("0launch (zero-install) " + zeroinstall.version) print("Copyright (C) 2010 Thomas Leonard") print( _("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" "\nunder the terms of the GNU Lesser General Public License." "\nFor more information about these matters, see the file named COPYING." )) elif getattr(options, 'import'): # (import is a keyword) cmd = __import__('zeroinstall.cmd.import', globals(), locals(), ["import"], 0) cmd.handle(config, options, args) elif options.feed: from zeroinstall.cmd import add_feed add_feed.handle(config, options, args, add_ok=True, remove_ok=True) elif options.select_only: from zeroinstall.cmd import select if not options.show: options.quiet = True select.handle(config, options, args) elif options.download_only or options.xml or options.show: from zeroinstall.cmd import download download.handle(config, options, args) else: if len(args) < 1: if options.gui: from zeroinstall import helpers return helpers.get_selections_gui(None, []) else: raise UsageError() else: from zeroinstall.cmd import run run.handle(config, options, args) except NeedDownload as ex: # This only happens for dry runs print(ex) except KeyboardInterrupt: logging.info("KeyboardInterrupt") sys.exit(1) except UsageError: parser.print_help() sys.exit(1) except SafeException as ex: if options.verbose: raise try: print(unicode(ex), file=sys.stderr) except: print(repr(ex), file=sys.stderr) sys.exit(1)