本文整理汇总了Python中zeroinstall.support.tasks.check函数的典型用法代码示例。如果您正苦于以下问题:Python check函数的具体用法?Python check怎么用?Python check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_details_page
def update_details_page():
blocker = slave.invoke_master(['get-feed-metadata', uri.get_text()])
yield blocker
tasks.check(blocker)
feed = blocker.result
about.set_text('%s - %s' % (feed['name'], feed['summary']))
icon_path = feed['icon-path']
from zeroinstall.gtkui import icon
icon_pixbuf = icon.load_icon(icon_path)
if icon_pixbuf:
icon_widget.set_from_pixbuf(icon_pixbuf)
feed_category = feed['category']
if feed_category:
i = 0
for row in categories:
if row.lower() == feed_category.lower():
category.set_active(i)
break
i += 1
self.window.set_response_sensitive(_RESPONSE_PREV, True)
nb.next_page()
dialog_next.set_property('visible', False)
dialog_ok.set_property('visible', True)
dialog_ok.grab_focus()
示例2: collect_output
def collect_output(self, buffer):
try:
iter = buffer.get_end_iter()
buffer.place_cursor(iter)
if not self.driver.ready:
buffer.insert_at_cursor("Can't run, because we failed to select a set of versions.\n")
return
sels = selections.Selections(self.driver.sels)
uncached = sels.get_unavailable_selections(self.driver.config, include_packages = True)
if uncached:
buffer.insert_at_cursor("Can't run: the chosen versions have not been downloaded yet. I need:\n\n- " +
"\n\n- " . join(['%s version %s\n (%s)' %(x.interface, x.version, x.id) for x in uncached]))
return
self.hide()
try:
gtk.gdk.flush()
iter = buffer.get_end_iter()
buffer.place_cursor(iter)
# Tell 0launch to run the program
blocker = slave.run_test()
yield blocker
tasks.check(blocker)
buffer.insert_at_cursor(blocker.result)
finally:
self.show()
except Exception as ex:
buffer.insert_at_cursor(str(ex))
raise
示例3: download
def download(self, dl):
# (changed if we get redirected)
current_url = dl.url
redirections_remaining = 10
# Assign the Download to a Site based on its scheme, host and port. If the result is a redirect,
# reassign it to the appropriate new site. Note that proxy handling happens later; we want to group
# and limit by the target site, not treat everything as going to a single site (the proxy).
while True:
location_parts = urlparse.urlparse(current_url)
site_key = (location_parts.scheme,
location_parts.hostname,
location_parts.port or default_port.get(location_parts.scheme, None))
step = DownloadStep()
step.dl = dl
step.url = current_url
blocker = self._sites[site_key].download(step)
yield blocker
tasks.check(blocker)
if not step.redirect:
break
current_url = step.redirect
if redirections_remaining == 0:
raise download.DownloadError("Too many redirections {url} -> {current}".format(
url = dl.url,
current = current_url))
redirections_remaining -= 1
示例4: testDistro
def testDistro(self):
with output_suppressed():
native_url = "http://example.com:8000/Native.xml"
# Initially, we don't have the feed at all...
master_feed = self.config.iface_cache.get_feed(native_url)
assert master_feed is None, master_feed
trust.trust_db.trust_key("DE937DD411906ACF7C263B396FCF121BE2390E0B", "example.com:8000")
self.child = server.handle_requests(
"Native.xml", "6FCF121BE2390E0B.gpg", "/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B"
)
policy = Policy(native_url, config=self.config)
assert policy.need_download()
solve = policy.solve_with_downloads()
self.config.handler.wait_for_blocker(solve)
tasks.check(solve)
master_feed = self.config.iface_cache.get_feed(native_url)
assert master_feed is not None
assert master_feed.implementations == {}
distro_feed_url = master_feed.get_distro_feed()
assert distro_feed_url is not None
distro_feed = self.config.iface_cache.get_feed(distro_feed_url)
assert distro_feed is not None
assert len(distro_feed.implementations) == 2, distro_feed.implementations
示例5: collect_output
def collect_output(self, buffer):
try:
iter = buffer.get_end_iter()
buffer.place_cursor(iter)
if not self.driver.ready:
buffer.insert_at_cursor("Can't run, because we failed to select a set of versions.\n")
return
self.hide()
try:
gtk.gdk.flush()
iter = buffer.get_end_iter()
buffer.place_cursor(iter)
# Tell 0launch to run the program
blocker = slave.run_test()
yield blocker
tasks.check(blocker)
buffer.insert_at_cursor(blocker.result)
finally:
self.show()
except Exception as ex:
buffer.insert_at_cursor(str(ex))
raise
示例6: _queue_confirm_import_feed
def _queue_confirm_import_feed(self, pending, valid_sigs):
# If we're already confirming something else, wait for that to finish...
while self._current_confirm is not None:
yield self._current_confirm
# Check whether we still need to confirm. The user may have
# already approved one of the keys while dealing with another
# feed.
from zeroinstall.injector import trust
domain = trust.domain_from_url(pending.url)
for sig in valid_sigs:
is_trusted = trust.trust_db.is_trusted(sig.fingerprint, domain)
if is_trusted:
return
# Take the lock and confirm this feed
self._current_confirm = lock = tasks.Blocker('confirm key lock')
try:
done = self.confirm_import_feed(pending, valid_sigs)
if done is not None:
yield done
tasks.check(done)
finally:
self._current_confirm = None
lock.trigger()
示例7: download_impls
def download_impls():
if unsafe_impls:
confirm = self.handler.confirm_install(_('The following components need to be installed using native packages. '
'These come from your distribution, and should therefore be trustworthy, but they also '
'run with extra privileges. In particular, installing them may run extra services on your '
'computer or affect other users. You may be asked to enter a password to confirm. The '
'packages are:\n\n') + ('\n'.join('- ' + x for x in unsafe_impls)))
yield confirm
tasks.check(confirm)
blockers = []
for impl, source in to_download:
blockers.append(self.download_impl(impl, source, stores))
# Record the first error log the rest
error = []
def dl_error(ex, tb = None):
if error:
self.handler.report_error(ex)
else:
error.append((ex, tb))
while blockers:
yield blockers
tasks.check(blockers, dl_error)
blockers = [b for b in blockers if not b.happened]
if error:
from zeroinstall import support
support.raise_with_traceback(*error[0])
示例8: handle
def handle(config, options, args):
"""@type config: L{zeroinstall.injector.config.Config}
@type args: [str]"""
if len(args) != 1:
raise UsageError()
app = config.app_mgr.lookup_app(args[0], missing_ok = True)
if app is not None:
sels = app.get_selections()
r = app.get_requirements()
do_select = r.parse_update_options(options) or options.refresh
iface_uri = sels.interface
else:
iface_uri = model.canonical_iface_uri(args[0])
r = None
do_select = True
if do_select or options.gui:
sels = select.get_selections(config, options, iface_uri,
select_only = False, download_only = True, test_callback = None, requirements = r)
if not sels:
sys.exit(1) # Aborted by user
else:
dl = app.download_selections(sels)
if dl:
tasks.wait_for_blocker(dl)
tasks.check(dl)
if options.xml:
select.show_xml(sels)
if options.show:
select.show_human(sels, config.stores)
if app is not None and do_select:
print(_("(use '0install update' to save the new parameters)"))
示例9: main
def main():
force_refresh = bool(options.refresh)
while True:
window.refresh_button.set_sensitive(False)
window.browser.set_update_icons(force_refresh)
solved = policy.solve_with_downloads(force = force_refresh, update_local = True)
if not window.systray_icon:
window.show()
yield solved
try:
window.refresh_button.set_sensitive(True)
window.browser.highlight_problems()
tasks.check(solved)
except Exception, ex:
window.report_exception(ex)
if window.systray_icon and window.systray_icon.get_visible() and \
window.systray_icon.is_embedded():
if policy.ready:
window.systray_icon.set_tooltip(_('Downloading updates for %s') % root_iface.get_name())
window.run_button.set_active(True)
else:
# Should already be reporting an error, but
# blink it again just in case
window.systray_icon.set_blinking(True)
refresh_clicked = dialog.ButtonClickedBlocker(window.refresh_button)
yield refresh_clicked, _recalculate
if refresh_clicked.happened:
force_refresh = True
示例10: testDistro
def testDistro(self):
with output_suppressed():
native_url = 'http://example.com:8000/Native.xml'
# Initially, we don't have the feed at all...
master_feed = self.config.iface_cache.get_feed(native_url)
assert master_feed is None, master_feed
trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'example.com:8000')
run_server('Native.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B')
driver = Driver(requirements = Requirements(native_url), config = self.config)
assert driver.need_download()
solve = driver.solve_with_downloads()
tasks.wait_for_blocker(solve)
tasks.check(solve)
master_feed = self.config.iface_cache.get_feed(native_url)
assert master_feed is not None
assert master_feed.implementations == {}
distro_feed_url = master_feed.get_distro_feed()
assert distro_feed_url is not None
distro_feed = self.config.iface_cache.get_feed(distro_feed_url)
assert distro_feed is not None
assert len(distro_feed.implementations) == 2, distro_feed.implementations
示例11: download_keys
def download_keys(self, fetcher, feed_hint=None, key_mirror=None):
"""Download any required GPG keys not already on our keyring.
When all downloads are done (successful or otherwise), add any new keys
to the keyring, L{recheck}.
@param fetcher: fetcher to manage the download (was Handler before version 1.5)
@type fetcher: L{fetch.Fetcher}
@param key_mirror: URL of directory containing keys, or None to use feed's directory
@type key_mirror: str
@rtype: [L{zeroinstall.support.tasks.Blocker}]"""
downloads = {}
blockers = []
for x in self.sigs:
key_id = x.need_key()
if key_id:
try:
import urlparse
except ImportError:
from urllib import parse as urlparse # Python 3
key_url = urlparse.urljoin(key_mirror or self.url, "%s.gpg" % key_id)
logger.info(_("Fetching key from %s"), key_url)
dl = fetcher.download_url(key_url, hint=feed_hint)
downloads[dl.downloaded] = (dl, dl.tempfile)
blockers.append(dl.downloaded)
exception = None
any_success = False
from zeroinstall.support import tasks
while blockers:
yield blockers
old_blockers = blockers
blockers = []
for b in old_blockers:
dl, stream = downloads[b]
try:
tasks.check(b)
if b.happened:
stream.seek(0)
self._downloaded_key(stream)
any_success = True
stream.close()
else:
blockers.append(b)
except Exception:
_type, exception, tb = sys.exc_info()
logger.warning(
_("Failed to import key for '%(url)s': %(exception)s"),
{"url": self.url, "exception": str(exception)},
)
stream.close()
if exception and not any_success:
raise_with_traceback(exception, tb)
self.recheck()
示例12: doTest
def doTest(self):
imp.reload(packagekit)
pk = packagekit.PackageKit()
assert pk.available
# Check none is found yet
factory = Exception("not called")
pk.get_candidates('gimp', factory, 'package:test')
blocker = pk.fetch_candidates(["gimp"])
blocker2 = pk.fetch_candidates(["gimp"]) # Check batching too
@tasks.async
def wait():
yield blocker, blocker2
if blocker.happened:
tasks.check(blocker)
else:
tasks.check(blocker2)
tasks.wait_for_blocker(wait())
impls = {}
def factory(impl_id, only_if_missing, installed):
assert impl_id.startswith('package:')
assert only_if_missing is True
assert installed is False
feed = None
impl = model.DistributionImplementation(feed, impl_id, self)
impl.installed = installed
impls[impl_id] = impl
return impl
pk.get_candidates('gimp', factory, 'package:test')
self.assertEqual(["package:test:gimp:2.6.8-2:x86_64"], list(impls.keys()))
self.assertEqual(False, list(impls.values())[0].installed)
impl, = impls.values()
self.config.handler.allow_downloads = True
_pk = pk.pk
rm, = impl.download_sources
dl = packagekit.PackageKitDownload('packagekit:' + rm.packagekit_id, hint = None,
pk = _pk, packagekit_id = rm.packagekit_id, expected_size = rm.size)
self.config.handler.monitor_download(dl)
b = dl.downloaded
tasks.wait_for_blocker(b)
tasks.check(b)
#self.assertEqual("/usr/bin/fixed", list(impls.values())[0].main) # Fixup not used in Python now
tasks.wait_for_blocker(blocker)
tasks.wait_for_blocker(blocker2)
# Don't fetch it again
tasks.wait_for_blocker(pk.fetch_candidates(["gimp"]))
示例13: confirm_import_feed
def confirm_import_feed(self, pending, valid_sigs):
"""Sub-classes should override this method to interact with the user about new feeds.
If multiple feeds need confirmation, L{confirm_keys} will only invoke one instance of this
method at a time.
@param pending: the new feed to be imported
@type pending: L{PendingFeed}
@param valid_sigs: maps signatures to a list of fetchers collecting information about the key
@type valid_sigs: {L{gpg.ValidSig} : L{fetch.KeyInfoFetcher}}
@since: 0.42
@see: L{confirm_keys}"""
from zeroinstall.injector import trust
assert valid_sigs
domain = trust.domain_from_url(pending.url)
# Ask on stderr, because we may be writing XML to stdout
print >>sys.stderr, _("Feed: %s") % pending.url
print >>sys.stderr, _("The feed is correctly signed with the following keys:")
for x in valid_sigs:
print >>sys.stderr, "-", x
def text(parent):
text = ""
for node in parent.childNodes:
if node.nodeType == node.TEXT_NODE:
text = text + node.data
return text
shown = set()
key_info_fetchers = valid_sigs.values()
while key_info_fetchers:
old_kfs = key_info_fetchers
key_info_fetchers = []
for kf in old_kfs:
infos = set(kf.info) - shown
if infos:
if len(valid_sigs) > 1:
print "%s: " % kf.fingerprint
for key_info in infos:
print >>sys.stderr, "-", text(key_info)
shown.add(key_info)
if kf.blocker:
key_info_fetchers.append(kf)
if key_info_fetchers:
for kf in key_info_fetchers: print >>sys.stderr, kf.status
stdin = tasks.InputBlocker(0, 'console')
blockers = [kf.blocker for kf in key_info_fetchers] + [stdin]
yield blockers
for b in blockers:
try:
tasks.check(b)
except Exception, ex:
warn(_("Failed to get key info: %s"), ex)
if stdin.happened:
print >>sys.stderr, _("Skipping remaining key lookups due to input from user")
break
示例14: reply_when_done
def reply_when_done(ticket, blocker):
try:
if blocker:
yield blocker
tasks.check(blocker)
send_json(["return", ticket, ["ok", []]])
except Exception as ex:
logger.info("async task failed", exc_info = True)
send_json(["return", ticket, ["error", str(ex)]])
示例15: download
def download(self, dl, timeout = None):
"""@type dl: L{zeroinstall.injector.download.Download}"""
# (changed if we get redirected)
current_url = dl.url
redirections_remaining = 10
original_exception = None
# Assign the Download to a Site based on its scheme, host and port. If the result is a redirect,
# reassign it to the appropriate new site. Note that proxy handling happens later; we want to group
# and limit by the target site, not treat everything as going to a single site (the proxy).
while True:
location_parts = urlparse.urlparse(current_url)
site_key = (location_parts.scheme,
location_parts.hostname,
location_parts.port or default_port.get(location_parts.scheme, None))
step = DownloadStep()
step.dl = dl
step.url = current_url
blocker = self._sites[site_key].download(step, timeout)
yield blocker
try:
tasks.check(blocker)
except download.DownloadError as ex:
if original_exception is None:
original_exception = ex
else:
logger.warning("%s (while trying mirror)", ex)
mirror_url = step.dl.get_next_mirror_url()
if mirror_url is None:
raise original_exception
# Try the mirror.
# There are actually two places where we try to use the mirror: this one
# looks to see if we have an exact copy of same file somewhere else. If this
# fails, Fetcher will also look for a different archive that would generate
# the required implementation.
logger.warning("%s: trying archive mirror at %s", ex, mirror_url)
step.redirect = mirror_url
redirections_remaining = 10
if not step.redirect:
break
current_url = step.redirect
if redirections_remaining == 0:
raise download.DownloadError("Too many redirections {url} -> {current}".format(
url = dl.url,
current = current_url))
redirections_remaining -= 1