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

Source Code for Module zeroinstall.cmd.import

 1  """ 
 2  The B{0install import} command-line interface. 
 3  """ 
 4   
 5  # Copyright (C) 2011, Thomas Leonard 
 6  # See the README file for details, or visit http://0install.net. 
 7   
 8  import os 
 9   
10  from zeroinstall import SafeException, _, logger 
11  from zeroinstall.cmd import UsageError 
12  from zeroinstall.injector import gpg 
13  from zeroinstall.injector.iface_cache import PendingFeed 
14  from zeroinstall.support import tasks 
15  from xml.dom import minidom 
16   
17  syntax = "FEED" 
18   
19 -def add_options(parser):
20 pass
21
22 -def handle(config, options, args):
23 if not args: 24 raise UsageError() 25 26 for x in args: 27 if not os.path.isfile(x): 28 raise SafeException(_("File '%s' does not exist") % x) 29 logger.info(_("Importing from file '%s'"), x) 30 with open(x, 'rb') as signed_data: 31 data, sigs = gpg.check_stream(signed_data) 32 doc = minidom.parseString(data.read()) 33 uri = doc.documentElement.getAttribute('uri') 34 if not uri: 35 raise SafeException(_("Missing 'uri' attribute on root element in '%s'") % x) 36 logger.info(_("Importing information about interface %s"), uri) 37 signed_data.seek(0) 38 39 pending = PendingFeed(uri, signed_data) 40 41 def run(): 42 keys_downloaded = tasks.Task(pending.download_keys(config.fetcher), "download keys") 43 yield keys_downloaded.finished 44 tasks.check(keys_downloaded.finished) 45 if not config.iface_cache.update_feed_if_trusted(uri, pending.sigs, pending.new_xml): 46 blocker = config.trust_mgr.confirm_keys(pending) 47 if blocker: 48 yield blocker 49 tasks.check(blocker) 50 if not config.iface_cache.update_feed_if_trusted(uri, pending.sigs, pending.new_xml): 51 raise SafeException(_("No signing keys trusted; not importing"))
52 53 task = tasks.Task(run(), "import feed") 54 55 tasks.wait_for_blocker(task.finished) 56
57 -def complete(completion, args, cword):
58 """@type completion: L{zeroinstall.cmd._Completion} 59 @type args: [str] 60 @type cword: int""" 61 if len(args) != 1: return 62 completion.expand_files()
63