本文整理汇总了Python中zeroinstall.support.tasks.wait_for_blocker函数的典型用法代码示例。如果您正苦于以下问题:Python wait_for_blocker函数的具体用法?Python wait_for_blocker怎么用?Python wait_for_blocker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wait_for_blocker函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testImplMirrorFails
def testImplMirrorFails(self):
with resourcewarnings_suppressed():
trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'example.com:8000')
run_server('/Hello.xml',
'/6FCF121BE2390E0B.gpg',
server.Give404('/HelloWorld.tgz'),
server.Give404('/0mirror/archive/http%3A%23%23example.com%3A8000%23HelloWorld.tgz'),
server.Give404('/0mirror/feeds/http/example.com:8000/Hello.xml/impl/sha1=3ce644dc725f1d21cfcf02562c76f375944b266a'))
driver = Driver(requirements = Requirements('http://example.com:8000/Hello.xml'), config = self.config)
self.config.mirror = 'http://example.com:8000/0mirror'
refreshed = driver.solve_with_downloads()
tasks.wait_for_blocker(refreshed)
assert driver.solver.ready
getLogger().setLevel(logging.ERROR)
try:
downloaded = driver.download_uncached_implementations()
tasks.wait_for_blocker(downloaded)
assert 0
except download.DownloadError as ex:
assert 'Missing: HelloWorld.tgz' in str(ex), ex
self.assertEqual([
'http://example.com:8000/Hello.xml',
'http://example.com:8000/6FCF121BE2390E0B.gpg',
# The original archive:
'http://example.com:8000/HelloWorld.tgz',
# Mirror of original archive:
'http://example.com:8000/0mirror/archive/http%3A%23%23example.com%3A8000%23HelloWorld.tgz',
# Mirror of implementation:
'http://example.com:8000/0mirror/feeds/http/example.com:8000/Hello.xml/impl/sha1=3ce644dc725f1d21cfcf02562c76f375944b266a'
], traced_downloads)
示例2: 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)"))
示例3: testReplay
def testReplay(self):
with resourcewarnings_suppressed():
old_out = sys.stdout
try:
sys.stdout = StringIO()
getLogger().setLevel(ERROR)
iface = self.config.iface_cache.get_interface('http://example.com:8000/Hello.xml')
mtime = int(os.stat('Hello-new.xml').st_mtime)
with open('Hello-new.xml', 'rb') as stream:
self.config.iface_cache.update_feed_from_network(iface.uri, stream.read(), mtime + 10000)
trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'example.com:8000')
run_server(server.Give404('/Hello.xml'), 'latest.xml', '/0mirror/keys/6FCF121BE2390E0B.gpg', 'Hello.xml')
self.config.mirror = 'http://example.com:8000/0mirror'
# Update from mirror (should ignore out-of-date timestamp)
refreshed = self.config.fetcher.download_and_import_feed(iface.uri, self.config.iface_cache)
tasks.wait_for_blocker(refreshed)
# Update from upstream (should report an error)
refreshed = self.config.fetcher.download_and_import_feed(iface.uri, self.config.iface_cache)
try:
tasks.wait_for_blocker(refreshed)
raise Exception("Should have been rejected!")
except model.SafeException as ex:
assert "New feed's modification time is before old version" in str(ex)
# Must finish with the newest version
self.assertEqual(1342285569, self.config.iface_cache._get_signature_date(iface.uri))
finally:
sys.stdout = old_out
示例4: get_selections
def get_selections(config, options, iface_uri, select_only, download_only, test_callback):
"""Get selections for iface_uri, according to the options passed.
Will switch to GUI mode if necessary.
@param options: options from OptionParser
@param iface_uri: canonical URI of the interface
@param select_only: return immediately even if the selected versions aren't cached
@param download_only: wait for stale feeds, and display GUI button as Download, not Run
@return: the selected versions, or None if the user cancels
@rtype: L{selections.Selections} | None
"""
if options.offline:
config.network_use = model.network_offline
iface_cache = config.iface_cache
# Try to load it as a feed. If it is a feed, it'll get cached. If not, it's a
# selections document and we return immediately.
maybe_selections = iface_cache.get_feed(iface_uri, selections_ok = True)
if isinstance(maybe_selections, selections.Selections):
if not select_only:
blocker = maybe_selections.download_missing(config)
if blocker:
logger.info(_("Waiting for selected implementations to be downloaded..."))
tasks.wait_for_blocker(blocker)
return maybe_selections
r = requirements.Requirements(iface_uri)
r.parse_options(options)
return get_selections_for(r, config, options, select_only, download_only, test_callback)
示例5: 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
示例6: ensure_cached
def ensure_cached(uri, command = 'run', config = None):
"""Ensure that an implementation of uri is cached.
If not, it downloads one. It uses the GUI if a display is
available, or the console otherwise.
@param uri: the required interface
@type uri: str
@return: the selected implementations, or None if the user cancelled
@rtype: L{zeroinstall.injector.selections.Selections}
"""
from zeroinstall.injector import policy, selections
if config is None:
from zeroinstall.injector.config import load_config
config = load_config()
p = policy.Policy(uri, command = command, config = config)
p.freshness = 0 # Don't check for updates
if p.need_download() or not p.ready:
if os.environ.get('DISPLAY', None):
return get_selections_gui(uri, ['--command', command])
else:
done = p.solve_and_download_impls()
tasks.wait_for_blocker(done)
return selections.Selections(p)
示例7: handle
def handle(config, options, args):
if args:
raise UsageError()
if options.offline:
config.network_use = model.network_offline
def slave_raw_input(prompt = ""):
ticket = take_ticket()
send_json(["invoke", ticket, ["input", prompt]])
while True:
message = recv_json()
if message[0] == 'return' and message[1] == ticket:
reply = message[2]
assert reply[0] == 'ok', reply
return reply[1]
else:
handle_message(config, options, message)
support.raw_input = slave_raw_input
@tasks.async
def handle_events():
while True:
logger.debug("waiting for stdin")
yield tasks.InputBlocker(stdin, 'wait for commands from master')
logger.debug("reading JSON")
message = recv_json()
logger.debug("got %s", message)
if message is None: break
handle_message(config, options, message)
tasks.wait_for_blocker(handle_events())
示例8: add_digests
def add_digests(feed_path, implementation, config):
root = qdom.Element(namespaces.XMLNS_IFACE, 'interface', {})
name = qdom.Element(namespaces.XMLNS_IFACE, 'name', {})
name.content = 'Test'
summary = qdom.Element(namespaces.XMLNS_IFACE, 'summary', {})
summary.content = 'testing'
test_impl = qdom.Element(namespaces.XMLNS_IFACE, 'implementation', {'id': 'sha1new=1', 'version': '0'})
root.childNodes = [name, summary, test_impl]
for child in implementation.childNodes:
if child.namespaceURI == namespaces.XMLNS_IFACE and child.localName in ('archive', 'file', 'recipe'):
test_impl.childNodes.append(dom_to_qdom(child))
feed = model.ZeroInstallFeed(root, local_path = feed_path)
impl, = feed.implementations.values()
assert impl.download_sources, "No retrieval methods in implementation!"
method, = impl.download_sources
basename_hrefs(method)
# When fetcher asks FakeStores to check the digest, FakeStores instead stores the actual
# digest on implementation.
fake_stores = FakeStores(implementation, config.stores)
blocker = config.fetcher.download_impl(impl, method, fake_stores)
tasks.wait_for_blocker(blocker)
示例9: handle
def handle(config, options, args):
if not args:
raise UsageError()
for x in args:
if not os.path.isfile(x):
raise SafeException(_("File '%s' does not exist") % x)
logger.info(_("Importing from file '%s'"), x)
with open(x, 'rb') as signed_data:
data, sigs = gpg.check_stream(signed_data)
doc = minidom.parseString(data.read())
uri = doc.documentElement.getAttribute('uri')
if not uri:
raise SafeException(_("Missing 'uri' attribute on root element in '%s'") % x)
logger.info(_("Importing information about interface %s"), uri)
signed_data.seek(0)
pending = PendingFeed(uri, signed_data)
def run():
keys_downloaded = tasks.Task(pending.download_keys(config.fetcher), "download keys")
yield keys_downloaded.finished
tasks.check(keys_downloaded.finished)
if not config.iface_cache.update_feed_if_trusted(uri, pending.sigs, pending.new_xml):
blocker = config.trust_mgr.confirm_keys(pending)
if blocker:
yield blocker
tasks.check(blocker)
if not config.iface_cache.update_feed_if_trusted(uri, pending.sigs, pending.new_xml):
raise SafeException(_("No signing keys trusted; not importing"))
task = tasks.Task(run(), "import feed")
tasks.wait_for_blocker(task.finished)
示例10: testDistro
def testDistro(self):
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')
out, err = self.run_ocaml(['download', native_url])
assert not out, out
assert "Can't find all required implementations" in err, err
master_feed = self.config.iface_cache.get_feed(native_url, force = True)
assert master_feed is not None
assert master_feed.implementations == {}
blocker = self.config.iface_cache.distro.fetch_candidates(master_feed)
if blocker:
tasks.wait_for_blocker(blocker)
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: ensure_cached
def ensure_cached(uri, command = 'run', config = None):
"""Ensure that an implementation of uri is cached.
If not, it downloads one. It uses the GUI if a display is
available, or the console otherwise.
@param uri: the required interface
@type uri: str
@return: the selected implementations, or None if the user cancelled
@rtype: L{zeroinstall.injector.selections.Selections}
"""
from zeroinstall.injector.driver import Driver
if config is None:
from zeroinstall.injector.config import load_config
config = load_config()
from zeroinstall.injector.requirements import Requirements
requirements = Requirements(uri)
requirements.command = command
d = Driver(config, requirements)
if d.need_download() or not d.solver.ready:
sels = get_selections_gui(uri, ['--command', command], use_gui = None)
if sels != DontUseGUI:
return sels
done = d.solve_and_download_impls()
tasks.wait_for_blocker(done)
return d.solver.selections
示例12: downloadZeroFeed
def downloadZeroFeed(url):
tasks.wait_for_blocker(download_info(url))
try:
zeroPath = ZeroFindPath(url)
return zeroPath
except:
return False
示例13: testRenameFailure
def testRenameFailure(self):
recipe = model.Recipe()
try:
recipe.steps.append(model.RenameStep("missing-source", "dest"))
blocker = self.config.fetcher.cook("sha256new_XXX", recipe, self.config.stores)
tasks.wait_for_blocker(blocker)
assert 0
except model.SafeException as ex:
assert "<rename> source 'missing-source' does not exist" in str(ex), ex
示例14: testDownloadIconFails
def testDownloadIconFails(self):
path = model.canonical_iface_uri(os.path.join(mydir, 'Binary.xml'))
iface = self.config.iface_cache.get_interface(path)
blocker = self.config.fetcher.download_icon(iface)
try:
tasks.wait_for_blocker(blocker)
assert False
except download.DownloadError as ex:
assert "Error downloading http://localhost/missing.png" in str(ex), ex
示例15: download_missing_selections
def download_missing_selections(sels):
from zeroinstall.support import tasks
from zeroinstall.injector.config import load_config
config = load_config()
blocker = sels.download_missing(config)
if blocker:
logging.info("Waiting for selected implementations to be downloaded...")
tasks.wait_for_blocker(blocker)