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

Source Code for Module zeroinstall.cmd.man

 1  """ 
 2  The B{0install man} 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 sys, os 
11   
12  from zeroinstall import support, logger 
13   
14  syntax = "NAME" 
15   
16 -def add_options(parser):
17 pass
18
19 -def handle(config, options, args):
20 if len(args) != 1 or not _0install_man(config, args[0]): 21 logger.debug("Not a 0install alias or app-script, so passing through to system man command: %r", args) 22 os.execlp('man', 'man', *args)
23
24 -def _0install_man(config, command):
25 """@type command: str""" 26 from zeroinstall import apps, alias, helpers 27 28 path = support.find_in_path(command) 29 if not path: 30 return None 31 32 try: 33 with open(path, 'rt') as stream: 34 app_info = apps.parse_script_header(stream) 35 if app_info: 36 app = config.app_mgr.lookup_app(app_info.name) 37 sels = app.get_selections() 38 main = None 39 else: 40 alias_info = alias.parse_script_header(stream) 41 if alias_info is None: 42 return None 43 sels = helpers.ensure_cached(alias_info.uri, alias_info.command, config = config) 44 if not sels: 45 # Cancelled by user 46 sys.exit(1) 47 main = alias_info.main 48 except IOError as e: 49 logger.info("Error reading %s, falling back to `man %s`", path, command) 50 os.execlp('man', 'man', command) 51 sys.exit(1) 52 53 helpers.exec_man(config.stores, sels, main, fallback_name = command) 54 assert 0
55
56 -def complete(completion, args, cword):
57 """@type completion: L{zeroinstall.cmd._Completion} 58 @type args: [str] 59 @type cword: int""" 60 if len(args) != 1: return 61 completion.expand_apps()
62