def update_from_cache(interface, iface_cache = None): """Read a cached interface and any native feeds or user overrides. @param interface: the interface object to update @type interface: L{model.Interface} @return: True if cached version and user overrides loaded OK. False if upstream not cached. Local interfaces (starting with /) are always considered to be cached, although they are not actually stored in the cache. Internal: use L{iface_cache.IfaceCache.get_interface} instread. @rtype: bool""" interface.reset() if iface_cache is None: from zeroinstall.injector import policy iface_cache = policy.get_deprecated_singleton_config().iface_cache # Add the distribution package manager's version, if any path = basedir.load_first_data(config_site, 'native_feeds', model._pretty_escape(interface.uri)) if path: # Resolve any symlinks info(_("Adding native packager feed '%s'"), path) interface.extra_feeds.append(Feed(os.path.realpath(path), None, False)) update_user_overrides(interface) main_feed = iface_cache.get_feed(interface.uri, force = True) if main_feed: update_user_feed_overrides(main_feed) return main_feed is not None
def update_from_cache(interface, iface_cache=None): """Read a cached interface and any native feeds or user overrides. @param interface: the interface object to update @type interface: L{model.Interface} @return: True if cached version and user overrides loaded OK. False if upstream not cached. Local interfaces (starting with /) are always considered to be cached, although they are not actually stored in the cache. Internal: use L{iface_cache.IfaceCache.get_interface} instread. @rtype: bool""" interface.reset() if iface_cache is None: from zeroinstall.injector import policy iface_cache = policy.get_deprecated_singleton_config().iface_cache # Add the distribution package manager's version, if any path = basedir.load_first_data(config_site, 'native_feeds', model._pretty_escape(interface.uri)) if path: # Resolve any symlinks info(_("Adding native packager feed '%s'"), path) interface.extra_feeds.append(Feed(os.path.realpath(path), None, False)) update_user_overrides(interface) main_feed = iface_cache.get_feed(interface.uri, force=True) if main_feed: update_user_feed_overrides(main_feed) return main_feed is not None
def testSitePackages(self): # The old system (0install < 1.9): # - 0compile stores implementations to ~/.cache, and # - adds to extra_feeds # # The middle system (0install 1.9..1.12) # - 0compile stores implementations to ~/.local/0install.net/site-packages # but using an obsolete escaping scheme, and # - modern 0install finds them via extra_feeds # # The new system (0install >= 1.13): # - 0compile stores implementations to ~/.local/0install.net/site-packages, and # - 0install finds them automatically # For backwards compatibility, 0install >= 1.9: # - writes discovered feeds to extra_feeds # - skips such entries in extra_feeds when loading expected_escape = 'section__prog_5f_1.xml' meta_dir = basedir.save_data_path('0install.net', 'site-packages', 'http', 'example.com', expected_escape, '1.0', '0install') feed = os.path.join(meta_dir, 'feed.xml') shutil.copyfile(os.path.join(mydir, 'Local.xml'), feed) # Check that we find the feed without us having to register it iface = self.config.iface_cache.get_interface('http://example.com/section/prog_1.xml') self.assertEqual(1, len(iface.extra_feeds)) site_feed, = iface.extra_feeds self.assertEqual(True, site_feed.site_package) # Check that we write it out, so that older 0installs can find it writer.save_interface(iface) config_file = basedir.load_first_config('0install.net', 'injector', 'interfaces', 'http:##example.com#section#prog_1.xml') with open(config_file, 'rb') as s: doc = qdom.parse(s) feed_node = None for item in doc.childNodes: if item.name == 'feed': feed_node = item self.assertEqual('True', feed_node.getAttribute('is-site-package')) # Check we ignore this element iface.reset() self.assertEqual([], iface.extra_feeds) reader.update_user_overrides(iface) self.assertEqual([], iface.extra_feeds) # Check feeds are automatically removed again reader.update_from_cache(iface, iface_cache = self.config.iface_cache) self.assertEqual(1, len(iface.extra_feeds)) shutil.rmtree(basedir.load_first_data('0install.net', 'site-packages', 'http', 'example.com', expected_escape)) reader.update_from_cache(iface, iface_cache = self.config.iface_cache) self.assertEqual(0, len(iface.extra_feeds))
def testSitePackages(self): # The old system (0install < 1.9): # - 0compile stores implementations to ~/.cache, and # - adds to extra_feeds # The new system (0install >= 1.9): # - 0compile stores implementations to ~/.local/0install.net/site-packages, and # - 0install finds them automatically # For backwards compatibility, 0install >= 1.9: # - writes discovered feeds to extra_feeds # - skips such entries in extra_feeds when loading meta_dir = basedir.save_data_path('0install.net', 'site-packages', 'http:##example.com#prog.xml', '1.0', '0install') feed = os.path.join(meta_dir, 'feed.xml') shutil.copyfile(os.path.join(mydir, 'Local.xml'), feed) # Check that we find the feed without us having to register it iface = self.config.iface_cache.get_interface('http://example.com/prog.xml') self.assertEqual(1, len(iface.extra_feeds)) site_feed, = iface.extra_feeds self.assertEqual(True, site_feed.site_package) # Check that we write it out, so that older 0installs can find it writer.save_interface(iface) config_file = basedir.load_first_config('0install.net', 'injector', 'interfaces', 'http:##example.com#prog.xml') with open(config_file, 'rb') as s: doc = qdom.parse(s) feed_node = None for item in doc.childNodes: if item.name == 'feed': feed_node = item self.assertEqual('True', feed_node.getAttribute('site-package')) # Check we ignore this element iface.reset() self.assertEqual([], iface.extra_feeds) reader.update_user_overrides(iface) self.assertEqual([], iface.extra_feeds) # Check feeds are automatically removed again reader.update_from_cache(iface, iface_cache = self.config.iface_cache) self.assertEqual(1, len(iface.extra_feeds)) shutil.rmtree(basedir.load_first_data('0install.net', 'site-packages', 'http:##example.com#prog.xml')) reader.update_from_cache(iface, iface_cache = self.config.iface_cache) self.assertEqual(0, len(iface.extra_feeds))
def update_from_cache(interface, iface_cache=None): """Read a cached interface and any native feeds or user overrides. @param interface: the interface object to update @type interface: L{model.Interface} @return: True if cached version and user overrides loaded OK. False if upstream not cached. Local interfaces (starting with /) are always considered to be cached, although they are not actually stored in the cache. Internal: use L{iface_cache.IfaceCache.get_interface} instread. @rtype: bool""" interface.reset() if iface_cache is None: import warnings warnings.warn("iface_cache should be specified", DeprecationWarning, 2) from zeroinstall.injector import policy iface_cache = policy.get_deprecated_singleton_config().iface_cache # Add the distribution package manager's version, if any path = basedir.load_first_data(config_site, 'native_feeds', model._pretty_escape(interface.uri)) if path: # Resolve any symlinks logger.info(_("Adding native packager feed '%s'"), path) interface.extra_feeds.append(Feed(os.path.realpath(path), None, False)) # Add locally-compiled binaries, if any escaped_uri = model.escape_interface_uri(interface.uri) known_site_feeds = set() for path in basedir.load_data_paths(config_site, 'site-packages', *escaped_uri): try: _add_site_packages(interface, path, known_site_feeds) except Exception as ex: logger.warn("Error loading site packages from {path}: {ex}".format( path=path, ex=ex)) update_user_overrides(interface, known_site_feeds) main_feed = iface_cache.get_feed(interface.uri, force=True) if main_feed: update_user_feed_overrides(main_feed) return main_feed is not None
def update_from_cache(interface, iface_cache=None): """Read a cached interface and any native feeds or user overrides. @param interface: the interface object to update @type interface: L{model.Interface} @return: True if cached version and user overrides loaded OK. False if upstream not cached. Local interfaces (starting with /) are always considered to be cached, although they are not actually stored in the cache. Internal: use L{iface_cache.IfaceCache.get_interface} instread. @rtype: bool""" interface.reset() if iface_cache is None: import warnings warnings.warn("iface_cache should be specified", DeprecationWarning, 2) from zeroinstall.injector import policy iface_cache = policy.get_deprecated_singleton_config().iface_cache # Add the distribution package manager's version, if any path = basedir.load_first_data(config_site, "native_feeds", model._pretty_escape(interface.uri)) if path: # Resolve any symlinks logger.info(_("Adding native packager feed '%s'"), path) interface.extra_feeds.append(Feed(os.path.realpath(path), None, False)) # Add locally-compiled binaries, if any escaped_uri = model.escape_interface_uri(interface.uri) known_site_feeds = set() for path in basedir.load_data_paths(config_site, "site-packages", *escaped_uri): try: _add_site_packages(interface, path, known_site_feeds) except Exception as ex: logger.warn("Error loading site packages from {path}: {ex}".format(path=path, ex=ex)) update_user_overrides(interface, known_site_feeds) main_feed = iface_cache.get_feed(interface.uri, force=True) if main_feed: update_user_feed_overrides(main_feed) return main_feed is not None
def update_from_cache(interface): """Read a cached interface and any native feeds or user overrides. @param interface: the interface object to update @type interface: L{model.Interface} @return: True if cached version and user overrides loaded OK. False if upstream not cached. Local interfaces (starting with /) are always considered to be cached, although they are not actually stored in the cache. @rtype: bool""" interface.reset() main_feed = None if interface.uri.startswith('/'): debug(_("Loading local interface file '%s'"), interface.uri) update(interface, interface.uri, local=True) cached = True else: cached = basedir.load_first_cache(config_site, 'interfaces', escape(interface.uri)) if cached: debug( _("Loading cached information for %(interface)s from %(cached)s" ), { 'interface': interface, 'cached': cached }) main_feed = update(interface, cached) # Add the distribution package manager's version, if any path = basedir.load_first_data(config_site, 'native_feeds', model._pretty_escape(interface.uri)) if path: # Resolve any symlinks info(_("Adding native packager feed '%s'"), path) interface.extra_feeds.append(Feed(os.path.realpath(path), None, False)) update_user_overrides(interface, main_feed) return bool(cached)