def testFeeds(self): iface = model.Interface('http://test/test') main_feed = model.ZeroInstallFeed(test_feed, local_path='/Hello') self.config.iface_cache._feeds[iface.uri] = main_feed iface.stability_policy = model.developer main_feed.last_checked = 100 iface.extra_feeds.append(model.Feed('http://sys-feed', None, False)) iface.extra_feeds.append( model.Feed('http://user-feed', 'Linux-*', True)) writer.save_interface(iface) writer.save_feed(main_feed) iface = model.Interface('http://test/test') self.assertEquals(None, iface.stability_policy) main_feed = model.ZeroInstallFeed(test_feed, local_path='/Hello') self.config.iface_cache._feeds[iface.uri] = main_feed reader.update_user_overrides(iface) reader.update_user_feed_overrides(main_feed) self.assertEquals(model.developer, iface.stability_policy) self.assertEquals(100, main_feed.last_checked) self.assertEquals("[<Feed from http://user-feed>]", str(iface.extra_feeds)) feed = iface.extra_feeds[0] self.assertEquals('http://user-feed', feed.uri) self.assertEquals('Linux', feed.os) self.assertEquals(None, feed.machine)
def testFeeds(self): iface = model.Interface('http://test/test') main_feed = model.ZeroInstallFeed(test_feed, local_path = '/Hello') self.config.iface_cache._feeds[iface.uri] = main_feed iface.stability_policy = model.developer main_feed.last_checked = 100 iface.extra_feeds.append(model.Feed('http://sys-feed', None, False)) iface.extra_feeds.append(model.Feed('http://user-feed', 'Linux-*', True)) writer.save_interface(iface) writer.save_feed(main_feed) iface = model.Interface('http://test/test') self.assertEqual(None, iface.stability_policy) main_feed = model.ZeroInstallFeed(test_feed, local_path = '/Hello') self.config.iface_cache._feeds[iface.uri] = main_feed reader.update_user_overrides(iface) reader.update_user_feed_overrides(main_feed) self.assertEqual(model.developer, iface.stability_policy) self.assertEqual(100, main_feed.last_checked) self.assertEqual("[<Feed from http://user-feed>]", str(iface.extra_feeds)) feed = iface.extra_feeds[0] self.assertEqual('http://user-feed', feed.uri) self.assertEqual('Linux', feed.os) self.assertEqual(None, feed.machine)
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 complete(completion, args, cword): if len(args) != 1: return iface_cache = completion.config.iface_cache for uri in iface_cache.list_all_interfaces(): dummy = model.Interface(uri) reader.update_user_overrides(dummy) if dummy.extra_feeds: completion.add_filtered(uri)
def testStoreNothing(self): iface = model.Interface('http://test/test') writer.save_interface(iface) iface = model.Interface('http://test/test') self.assertEquals(None, iface.stability_policy) reader.update_user_overrides(iface) feed = self.config.iface_cache.get_feed(iface.uri) self.assertEquals(None, feed)
def testStoreNothing(self): iface = model.Interface('http://test/test') writer.save_interface(iface) iface = model.Interface('http://test/test') self.assertEqual(None, iface.stability_policy) reader.update_user_overrides(iface) feed = self.config.iface_cache.get_feed(iface.uri) self.assertEqual(None, feed)
def complete(completion, args, cword): """@type completion: L{zeroinstall.cmd._Completion} @type args: [str] @type cword: int""" if len(args) != 1: return iface_cache = completion.config.iface_cache for uri in iface_cache.list_all_interfaces(): dummy = model.Interface(uri) reader.update_user_overrides(dummy) if dummy.extra_feeds: completion.add_filtered(uri)
def complete(completion, args, cword): """@type completion: L{zeroinstall.cmd._Completion} @type args: [str] @type cword: int""" if len(args) != 1: return iface_cache = completion.config.iface_cache for uri in iface_cache.list_all_interfaces(): dummy = model.Interface(uri) reader.update_user_overrides(dummy) if dummy.extra_feeds: completion.add_filtered(uri)
def complete(completion, args, cword): if cword > 1: return if cword == 0: list_feeds.complete(completion, args[:1], 1) # Or it could be a feed directly completion.expand_files() if cword == 1: # With two arguments, we can only remove a feed that is registered dummy = model.Interface(args[0]) reader.update_user_overrides(dummy) for feed in dummy.extra_feeds: completion.add_filtered(feed.uri)
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 complete(completion, args, cword): """@type completion: L{zeroinstall.cmd._Completion} @type args: [str] @type cword: int""" if cword > 1: return if cword == 0: list_feeds.complete(completion, args[:1], 1) # Or it could be a feed directly completion.expand_files() if cword == 1: # With two arguments, we can only remove a feed that is registered dummy = model.Interface(args[0]) reader.update_user_overrides(dummy) for feed in dummy.extra_feeds: completion.add_filtered(feed.uri)