本文整理汇总了Python中zeroinstall.injector.qdom.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLocalPath
def testLocalPath(self):
# 0launch --get-selections Local.xml
iface = os.path.join(mydir, "Local.xml")
p = policy.Policy(iface, config=self.config)
p.need_download()
assert p.ready
s1 = selections.Selections(p)
xml = s1.toDOM().toxml("utf-8")
# Reload selections and check they're the same
root = qdom.parse(StringIO(xml))
s2 = selections.Selections(root)
local_path = s2.selections[iface].local_path
assert os.path.isdir(local_path), local_path
assert not s2.selections[iface].digests, s2.selections[iface].digests
# Add a newer implementation and try again
feed = self.config.iface_cache.get_feed(iface)
impl = model.ZeroInstallImplementation(feed, "foo bar=123", local_path=None)
impl.version = model.parse_version("1.0")
impl.commands["run"] = model.Command(qdom.Element(namespaces.XMLNS_IFACE, "command", {"path": "dummy"}), None)
impl.add_download_source("http://localhost/bar.tgz", 1000, None)
feed.implementations = {impl.id: impl}
assert p.need_download()
assert p.ready, p.solver.get_failure_reason()
s1 = selections.Selections(p)
xml = s1.toDOM().toxml("utf-8")
root = qdom.parse(StringIO(xml))
s2 = selections.Selections(root)
xml = s2.toDOM().toxml("utf-8")
qdom.parse(StringIO(xml))
assert s2.selections[iface].local_path is None
assert not s2.selections[iface].digests, s2.selections[iface].digests
assert s2.selections[iface].id == "foo bar=123"
示例2: testLocalPath
def testLocalPath(self):
# 0launch --get-selections Local.xml
iface = os.path.join(mydir, "Local.xml")
driver = Driver(requirements = Requirements(iface), config = self.config)
driver.need_download()
assert driver.solver.ready
s1 = driver.solver.selections
xml = s1.toDOM().toxml("utf-8")
# Reload selections and check they're the same
root = qdom.parse(BytesIO(xml))
s2 = selections.Selections(root)
local_path = s2.selections[iface].local_path
assert os.path.isdir(local_path), local_path
assert not s2.selections[iface].digests, s2.selections[iface].digests
# Add a newer implementation and try again
feed = self.config.iface_cache.get_feed(iface)
impl = model.ZeroInstallImplementation(feed, "foo bar=123", local_path = None)
impl.version = model.parse_version('1.0')
impl.commands["run"] = model.Command(qdom.Element(namespaces.XMLNS_IFACE, 'command', {'path': 'dummy', 'name': 'run'}), None)
impl.add_download_source('http://localhost/bar.tgz', 1000, None)
feed.implementations = {impl.id: impl}
assert driver.need_download()
assert driver.solver.ready, driver.solver.get_failure_reason()
s1 = driver.solver.selections
xml = s1.toDOM().toxml("utf-8")
root = qdom.parse(BytesIO(xml))
s2 = selections.Selections(root)
xml = s2.toDOM().toxml("utf-8")
qdom.parse(BytesIO(xml))
assert s2.selections[iface].local_path is None
assert not s2.selections[iface].digests, s2.selections[iface].digests
assert s2.selections[iface].id == 'foo bar=123'
示例3: get_selections
def get_selections(self, prompt = False):
if self._selections:
assert not prompt
return self._selections
selections_file = self.config.get('compile', 'selections')
if selections_file:
if prompt:
raise SafeException("Selections are fixed by %s" % selections_file)
stream = file(selections_file)
try:
self._selections = selections.Selections(qdom.parse(stream))
finally:
stream.close()
from zeroinstall.injector import handler
from zeroinstall.injector.config import load_config
if os.isatty(1):
h = handler.ConsoleHandler()
else:
h = handler.Handler()
config = load_config(h)
blocker = self._selections.download_missing(config)
if blocker:
print "Waiting for selected implementations to be downloaded..."
h.wait_for_blocker(blocker)
else:
command = install_prog + ['download', '--source', '--xml']
if prompt and '--console' not in install_prog:
if os.name == 'nt':
command[0] += '-win'
command.append('--gui')
command.append(self.interface)
child = subprocess.Popen(command, stdout = subprocess.PIPE)
try:
self._selections = selections.Selections(qdom.parse(child.stdout))
finally:
if child.wait():
raise SafeException(' '.join(repr(x) for x in command) + " failed (exit code %d)" % child.returncode)
self.root_impl = self._selections.selections[self.interface]
self.orig_srcdir = os.path.realpath(lookup(self.root_impl))
self.user_srcdir = None
if os.path.isdir('src'):
self.user_srcdir = os.path.realpath('src')
if self.user_srcdir == self.orig_srcdir or \
self.user_srcdir.startswith(os.path.join(self.orig_srcdir, '')) or \
self.orig_srcdir.startswith(os.path.join(self.user_srcdir, '')):
info("Ignoring 'src' directory because it coincides with %s",
self.orig_srcdir)
self.user_srcdir = None
return self._selections
示例4: testOverlay
def testOverlay(self):
for xml, expected in [(b'<overlay/>', '<overlay . on />'),
(b'<overlay src="usr"/>', '<overlay usr on />'),
(b'<overlay src="package" mount-point="/usr/games"/>', '<overlay package on /usr/games>')]:
e = qdom.parse(BytesIO(xml))
ol = model.process_binding(e)
self.assertEqual(expected, str(ol))
doc = minidom.parseString('<doc/>')
new_xml = ol._toxml(doc, None).toxml(encoding = 'utf-8')
new_e = qdom.parse(BytesIO(new_xml))
new_ol = model.process_binding(new_e)
self.assertEqual(expected, str(new_ol))
示例5: testOldCommands
def testOldCommands(self):
command_feed = os.path.join(mydir, 'old-selections.xml')
with open(command_feed, 'rb') as stream:
s1 = selections.Selections(qdom.parse(stream))
self.assertEqual("run", s1.command)
self.assertEqual(2, len(s1.commands))
self.assertEqual("bin/java", s1.commands[1].path)
xml = s1.toDOM().toxml("utf-8")
root = qdom.parse(BytesIO(xml))
s2 = selections.Selections(root)
self.assertEqual("run", s2.command)
self.assertEqual(2, len(s2.commands))
self.assertEqual("bin/java", s2.commands[1].path)
示例6: testDownload
def testDownload(self):
out, err = self.run_0install(['download'])
assert out.lower().startswith("usage:")
assert '--show' in out
out, err = self.run_0install(['download', 'Local.xml', '--show'])
assert not err, err
assert 'Version: 0.1' in out
local_uri = model.canonical_iface_uri('Local.xml')
out, err = self.run_0install(['download', 'Local.xml', '--xml'])
assert not err, err
sels = selections.Selections(qdom.parse(BytesIO(str(out).encode('utf-8'))))
assert sels.selections[local_uri].version == '0.1'
out, err = self.run_0install(['download', 'Local.xml', '--show', '--with-store=/foo'])
assert not err, err
assert self.config.stores.stores[-1].dir == '/foo'
out, err = self.run_0install(['download', '--offline', 'selections.xml'])
assert 'Would download' in err
self.config.network_use = model.network_full
self.config.stores = TestStores()
digest = 'sha1=3ce644dc725f1d21cfcf02562c76f375944b266a'
self.config.fetcher.allow_download(digest)
out, err = self.run_0install(['download', 'Hello.xml', '--show'])
assert not err, err
assert self.config.stores.lookup_any([digest]).startswith('/fake')
assert 'Version: 1\n' in out
out, err = self.run_0install(['download', '--offline', 'selections.xml', '--show'])
assert '/fake_store' in out
self.config.network_use = model.network_full
示例7: action_help
def action_help(self, uri):
from zeroinstall.injector.config import load_config
c = load_config()
xml = subprocess.check_output(['0install', 'download', '--xml', '--', uri], universal_newlines = False)
sels = selections.Selections(qdom.parse(BytesIO(xml)))
impl = sels.selections[uri]
assert impl, "Failed to choose an implementation of %s" % uri
help_dir = impl.attrs.get('doc-dir')
if impl.id.startswith('package:'):
assert os.path.isabs(help_dir), "Package doc-dir must be absolute!"
path = help_dir
else:
path = impl.local_path or c.stores.lookup_any(impl.digests)
assert path, "Chosen implementation is not cached!"
if help_dir:
path = os.path.join(path, help_dir)
else:
main = impl.main
if main:
# Hack for ROX applications. They should be updated to
# set doc-dir.
help_dir = os.path.join(path, os.path.dirname(main), 'Help')
if os.path.isdir(help_dir):
path = help_dir
# xdg-open has no "safe" mode, so check we're not "opening" an application.
if os.path.exists(os.path.join(path, 'AppRun')):
raise Exception(_("Documentation directory '%s' is an AppDir; refusing to open") % path)
subprocess.Popen(['xdg-open', path])
示例8: testDownload
def testDownload(self):
out, err = self.run_0install(["download"])
assert out.lower().startswith("usage:")
assert "--show" in out
out, err = self.run_0install(["download", "Local.xml", "--show"])
assert not err, err
assert "Version: 0.1" in out
local_uri = model.canonical_iface_uri("Local.xml")
out, err = self.run_0install(["download", "Local.xml", "--xml"])
assert not err, err
sels = selections.Selections(qdom.parse(StringIO(str(out))))
assert sels.selections[local_uri].version == "0.1"
out, err = self.run_0install(["download", "Local.xml", "--show", "--with-store=/foo"])
assert not err, err
assert self.config.stores.stores[-1].dir == "/foo"
out, err = self.run_0install(["download", "--offline", "selections.xml"])
assert "Would download" in err
self.config.network_use = model.network_full
self.config.stores = TestStores()
digest = "sha1=3ce644dc725f1d21cfcf02562c76f375944b266a"
self.config.fetcher.allow_download(digest)
out, err = self.run_0install(["download", "Hello.xml", "--show"])
assert not err, err
assert self.config.stores.lookup_any([digest]).startswith("/fake")
assert "Version: 1\n" in out
out, err = self.run_0install(["download", "--offline", "selections.xml", "--show"])
assert "/fake_store" in out
self.config.network_use = model.network_full
示例9: testSelections
def testSelections(self):
from zeroinstall.injector import cli
root = qdom.parse(file("selections.xml"))
sels = selections.Selections(root)
class Options:
dry_run = False
with output_suppressed():
self.child = server.handle_requests(
"Hello.xml",
"6FCF121BE2390E0B.gpg",
"/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B",
"HelloWorld.tgz",
)
sys.stdin = Reply("Y\n")
try:
self.config.stores.lookup_any(sels.selections["http://example.com:8000/Hello.xml"].digests)
assert False
except NotStored:
pass
cli.main(["--download-only", "selections.xml"])
path = self.config.stores.lookup_any(sels.selections["http://example.com:8000/Hello.xml"].digests)
assert os.path.exists(os.path.join(path, "HelloWorld", "main"))
assert sels.download_missing(self.config) is None
示例10: load_feed
def load_feed(source, local=False):
"""Load a feed from a local file.
@param source: the name of the file to read
@type source: str
@param local: this is a local feed
@type local: bool
@return: the new feed
@rtype: L{ZeroInstallFeed}
@raise InvalidInterface: if the source's syntax is incorrect
@since: 0.48
@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
try:
with open(source, "rb") as stream:
root = qdom.parse(stream, filter_for_version=True)
except IOError as ex:
if ex.errno == errno.ENOENT and local:
raise MissingLocalFeed(
_(
"Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."
)
)
raise InvalidInterface(_("Can't read file"), ex)
except Exception as ex:
raise InvalidInterface(_("Invalid XML"), ex)
if local:
assert os.path.isabs(source), source
local_path = source
else:
local_path = None
feed = ZeroInstallFeed(root, local_path)
feed.last_modified = int(os.stat(source).st_mtime)
return feed
示例11: handle
def handle(args):
files = [abspath(f) for f in args.path]
if not cmd.find_config(missing_ok = True):
# Import into appropriate registry for this feed
with open(files[0], 'rb') as stream:
doc = qdom.parse(stream)
master = incoming.get_feed_url(doc, files[0])
from_registry = registry.lookup(master)
assert from_registry['type'] == 'local', 'Unsupported registry type in %s' % from_registry
os.chdir(from_registry['path'])
print("Adding to registry '{path}'".format(path = from_registry['path']))
config = cmd.load_config()
messages = []
for feed in files:
print("Adding", feed)
msg = incoming.process(config, feed, delete_on_success = False)
if msg:
messages.append(msg)
update.do_update(config, messages = messages)
示例12: handle
def handle(config, options, args):
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()
if r.extra_restrictions and not options.xml:
print("User-provided restrictions in force:")
for uri, expr in r.extra_restrictions.items():
print(" {uri}: {expr}".format(uri = uri, expr = expr))
print()
elif os.path.exists(args[0]):
with open(args[0], 'rb') as stream:
sels = selections.Selections(qdom.parse(stream))
else:
raise SafeException(_("Neither an app nor a file: '%s'") % args[0])
if options.root_uri:
print(sels.interface)
elif options.xml:
select.show_xml(sels)
else:
select.show_human(sels, config.stores)
示例13: testSelect
def testSelect(self):
out, err = self.run_ocaml(['select'])
assert out.lower().startswith("usage:")
assert '--xml' in out
out, err = self.run_ocaml(['select', 'Local.xml'])
assert not err, err
assert 'Version: 0.1' in out
out, err = self.run_ocaml(['select', 'Local.xml', '--command='])
assert not err, err
assert 'Version: 0.1' in out
local_uri = os.path.realpath('Local.xml')
out, err = self.run_ocaml(['select', 'Local.xml'])
assert not err, err
assert 'Version: 0.1' in out
out, err = self.run_ocaml(['select', 'Local.xml', '--xml'])
sels = selections.Selections(qdom.parse(BytesIO(str(out).encode('utf-8'))))
assert sels.selections[local_uri].version == '0.1'
# This now triggers a download to fetch the feed.
#out, err = self.run_ocaml(['select', 'selections.xml'])
#assert not err, err
#assert 'Version: 1\n' in out
#assert '(not cached)' in out
out, err = self.run_ocaml(['select', 'runnable/RunExec.xml'])
assert not err, err
assert 'Runner' in out, out
示例14: build
def build(selections_xml):
# Get the chosen versions
sels = selections.Selections(qdom.parse(BytesIO(selections_xml)))
impl = sels.selections[interface_uri]
min_version = impl.attrs.get(XMLNS_0COMPILE + " min-version", our_min_version)
# Check the syntax is valid and the version is high enough
if model.parse_version(min_version) < model.parse_version(our_min_version):
min_version = our_min_version
# Do the whole build-and-register-feed
c = Command()
c.run(
(
"0launch",
"--message",
_("Download the 0compile tool, to compile the source code"),
"--not-before=" + min_version,
"http://0install.net/2006/interfaces/0compile.xml",
"gui",
interface_uri,
),
lambda unused: on_success(),
)
示例15: testLocale
def testLocale(self):
local_path = os.path.join(mydir, 'Local.xml')
with open(local_path, 'rb') as stream:
dom = qdom.parse(stream)
feed = model.ZeroInstallFeed(dom, local_path = local_path)
# (defaults to en-US if no language is set in the locale)
self.assertEqual("Local feed (English)", feed.summary)
self.assertEqual("English", feed.description)
self.assertEqual(4, len(feed.summaries))
self.assertEqual(2, len(feed.descriptions))
try:
basetest.test_locale = ('es_ES', 'UTF8')
self.assertEqual("Fuente local", feed.summary)
self.assertEqual("Español", feed.description)
basetest.test_locale = ('en_GB', 'UTF8')
self.assertEqual("Local feed (English GB)", feed.summary)
basetest.test_locale = ('fr_FR', 'UTF8')
self.assertEqual("Local feed (English)", feed.summary)
self.assertEqual("English", feed.description)
finally:
basetest.test_locale = (None, None)