2 The B{0install import} command-line interface.
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
11 from zeroinstall
import SafeException
, _
12 from zeroinstall
.cmd
import UsageError
13 from zeroinstall
.injector
import gpg
14 from zeroinstall
.injector
.iface_cache
import PendingFeed
15 from zeroinstall
.support
import tasks
16 from xml
.dom
import minidom
20 def add_options(parser
):
23 def handle(config
, options
, args
):
30 if not os
.path
.isfile(x
):
31 raise SafeException(_("File '%s' does not exist") % x
)
32 logging
.info(_("Importing from file '%s'"), x
)
34 data
, sigs
= gpg
.check_stream(signed_data
)
35 doc
= minidom
.parseString(data
.read())
36 uri
= doc
.documentElement
.getAttribute('uri')
38 raise SafeException(_("Missing 'uri' attribute on root element in '%s'") % x
)
39 logging
.info(_("Importing information about interface %s"), uri
)
42 pending
= PendingFeed(uri
, signed_data
)
45 keys_downloaded
= tasks
.Task(pending
.download_keys(h
), "download keys")
46 yield keys_downloaded
.finished
47 tasks
.check(keys_downloaded
.finished
)
48 if not config
.iface_cache
.update_feed_if_trusted(uri
, pending
.sigs
, pending
.new_xml
):
49 blocker
= config
.trust_mgr
.confirm_keys(pending
)
53 if not config
.iface_cache
.update_feed_if_trusted(uri
, pending
.sigs
, pending
.new_xml
):
54 raise SafeException(_("No signing keys trusted; not importing"))
56 task
= tasks
.Task(run(), "import feed")
58 errors
= tasks
.wait_for_blocker(task
.finished
)
60 raise SafeException(_("Errors during download: ") + '\n'.join(errors
))