All Samples(10569) | Call(10083) | Derive(0) | Import(486)
Log a message with severity 'DEBUG' on the root logger.
def debug(msg, *args, **kwargs):
"""
Log a message with severity 'DEBUG' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.debug(msg, *args, **kwargs)
import os
import os.path
import logging
from logging import log, error, warning, info, debug
sys.path.append(os.path.abspath("")+"/../src/gnat/")
src/z/e/zero-install-HEAD/releases/0launch/injector-0.30/zeroinstall/injector/policy.py zero-install(Download)
import time import sys, os, sets from logging import info, debug, warn import arch from model import *
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
self.restrictions = {}
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.requires:
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
if f.os in arch.os_ranks and f.machine in machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
f, f.os, f.machine)
def get_ranked_implementations(self, iface):
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self._warned_offline:
debug("Nothing known about interface, but we are off-line.")
elif not uri.startswith('/'):
now = time.time()
staleness = now - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.freshness > 0 and staleness > self.freshness:
if iface.last_check_attempt and iface.last_check_attempt > now - FAILED_CHECK_DELAY:
debug("Stale, but tried to check recently (%s) so not rechecking now.", time.ctime(iface.last_check_attempt))
else:
debug("Adding %s to stale set", iface)
def begin_iface_download(self, interface, force = False):
"""Start downloading the interface, and add a callback to process it when
done. If it is already being downloaded, do nothing."""
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
# Possibly we should handle this better, but it's unlikely anyone will need
# to use an interface as an icon or implementation as well, and some of the code
# assumes it's OK keep asking for the same interface to be downloaded.
debug("Already have a handler for %s; not adding another", interface)
def begin_icon_download(self, interface, force = False):
"""Start downloading an icon for this interface. On success, add it to the
icon cache. If the interface has no icon, do nothing."""
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
"""Callback used by L{iface_cache.IfaceCache.update_interface_from_network}."""
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
raise SafeException("Missing <feed-for> element in '%s'; "
"this interface can't be used as a feed." % feed_iface_uri)
feed_targets = feed_iface.feed_for
debug("Feed targets: %s", feed_targets)
if not feed_iface.name:
warn("Warning: unknown interface '%s'" % feed_iface_uri)
return [iface_cache.get_interface(uri) for uri in feed_targets]
src/z/e/zero-install-HEAD/releases/0launch/injector-0.29/zeroinstall/injector/policy.py zero-install(Download)
import time import sys, os, sets from logging import info, debug, warn import arch from model import *
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
self.restrictions = {}
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.requires:
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
if f.os in arch.os_ranks and f.machine in machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
f, f.os, f.machine)
def get_ranked_implementations(self, iface):
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self._warned_offline:
debug("Nothing known about interface, but we are off-line.")
elif not uri.startswith('/'):
now = time.time()
staleness = now - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.freshness > 0 and staleness > self.freshness:
if iface.last_check_attempt and iface.last_check_attempt > now - FAILED_CHECK_DELAY:
debug("Stale, but tried to check recently (%s) so not rechecking now.", time.ctime(iface.last_check_attempt))
else:
debug("Adding %s to stale set", iface)
def begin_iface_download(self, interface, force = False):
"""Start downloading the interface, and add a callback to process it when
done. If it is already being downloaded, do nothing."""
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
# Possibly we should handle this better, but it's unlikely anyone will need
# to use an interface as an icon or implementation as well, and some of the code
# assumes it's OK keep asking for the same interface to be downloaded.
debug("Already have a handler for %s; not adding another", interface)
def begin_icon_download(self, interface, force = False):
"""Start downloading an icon for this interface. On success, add it to the
icon cache. If the interface has no icon, do nothing."""
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
"""Callback used by L{iface_cache.IfaceCache.update_interface_from_network}."""
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
raise SafeException("Missing <feed-for> element in '%s'; "
"this interface can't be used as a feed." % feed_iface_uri)
feed_targets = feed_iface.feed_for
debug("Feed targets: %s", feed_targets)
if not feed_iface.name:
warn("Warning: unknown interface '%s'" % feed_iface_uri)
return [iface_cache.get_interface(uri) for uri in feed_targets]
src/z/e/zero-install-HEAD/releases/0launch/injector-0.28/zeroinstall/injector/policy.py zero-install(Download)
import time import sys, os, sets from logging import info, debug, warn import arch from model import *
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
self.restrictions = {}
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.requires:
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
if f.os in arch.os_ranks and f.machine in machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
f, f.os, f.machine)
def get_ranked_implementations(self, iface):
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self._warned_offline:
debug("Nothing known about interface, but we are off-line.")
elif not uri.startswith('/'):
now = time.time()
staleness = now - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.freshness > 0 and staleness > self.freshness:
if iface.last_check_attempt and iface.last_check_attempt > now - FAILED_CHECK_DELAY:
debug("Stale, but tried to check recently (%s) so not rechecking now.", time.ctime(iface.last_check_attempt))
else:
debug("Adding %s to stale set", iface)
def begin_iface_download(self, interface, force = False):
"""Start downloading the interface, and add a callback to process it when
done. If it is already being downloaded, do nothing."""
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
# Possibly we should handle this better, but it's unlikely anyone will need
# to use an interface as an icon or implementation as well, and some of the code
# assumes it's OK keep asking for the same interface to be downloaded.
debug("Already have a handler for %s; not adding another", interface)
def begin_icon_download(self, interface, force = False):
"""Start downloading an icon for this interface. On success, add it to the
icon cache. If the interface has no icon, do nothing."""
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
"""Callback used by L{iface_cache.IfaceCache.update_interface_from_network}."""
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
raise SafeException("Missing <feed-for> element in '%s'; "
"this interface can't be used as a feed." % feed_iface_uri)
feed_targets = feed_iface.feed_for
debug("Feed targets: %s", feed_targets)
if not feed_iface.name:
warn("Warning: unknown interface '%s'" % feed_iface_uri)
return [iface_cache.get_interface(uri) for uri in feed_targets]
src/z/e/zero-install-HEAD/releases/0launch/injector-0.27/zeroinstall/injector/policy.py zero-install(Download)
import time import sys, os, sets from logging import info, debug, warn import arch from model import *
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
self.restrictions = {}
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.dependencies.values():
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
if f.os in arch.os_ranks and f.machine in machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
f, f.os, f.machine)
def get_ranked_implementations(self, iface):
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self._warned_offline:
debug("Nothing known about interface, but we are off-line.")
elif not uri.startswith('/'):
now = time.time()
staleness = now - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.freshness > 0 and staleness > self.freshness:
if iface.last_check_attempt and iface.last_check_attempt > now - FAILED_CHECK_DELAY:
debug("Stale, but tried to check recently (%s) so not rechecking now.", time.ctime(iface.last_check_attempt))
else:
debug("Adding %s to stale set", iface)
def begin_iface_download(self, interface, force = False):
"""Start downloading the interface, and add a callback to process it when
done. If it is already being downloaded, do nothing."""
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
# Possibly we should handle this better, but it's unlikely anyone will need
# to use an interface as an icon or implementation as well, and some of the code
# assumes it's OK keep asking for the same interface to be downloaded.
debug("Already have a handler for %s; not adding another", interface)
def begin_icon_download(self, interface, force = False):
"""Start downloading an icon for this interface. On success, add it to the
icon cache. If the interface has no icon, do nothing."""
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
"""Callback used by L{iface_cache.IfaceCache.update_interface_from_network}."""
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
raise SafeException("Missing <feed-for> element in '%s'; "
"this interface can't be used as a feed." % feed_iface_uri)
feed_targets = feed_iface.feed_for
debug("Feed targets: %s", feed_targets)
if not feed_iface.name:
warn("Warning: unknown interface '%s'" % feed_iface_uri)
return [iface_cache.get_interface(uri) for uri in feed_targets]
src/z/e/zero-install-HEAD/releases/0launch/injector-0.19/zeroinstall/injector/policy.py zero-install(Download)
# Copyright (C) 2006, Thomas Leonard # See the README file for details, or visit http://0install.net. import time import sys from logging import info, debug, warn import arch
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
def recalculate(self):
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(iface):
if iface in self.implementation:
debug("cycle; skipping second %s", iface)
return
self.implementation[iface] = None # Avoid cycles
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.dependencies.values():
debug("Considering dependency %s", d)
process(self.get_interface(d.interface))
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
def usable_feeds(self, iface):
"""Generator for iface.feeds that are valid for our architecture."""
for f in iface.feeds:
if f.os in arch.os_ranks and f.machine in arch.machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
def get_interface(self, uri):
iface = iface_cache.get_interface(uri)
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self.warned_offline:
debug("Nothing known about interface, but we are off-line.")
self.warned_offline = True
elif not uri.startswith('/'):
staleness = time.time() - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.network_use != network_offline and self.freshness > 0 and staleness > self.freshness:
debug("Updating %s", iface)
self.begin_iface_download(iface, False)
#else: debug("Local interface, so not checking staleness.")
return iface
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
dl = download.begin_iface_download(interface, force)
if not dl:
assert not force
debug("Already in progress")
return
debug("Need to download")
# Calls update_interface_from_network eventually on success
self.handler.monitor_download(dl)
def begin_icon_download(self, interface, force = False):
debug("begin_icon_download %s (force = %d)", interface, force)
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
continue
source = icon.getAttribute('href')
if source:
dl = download.begin_icon_download(interface, source, force)
if not dl:
assert not force
debug("Icon download already in progress")
return
debug("Waiting for icon to download")
def interface_changed(self, interface):
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
This is used by --feed. If there are no interfaces, raises SafeException."""
src/z/e/zero-install-HEAD/releases/0launch/injector-0.26/zeroinstall/injector/policy.py zero-install(Download)
import time import sys, os, sets from logging import info, debug, warn import arch from model import *
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
self.restrictions = {}
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.dependencies.values():
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
if f.os in arch.os_ranks and f.machine in machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
f, f.os, f.machine)
def get_ranked_implementations(self, iface):
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self._warned_offline:
debug("Nothing known about interface, but we are off-line.")
elif not uri.startswith('/'):
now = time.time()
staleness = now - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.freshness > 0 and staleness > self.freshness:
if iface.last_check_attempt and iface.last_check_attempt > now - FAILED_CHECK_DELAY:
debug("Stale, but tried to check recently (%s) so not rechecking now.", time.ctime(iface.last_check_attempt))
else:
debug("Adding %s to stale set", iface)
def begin_iface_download(self, interface, force = False):
"""Start downloading the interface, and add a callback to process it when
done. If it is already being downloaded, do nothing."""
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
def begin_icon_download(self, interface, force = False):
"""Start downloading an icon for this interface. On success, add it to the
icon cache. If the interface has no icon, do nothing."""
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
"""Callback used by L{iface_cache.IfaceCache.update_interface_from_network}."""
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
raise SafeException("Missing <feed-for> element in '%s'; "
"this interface can't be used as a feed." % feed_iface_uri)
feed_targets = feed_iface.feed_for
debug("Feed targets: %s", feed_targets)
if not feed_iface.name:
warn("Warning: unknown interface '%s'" % feed_iface_uri)
return [iface_cache.get_interface(uri) for uri in feed_targets]
src/z/e/zero-install-HEAD/releases/0launch/injector-0.23/zeroinstall/injector/policy.py zero-install(Download)
# Copyright (C) 2006, Thomas Leonard # See the README file for details, or visit http://0install.net. import time import sys, os from logging import info, debug, warn import arch
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
def recalculate(self):
self.restrictions = {} # Interface -> [Restriction]
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.dependencies.values():
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
if f.os in arch.os_ranks and f.machine in machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
f, f.os, f.machine)
def get_ranked_implementations(self, iface):
def get_interface(self, uri):
iface = iface_cache.get_interface(uri)
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self.warned_offline:
debug("Nothing known about interface, but we are off-line.")
self.warned_offline = True
elif not uri.startswith('/'):
staleness = time.time() - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.network_use != network_offline and self.freshness > 0 and staleness > self.freshness:
debug("Updating %s", iface)
self.begin_iface_download(iface, False)
#else: debug("Local interface, so not checking staleness.")
return iface
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
def begin_icon_download(self, interface, force = False):
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
This is used by --feed. If there are no interfaces, raises SafeException."""
src/z/e/zero-install-HEAD/releases/0launch/injector-0.22/zeroinstall/injector/policy.py zero-install(Download)
# Copyright (C) 2006, Thomas Leonard # See the README file for details, or visit http://0install.net. import time import sys, os from logging import info, debug, warn import arch
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
def recalculate(self):
self.restrictions = {} # Interface -> [Restriction]
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.dependencies.values():
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
def usable_feeds(self, iface):
"""Generator for iface.feeds that are valid for our architecture."""
for f in iface.feeds:
if f.os in arch.os_ranks and f.machine in arch.machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
def get_interface(self, uri):
iface = iface_cache.get_interface(uri)
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self.warned_offline:
debug("Nothing known about interface, but we are off-line.")
self.warned_offline = True
elif not uri.startswith('/'):
staleness = time.time() - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.network_use != network_offline and self.freshness > 0 and staleness > self.freshness:
debug("Updating %s", iface)
self.begin_iface_download(iface, False)
#else: debug("Local interface, so not checking staleness.")
return iface
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
def begin_icon_download(self, interface, force = False):
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
This is used by --feed. If there are no interfaces, raises SafeException."""
src/z/e/zero-install-HEAD/releases/0launch/injector-0.21/zeroinstall/injector/policy.py zero-install(Download)
# Copyright (C) 2006, Thomas Leonard # See the README file for details, or visit http://0install.net. import time import sys, os from logging import info, debug, warn import arch
# (allow self for backwards compat)
self.handler = handler or self
debug("Supported systems: '%s'", arch.os_ranks)
debug("Supported processors: '%s'", arch.machine_ranks)
path = basedir.load_first_config(config_site, config_prog, 'global')
def recalculate(self):
self.restrictions = {} # Interface -> [Restriction]
self.implementation = {}
self.ready = True
debug("Recalculate! root = %s", self.root)
def process(dep):
iface = self.get_interface(dep.interface)
if iface in self.implementation:
debug("Interface requested twice; skipping second %s", iface)
impl = self._get_best_implementation(iface)
if impl:
debug("Will use implementation %s (version %s)", impl, impl.get_version())
self.implementation[iface] = impl
for d in impl.dependencies.values():
debug("Considering dependency %s", d)
process(d)
else:
debug("No implementation chould be chosen yet");
def _get_best_implementation(self, iface):
impls = iface.implementations.values()
for f in self.usable_feeds(iface):
debug("Processing feed %s", f)
try:
feed_iface = self.get_interface(f.uri)
if feed_iface.name and iface.uri not in feed_iface.feed_for:
warn("Failed to load feed %s for %s: %s",
f, iface, str(ex))
debug("get_best_implementation(%s), with feeds: %s", iface, iface.feeds)
if not impls:
info("Interface %s has no implementations!", iface)
def usable_feeds(self, iface):
"""Generator for iface.feeds that are valid for our architecture."""
for f in iface.feeds:
if f.os in arch.os_ranks and f.machine in arch.machine_ranks:
yield f
else:
debug("Skipping '%s'; unsupported architecture %s-%s",
def get_interface(self, uri):
iface = iface_cache.get_interface(uri)
if iface.last_modified is None:
if self.network_use != network_offline:
debug("Interface not cached and not off-line. Downloading...")
self.begin_iface_download(iface)
else:
if self.warned_offline:
debug("Nothing known about interface, but we are off-line.")
self.warned_offline = True
elif not uri.startswith('/'):
staleness = time.time() - (iface.last_checked or 0)
debug("Staleness for %s is %.2f hours", iface, staleness / 3600.0)
if self.network_use != network_offline and self.freshness > 0 and staleness > self.freshness:
debug("Updating %s", iface)
self.begin_iface_download(iface, False)
#else: debug("Local interface, so not checking staleness.")
return iface
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
def begin_iface_download(self, interface, force = False):
debug("begin_iface_download %s (force = %d)", interface, force)
if interface.uri.startswith('/'):
return
debug("Need to download")
dl = self.handler.get_download(interface.uri, force = force)
if dl.on_success:
def begin_icon_download(self, interface, force = False):
debug("begin_icon_download %s (force = %d)", interface, force)
# Find a suitable icon to download
for icon in interface.get_metadata(XMLNS_IFACE, 'icon'):
type = icon.getAttribute('type')
if type != 'image/png':
debug('Skipping non-PNG icon')
def interface_changed(self, interface):
debug("interface_changed(%s): recalculating", interface)
self.recalculate()
def get_feed_targets(self, feed_iface_uri):
"""Return a list of Interfaces for which feed_iface can be a feed.
This is used by --feed. If there are no interfaces, raises SafeException."""
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next