23"""@type interface: L{Interface} 24 @type site_packages: str 25 @type known_site_feeds: {str}""" 26forimplinos.listdir(site_packages): 27ifimpl.startswith('.'):continue 28feed=os.path.join(site_packages,impl,'0install','feed.xml') 29ifnotos.path.exists(feed): 30logger.warning(_("Site-local feed {path} not found").format(path=feed)) 31logger.debug("Adding site-local feed '%s'",feed) 32 33# (we treat these as user overrides in order to let old versions of 0install 34# find them) 35interface.extra_feeds.append(Feed(feed,None,user_override=True,site_package=True)) 36known_site_feeds.add(feed)
39"""Read a cached interface and any native feeds or user overrides. 40 @param interface: the interface object to update 41 @type interface: L{model.Interface} 42 @type iface_cache: L{zeroinstall.injector.iface_cache.IfaceCache} | None 43 @return: True if cached version and user overrides loaded OK. 44 False if upstream not cached. Local interfaces (starting with /) are 45 always considered to be cached, although they are not actually stored in the cache. 46 @rtype: bool 47 @note: internal; use L{iface_cache.IfaceCache.get_interface} instread.""" 48interface.reset() 49ififace_cacheisNone: 50importwarnings 51warnings.warn("iface_cache should be specified",DeprecationWarning,2) 52fromzeroinstall.injectorimportpolicy 53iface_cache=policy.get_deprecated_singleton_config().iface_cache 54 55# Add the distribution package manager's version, if any 56path=basedir.load_first_data(config_site,'native_feeds',model._pretty_escape(interface.uri)) 57ifpath: 58# Resolve any symlinks 59logger.info(_("Adding native packager feed '%s'"),path) 60interface.extra_feeds.append(Feed(os.path.realpath(path),None,False)) 61 62# Add locally-compiled binaries, if any 63escaped_uri=model.escape_interface_uri(interface.uri) 64known_site_feeds=set() 65forpathinbasedir.load_data_paths(config_site,'site-packages',*escaped_uri): 66try: 67_add_site_packages(interface,path,known_site_feeds) 68exceptExceptionasex: 69logger.warning("Error loading site packages from {path}: {ex}".format(path=path,ex=ex)) 70 71update_user_overrides(interface,known_site_feeds) 72 73main_feed=iface_cache.get_feed(interface.uri,force=True) 74ifmain_feed: 75update_user_feed_overrides(main_feed) 76 77returnmain_feedisnotNone
80"""Load a feed. If the feed is remote, load from the cache. If local, load it directly. 81 @type url: str 82 @type selections_ok: bool 83 @return: the feed, or None if it's remote and not cached. 84 @rtype: L{ZeroInstallFeed} | None""" 85try: 86ifos.path.isabs(url): 87logger.debug(_("Loading local feed file '%s'"),url) 88returnload_feed(url,local=True,selections_ok=selections_ok) 89else: 90cached=basedir.load_first_cache(config_site,'interfaces',escape(url)) 91ifcached: 92logger.debug(_("Loading cached information for %(interface)s from %(cached)s"),{'interface':url,'cached':cached}) 93returnload_feed(cached,local=False) 94else: 95returnNone 96exceptInvalidInterfaceasex: 97ex.feed_url=url 98raise
101"""Update a feed with user-supplied information.102 Sets last_checked and user_stability ratings.103 @param feed: feed to update104 @type feed: L{ZeroInstallFeed}105 @since 0.49"""106user=basedir.load_first_config(config_site,config_prog,107'feeds',model._pretty_escape(feed.url))108ifuserisNone:109# For files saved by 0launch < 0.49110user=basedir.load_first_config(config_site,config_prog,111'user_overrides',escape(feed.url))112ifnotuser:113return114115try:116withopen(user,'rb')asstream:117root=qdom.parse(stream)118exceptExceptionasex:119logger.warning(_("Error reading '%(user)s': %(exception)s"),{'user':user,'exception':ex})120raise121122last_checked=root.getAttribute('last-checked')123iflast_checked:124feed.last_checked=int(last_checked)125126foriteminroot.childNodes:127ifitem.uri!=XMLNS_IFACE:continue128ifitem.name=='implementation':129id=item.getAttribute('id')130assertidisnotNone131impl=feed.implementations.get(id,None)132ifnotimpl:133logger.debug(_("Ignoring user-override for unknown implementation %(id)s in %(interface)s"),{'id':id,'interface':feed})134continue135136user_stability=item.getAttribute('user-stability')137ifuser_stability:138impl.user_stability=stability_levels[str(user_stability)]
141"""Update an interface with user-supplied information.142 Sets preferred stability and updates extra_feeds.143 @param interface: the interface object to update144 @type interface: L{model.Interface}145 @param known_site_feeds: feeds to ignore (for backwards compatibility)146 @type known_site_feeds: {str}"""147user=basedir.load_first_config(config_site,config_prog,148'interfaces',model._pretty_escape(interface.uri))149ifuserisNone:150# For files saved by 0launch < 0.49151user=basedir.load_first_config(config_site,config_prog,152'user_overrides',escape(interface.uri))153ifnotuser:154return155156try:157withopen(user,'rb')asstream:158root=qdom.parse(stream)159exceptExceptionasex:160logger.warning(_("Error reading '%(user)s': %(exception)s"),{'user':user,'exception':ex})161raise162163stability_policy=root.getAttribute('stability-policy')164ifstability_policy:165interface.set_stability_policy(stability_levels[str(stability_policy)])166167foriteminroot.childNodes:168ifitem.uri!=XMLNS_IFACE:continue169ifitem.name=='feed':170feed_src=item.getAttribute('src')171ifnotfeed_src:172raiseInvalidInterface(_('Missing "src" attribute in <feed>'))173# (note: 0install 1.9..1.12 used a different scheme and the "site-package" attribute;174# we deliberately use a different attribute name to avoid confusion)175ifitem.getAttribute('is-site-package'):176# Site packages are detected earlier. This test isn't completely reliable,177# since older versions will remove the attribute when saving the config178# (hence the next test).179continue180iffeed_srcinknown_site_feeds:181continue182interface.extra_feeds.append(Feed(feed_src,item.getAttribute('arch'),True,langs=item.getAttribute('langs')))
185"""Test whether a feed file is valid.186 @param feed_url: the feed's expected URL187 @type feed_url: str188 @param source: the name of the file to test189 @type source: str190 @return: the modification time in src (usually just the mtime of the file)191 @rtype: int192 @raise InvalidInterface: If the source's syntax is incorrect"""193try:194feed=load_feed(source,local=False)195196iffeed.url!=feed_url:197raiseInvalidInterface(_("Incorrect URL used for feed.\n\n"198"%(feed_url)s is given in the feed, but\n"199"%(interface_uri)s was requested")%200{'feed_url':feed.url,'interface_uri':feed_url})201returnfeed.last_modified202exceptInvalidInterfaceasex:203logger.info(_("Error loading feed:\n"204"Interface URI: %(uri)s\n"205"Local file: %(source)s\n"206"%(exception)s")%207{'uri':feed_url,'source':source,'exception':ex})208raiseInvalidInterface(_("Error loading feed '%(uri)s':\n\n%(exception)s")%{'uri':feed_url,'exception':ex})
211"""Read in information about an interface.212 Deprecated.213 @param interface: the interface object to update214 @type interface: L{model.Interface}215 @param source: the name of the file to read216 @type source: str217 @param local: use file's mtime for last-modified, and uri attribute is ignored218 @type local: bool219 @type iface_cache: L{zeroinstall.injector.iface_cache.IfaceCache} | None220 @return: the new feed (since 0.32)221 @rtype: L{ZeroInstallFeed}222 @raise InvalidInterface: if the source's syntax is incorrect223 @see: L{update_from_cache}, which calls this"""224assertisinstance(interface,Interface)225226feed=load_feed(source,local)227228ifnotlocal:229iffeed.url!=interface.uri:230raiseInvalidInterface(_("Incorrect URL used for feed.\n\n"231"%(feed_url)s is given in the feed, but\n"232"%(interface_uri)s was requested")%233{'feed_url':feed.url,'interface_uri':interface.uri})234235ififace_cacheisNone:236importwarnings237warnings.warn("iface_cache should be specified",DeprecationWarning,2)238fromzeroinstall.injectorimportpolicy239iface_cache=policy.get_deprecated_singleton_config().iface_cache240iface_cache._feeds[support.unicode(interface.uri)]=feed241242returnfeed
245"""Load a feed from a local file.246 @param source: the name of the file to read247 @type source: str248 @param local: this is a local feed249 @type local: bool250 @param selections_ok: if it turns out to be a local selections document, return that instead251 @type selections_ok: bool252 @return: the new feed253 @rtype: L{ZeroInstallFeed}254 @raise InvalidInterface: if the source's syntax is incorrect255 @since: 0.48256 @see: L{iface_cache.iface_cache}, which uses this to load the feeds"""257try:258withopen(source,'rb')asstream:259root=qdom.parse(stream,filter_for_version=True)260exceptIOErrorasex:261ifex.errno==errno.ENOENTandlocal:262raiseMissingLocalFeed(_("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."))263raiseInvalidInterface(_("Can't read file"),ex)264exceptExceptionasex:265raiseInvalidInterface(_("Invalid XML"),ex)266267iflocal:268ifselections_okandroot.uri==XMLNS_IFACEandroot.name=='selections':269fromzeroinstall.injectorimportselections270returnselections.Selections(root)271assertos.path.isabs(source),source272local_path=source273else:274local_path=None275feed=ZeroInstallFeed(root,local_path)276feed.last_modified=int(os.stat(source).st_mtime)277returnfeed