From d74a632fd88201d526d705033e792e898cd2cf3d Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 9 Jan 2011 15:49:58 +0000 Subject: [PATCH] Added '0install list' sub-command --- zeroinstall/cmd/list.py | 27 +++++++++++++++++++++++++++ zeroinstall/injector/cli.py | 19 +++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 zeroinstall/cmd/list.py diff --git a/zeroinstall/cmd/list.py b/zeroinstall/cmd/list.py new file mode 100644 index 0000000..2bfd3d9 --- /dev/null +++ b/zeroinstall/cmd/list.py @@ -0,0 +1,27 @@ +""" +The B{0install list} command-line interface. +""" + +# Copyright (C) 2011, Thomas Leonard +# See the README file for details, or visit http://0install.net. + +from zeroinstall.cmd import UsageError +from zeroinstall.injector.iface_cache import iface_cache + +syntax = "PATTERN" + +def add_options(parser): + pass + +def handle(options, args): + if len(args) == 0: + matches = iface_cache.list_all_interfaces() + elif len(args) == 1: + match = args[0].lower() + matches = [i for i in iface_cache.list_all_interfaces() if match in i.lower()] + else: + raise UsageError() + + matches.sort() + for i in matches: + print i diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index 9718d63..267be41 100644 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -13,25 +13,13 @@ import logging from zeroinstall import SafeException, NeedDownload from zeroinstall.injector import model, autopolicy, selections from zeroinstall.injector.iface_cache import iface_cache +from zeroinstall.cmd import UsageError #def program_log(msg): os.access('MARK: 0launch: ' + msg, os.F_OK) #import __main__ #__main__.__builtins__.program_log = program_log #program_log('0launch ' + ' '.join((sys.argv[1:]))) -def _list_interfaces(args): - if len(args) == 0: - matches = iface_cache.list_all_interfaces() - elif len(args) == 1: - match = args[0].lower() - matches = [i for i in iface_cache.list_all_interfaces() if match in i.lower()] - else: - raise UsageError() - - matches.sort() - for i in matches: - print i - def _manage_feeds(options, args): from zeroinstall.injector import writer from zeroinstall.injector.handler import Handler @@ -150,8 +138,6 @@ def _get_selections(sels, options): doc.writexml(sys.stdout) sys.stdout.write('\n') -class UsageError(Exception): pass - def main(command_args): """Act as if 0launch was run with the given arguments. @arg command_args: array of arguments (e.g. C{sys.argv[1:]}) @@ -221,7 +207,8 @@ def main(command_args): try: if options.list: - _list_interfaces(args) + from zeroinstall.cmd import list + list.handle(options, args) elif options.version: import zeroinstall print "0launch (zero-install) " + zeroinstall.version -- 2.11.4.GIT