Package zeroinstall :: Package cmd :: Module show
[frames] | no frames]

Source Code for Module zeroinstall.cmd.show

 1  """ 
 2  The B{0install show} command-line interface. 
 3  """ 
 4   
 5  # Copyright (C) 2012, Thomas Leonard 
 6  # See the README file for details, or visit http://0install.net. 
 7   
 8  from __future__ import print_function 
 9   
10  import os 
11   
12  from zeroinstall import _, SafeException 
13  from zeroinstall.cmd import select, UsageError 
14  from zeroinstall.injector import qdom, selections 
15   
16  syntax = "APP | SELECTIONS" 
17   
18 -def add_options(parser):
19 parser.add_option("-r", "--root-uri", help=_("display just the root interface URI"), action='store_true') 20 parser.add_option("", "--xml", help=_("print selections as XML"), action='store_true')
21
22 -def handle(config, options, args):
23 if len(args) != 1: 24 raise UsageError() 25 26 app = config.app_mgr.lookup_app(args[0], missing_ok = True) 27 if app is not None: 28 sels = app.get_selections() 29 30 r = app.get_requirements() 31 32 if r.extra_restrictions and not options.xml: 33 print("User-provided restrictions in force:") 34 for uri, expr in r.extra_restrictions.items(): 35 print(" {uri}: {expr}".format(uri = uri, expr = expr)) 36 print() 37 elif os.path.exists(args[0]): 38 with open(args[0], 'rb') as stream: 39 sels = selections.Selections(qdom.parse(stream)) 40 else: 41 raise SafeException(_("Neither an app nor a file: '%s'") % args[0]) 42 43 if options.root_uri: 44 print(sels.interface) 45 elif options.xml: 46 select.show_xml(sels) 47 else: 48 select.show_human(sels, config.stores)
49
50 -def complete(completion, args, cword):
51 """@type completion: L{zeroinstall.cmd._Completion} 52 @type args: [str] 53 @type cword: int""" 54 if len(args) != 1: return 55 completion.expand_apps() 56 completion.expand_files()
57