本文整理汇总了Python中zeroinstall.injector.policy.Policy类的典型用法代码示例。如果您正苦于以下问题:Python Policy类的具体用法?Python Policy怎么用?Python Policy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Policy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: testFeeds
def testFeeds(self):
self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="0"
uri="%s"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Foo</name>
<summary>Foo</summary>
<description>Foo</description>
<feed src='http://bar'/>
</interface>""" % foo_iface_uri)
self.cache_iface('http://bar',
"""<?xml version="1.0" ?>
<interface last-modified="0"
uri="http://bar"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<feed-for interface='%s'/>
<name>Bar</name>
<summary>Bar</summary>
<description>Bar</description>
<implementation version='1.0' id='sha1=123' main='dummy'>
<archive href='foo' size='10'/>
</implementation>
</interface>""" % foo_iface_uri)
policy = Policy(foo_iface_uri, config = self.config)
policy.freshness = 0
policy.network_use = model.network_full
recalculate(policy)
assert policy.ready
foo_iface = self.config.iface_cache.get_interface(foo_iface_uri)
self.assertEquals('sha1=123', policy.implementation[foo_iface].id)
示例3: testNoNeedDl
def testNoNeedDl(self):
policy = Policy(foo_iface_uri, config = self.config)
policy.freshness = 0
assert policy.need_download()
policy = Policy(os.path.abspath('Foo.xml'), config = self.config)
assert not policy.need_download()
assert policy.ready
示例4: testConstraints
def testConstraints(self):
self.cache_iface('http://bar',
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
uri="http://bar"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Bar</name>
<summary>Bar</summary>
<description>Bar</description>
<implementation id='sha1=100' version='1.0'>
<archive href='foo' size='10'/>
</implementation>
<implementation id='sha1=150' stability='developer' version='1.5'>
<archive href='foo' size='10'/>
</implementation>
<implementation id='sha1=200' version='2.0'>
<archive href='foo' size='10'/>
</implementation>
</interface>""")
self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
uri="%s"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Foo</name>
<summary>Foo</summary>
<description>Foo</description>
<group main='dummy'>
<requires interface='http://bar'>
<version/>
</requires>
<implementation id='sha1=123' version='1.0'>
<archive href='foo' size='10'/>
</implementation>
</group>
</interface>""" % foo_iface_uri)
policy = Policy(foo_iface_uri, config = self.config)
policy.network_use = model.network_full
policy.freshness = 0
#logger.setLevel(logging.DEBUG)
recalculate(policy)
#logger.setLevel(logging.WARN)
foo_iface = self.config.iface_cache.get_interface(foo_iface_uri)
bar_iface = self.config.iface_cache.get_interface('http://bar')
assert policy.implementation[bar_iface].id == 'sha1=200'
dep = policy.implementation[foo_iface].dependencies['http://bar']
assert len(dep.restrictions) == 1
restriction = dep.restrictions[0]
restriction.before = model.parse_version('2.0')
recalculate(policy)
assert policy.implementation[bar_iface].id == 'sha1=100'
restriction.not_before = model.parse_version('1.5')
recalculate(policy)
assert policy.implementation[bar_iface].id == 'sha1=150'
示例5: testBackground
def testBackground(self, verbose=False):
p = Policy("http://example.com:8000/Hello.xml", config=self.config)
self.import_feed(p.root, "Hello.xml")
p.freshness = 0
p.network_use = model.network_minimal
p.solver.solve(p.root, arch.get_host_architecture())
assert p.ready, p.solver.get_failure_reason()
@tasks.async
def choose_download(registed_cb, nid, actions):
try:
assert actions == ["download", "Download"], actions
registed_cb(nid, "download")
except:
import traceback
traceback.print_exc()
yield None
global ran_gui
ran_gui = False
old_out = sys.stdout
try:
sys.stdout = StringIO()
self.child = server.handle_requests("Hello.xml", "6FCF121BE2390E0B.gpg")
my_dbus.system_services = {
"org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}
}
my_dbus.user_callback = choose_download
pid = os.getpid()
old_exit = os._exit
def my_exit(code):
# The background handler runs in the same process
# as the tests, so don't let it abort.
if os.getpid() == pid:
raise SystemExit(code)
# But, child download processes are OK
old_exit(code)
key_info = fetch.DEFAULT_KEY_LOOKUP_SERVER
fetch.DEFAULT_KEY_LOOKUP_SERVER = None
try:
try:
os._exit = my_exit
background.spawn_background_update(p, verbose)
assert False
except SystemExit, ex:
self.assertEquals(1, ex.code)
finally:
os._exit = old_exit
fetch.DEFAULT_KEY_LOOKUP_SERVER = key_info
finally:
sys.stdout = old_out
assert ran_gui
示例6: testAcceptKey
def testAcceptKey(self):
with output_suppressed():
self.child = server.handle_requests('Hello', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz')
policy = Policy('http://localhost:8000/Hello', config = self.config)
assert policy.need_download()
sys.stdin = Reply("Y\n")
try:
download_and_execute(policy, ['Hello'], main = 'Missing')
assert 0
except model.SafeException as ex:
if "HelloWorld/Missing" not in str(ex):
raise
示例7: testNoArchives
def testNoArchives(self):
self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
uri="%s"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Foo</name>
<summary>Foo</summary>
<description>Foo</description>
<implementation id='sha1=123' version='1.0' main='dummy'/>
</interface>""" % foo_iface_uri)
policy = Policy(foo_iface_uri, config = self.config)
policy.freshness = 0
recalculate(policy)
assert not policy.ready
示例8: testRejectKey
def testRejectKey(self):
with output_suppressed():
self.child = server.handle_requests('Hello', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B')
policy = Policy('http://localhost:8000/Hello', config = self.config)
assert policy.need_download()
sys.stdin = Reply("N\n")
try:
download_and_execute(policy, ['Hello'])
assert 0
except model.SafeException as ex:
if "has no usable implementations" not in str(ex):
raise ex
if "Not signed with a trusted key" not in str(policy.handler.ex):
raise ex
self.config.handler.ex = None
示例9: testMirrors
def testMirrors(self):
old_out = sys.stdout
try:
sys.stdout = StringIO()
getLogger().setLevel(ERROR)
trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'example.com:8000')
self.child = server.handle_requests(server.Give404('/Hello.xml'), 'latest.xml', '/0mirror/keys/6FCF121BE2390E0B.gpg')
policy = Policy('http://example.com:8000/Hello.xml', config = self.config)
self.config.feed_mirror = 'http://example.com:8000/0mirror'
refreshed = policy.solve_with_downloads()
policy.handler.wait_for_blocker(refreshed)
assert policy.ready
finally:
sys.stdout = old_out
示例10: testWrongSize
def testWrongSize(self):
with output_suppressed():
self.child = server.handle_requests(
"Hello-wrong-size",
"6FCF121BE2390E0B.gpg",
"/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B",
"HelloWorld.tgz",
)
policy = Policy("http://localhost:8000/Hello-wrong-size", config=self.config)
assert policy.need_download()
sys.stdin = Reply("Y\n")
try:
download_and_execute(policy, ["Hello"], main="Missing")
assert 0
except model.SafeException, ex:
if "Downloaded archive has incorrect size" not in str(ex):
raise ex
示例11: testRejectKeyXML
def testRejectKeyXML(self):
with output_suppressed():
self.child = server.handle_requests(
"Hello.xml", "6FCF121BE2390E0B.gpg", "/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B"
)
policy = Policy("http://example.com:8000/Hello.xml", config=self.config)
assert policy.need_download()
sys.stdin = Reply("N\n")
try:
download_and_execute(policy, ["Hello"])
assert 0
except model.SafeException, ex:
if "has no usable implementations" not in str(ex):
raise ex
if "Not signed with a trusted key" not in str(policy.handler.ex):
raise
self.config.handler.ex = None
示例12: testCycle
def testCycle(self):
self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
uri="%s"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Foo</name>
<summary>Foo</summary>
<description>Foo</description>
<group>
<requires interface='%s'/>
<implementation id='sha1=123' version='1.0'>
<archive href='foo' size='10'/>
</implementation>
</group>
</interface>""" % (foo_iface_uri, foo_iface_uri))
policy = Policy(foo_iface_uri, config = self.config)
policy.freshness = 0
recalculate(policy)
示例13: _check_for_updates
def _check_for_updates(old_policy, verbose):
from zeroinstall.injector.policy import Policy
from zeroinstall.injector.config import load_config
iface_cache = old_policy.config.iface_cache
root_iface = iface_cache.get_interface(old_policy.root).get_name()
background_config = load_config(BackgroundHandler(root_iface, old_policy.root))
policy = Policy(config = background_config, requirements = old_policy.requirements)
info(_("Checking for updates to '%s' in a background process"), root_iface)
if verbose:
policy.handler.notify("Zero Install", _("Checking for updates to '%s'...") % root_iface, timeout = 1)
network_state = policy.handler.get_network_state()
if network_state != _NetworkState.NM_STATE_CONNECTED:
info(_("Not yet connected to network (status = %d). Sleeping for a bit..."), network_state)
import time
time.sleep(120)
if network_state in (_NetworkState.NM_STATE_DISCONNECTED, _NetworkState.NM_STATE_ASLEEP):
info(_("Still not connected to network. Giving up."))
sys.exit(1)
else:
info(_("NetworkManager says we're on-line. Good!"))
policy.freshness = 0 # Don't bother trying to refresh when getting the interface
refresh = policy.refresh_all() # (causes confusing log messages)
tasks.wait_for_blocker(refresh)
# We could even download the archives here, but for now just
# update the interfaces.
if not policy.need_download():
if verbose:
policy.handler.notify("Zero Install", _("No updates to download."), timeout = 1)
sys.exit(0)
policy.handler.notify("Zero Install",
_("Updates ready to download for '%s'.") % root_iface,
timeout = 1)
_exec_gui(policy.root, '--refresh', '--systray')
sys.exit(1)
示例14: testNeedDL
def testNeedDL(self):
self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="0"
uri="%s"
main='ThisBetterNotExist'
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Foo</name>
<summary>Foo</summary>
<description>Foo</description>
<implementation version='1.0' id='sha1=123'>
<archive href='http://foo/foo.tgz' size='100'/>
</implementation>
</interface>""" % foo_iface_uri)
policy = Policy(foo_iface_uri, config = self.config)
policy.freshness = 0
policy.network_use = model.network_full
recalculate(policy)
assert policy.need_download()
assert policy.ready
示例15: testBestUnusable
def testBestUnusable(self):
self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
uri="%s"
xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>Foo</name>
<summary>Foo</summary>
<description>Foo</description>
<implementation id='sha1=123' version='1.0' arch='odd-weird' main='dummy'/>
</interface>""" % foo_iface_uri)
policy = Policy(foo_iface_uri, config = self.config)
policy.network_use = model.network_offline
recalculate(policy)
assert not policy.ready, policy.implementation
try:
download_and_execute(policy, [])
assert False
except model.SafeException as ex:
assert "has no usable implementations" in str(ex), ex