def testFeed(self): f = model.Feed('http://feed', arch=None, user_override=False) assert f.uri == 'http://feed' assert f.os == None assert f.machine == None assert f.arch == None assert f.user_override == False f = model.Feed('http://feed', arch='Linux-*', user_override=True) assert f.uri == 'http://feed' assert f.os == 'Linux' assert f.machine == None assert f.arch == 'Linux-*' assert f.user_override == True f = model.Feed('http://feed', arch='*-i386', user_override=True) assert f.uri == 'http://feed' assert f.os == None assert f.machine == 'i386' assert f.arch == '*-i386' assert f.user_override == True assert str(f).startswith('<Feed from') try: f = model.Feed('http://feed', arch='i386', user_override=True) assert False except model.SafeException as ex: assert 'Malformed arch' in str(ex)
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 _manage_feeds(options, args): from zeroinstall.injector import writer from zeroinstall.injector.handler import Handler from zeroinstall.injector.policy import Policy handler = Handler(dry_run = options.dry_run) if not args: raise UsageError() for x in args: print _("Feed '%s':") % x + '\n' x = model.canonical_iface_uri(x) policy = Policy(x, handler) if options.offline: policy.network_use = model.network_offline feed = iface_cache.get_feed(x) if policy.network_use != model.network_offline and policy.is_stale(feed): blocker = policy.fetcher.download_and_import_feed(x, iface_cache.iface_cache) print _("Downloading feed; please wait...") handler.wait_for_blocker(blocker) print _("Done") interfaces = policy.get_feed_targets(x) for i in range(len(interfaces)): feed = interfaces[i].get_feed(x) if feed: print _("%(index)d) Remove as feed for '%(uri)s'") % {'index': i + 1, 'uri': interfaces[i].uri} else: print _("%(index)d) Add as feed for '%(uri)s'") % {'index': i + 1, 'uri': interfaces[i].uri} print while True: try: i = raw_input(_('Enter a number, or CTRL-C to cancel [1]: ')).strip() except KeyboardInterrupt: print raise SafeException(_("Aborted at user request.")) if i == '': i = 1 else: try: i = int(i) except ValueError: i = 0 if i > 0 and i <= len(interfaces): break print _("Invalid number. Try again. (1 to %d)") % len(interfaces) iface = interfaces[i - 1] feed = iface.get_feed(x) if feed: iface.extra_feeds.remove(feed) else: iface.extra_feeds.append(model.Feed(x, arch = None, user_override = True)) writer.save_interface(iface) print '\n' + _("Feed list for interface '%s' is now:") % iface.get_name() if iface.feeds: for f in iface.feeds: print "- " + f.uri else: print _("(no feeds)")
def testDLfeed(self): self.cache_iface(foo_iface_uri, """<?xml version="1.0" ?> <interface last-modified="1110752708" uri="%s" xmlns="http://zero-install.sourceforge.net/2004/injector/interface"> <name>Foo</name> <summary>Foo</summary> <description>Foo</description> <feed src='http://example.com'/> </interface>""" % foo_iface_uri) driver = Driver(requirements = Requirements(foo_iface_uri), config = self.config) self.config.network_use = model.network_full assert driver.need_download() feed = self.config.iface_cache.get_feed(foo_iface_uri) feed.feeds = [model.Feed('/BadFeed', None, False)] logger.setLevel(logging.ERROR) assert driver.need_download() # Triggers warning logger.setLevel(logging.WARN)
def response(box, resp): if resp == RESPONSE_SETUP: def done_setup(): self.add_msg('Now use Build to compile the chosen source code.') self.run_command((sys.executable, main_path, 'setup'), done_setup) elif resp == RESPONSE_BUILD: def done_build(): self.add_msg('\nBuild successful. Now register or publish the build.') def build_failed(): self.add_msg('\nIf the messages displayed above indicate a missing dependency (e.g. no C compiler ' "or a library that isn't available through Zero Install) then install it using your " 'normal package manager and click on Build again. Note that for libraries you often ' 'need the -dev version of the package. ' '\nOtherwise, please notify the developers of this problem (this will transmit ' 'the contents of the build/build-failure.log file):') end = self.buffer.get_end_iter() anchor = self.buffer.create_child_anchor(end) align = gtk.Alignment(0.0, 0.0, 1.0, 1.0) button = ButtonMixed(gtk.STOCK_YES, 'Notify developers') align.add(button) align.set_padding(8, 8, 8, 8) align.show_all() self.tv.add_child_at_anchor(align, anchor) self.add_msg('\n') def report_bug(button): def done_notify(): self.add_msg("\nReport sent. Thank you! (note: you won't get a reply, as " "no contact details were sent; write to the project's mailing " "list if you want to discuss the problem)") self.run_command((sys.executable, main_path, 'report-bug'), done_notify) button.connect('clicked', report_bug) buildenv = BuildEnv() changes = buildenv.get_build_changes() if changes: options = get_build_options(box, '\n'.join(changes) + '\n\nIt would be best to do a clean (full) build.') else: options = [] if options is not None: box.run_command([sys.executable, main_path, 'build'] + options, done_build, build_failed) elif resp == RESPONSE_REGISTER: buildenv = BuildEnv() iface = iface_cache.get_interface(interface) reader.update_from_cache(iface) # Register using the feed-for, if available real_iface = iface for uri in iface.feed_for or []: real_iface = iface_cache.get_interface(uri) self.add_msg("Registering as a feed for %s" % real_iface.uri) break else: if os.path.isabs(iface.uri): self.add_msg("Warning: no <feed-for> in local feed %s!" % iface.uri) feed = buildenv.local_iface_file for f in real_iface.feeds or []: if f.uri == feed: self.add_msg("Feed '%s' is already registered for interface '%s'!\n" % (feed, real_iface.uri)) return box.buffer.insert_at_cursor("Registering feed '%s'\n" % feed) real_iface.extra_feeds.append(model.Feed(feed, arch = None, user_override = True)) writer.save_interface(real_iface) box.buffer.insert_at_cursor("Done. You can now close this window.\n") elif resp == RESPONSE_PUBLISH: buildenv = BuildEnv() box = PublishBox(self, buildenv) resp = box.run() box.destroy() if resp == gtk.RESPONSE_OK: def done_publish(): self.add_msg("\nYou can use '0publish --local' to add this " "into the main feed. If you don't have a main feed then this " "will create one. See " "http://0install.net/injector-packagers.html for more information.") self.run_command((sys.executable, main_path, 'publish', box.archive_dir.get_text()), done_publish) elif resp == gtk.RESPONSE_CANCEL or resp == gtk.RESPONSE_DELETE_EVENT: if self.kill_child(): return self.destroy() else: self.add_msg('Unknown response: %s' % resp)
def handle(config, options, args, add_ok = True, remove_ok = False): """@type add_ok: bool @type remove_ok: bool""" if len(args) == 2: iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0])) feed_url = model.canonical_iface_uri(args[1]) feed_import = find_feed_import(iface, feed_url) if feed_import: raise SafeException(_('Interface %(interface)s already has a feed %(feed)s') % {'interface': iface.uri, 'feed': feed_url}) iface.extra_feeds.append(model.Feed(feed_url, arch = None, user_override = True)) writer.save_interface(iface) return elif len(args) != 1: raise UsageError() x = args[0] print(_("Feed '%s':") % x + '\n') x = model.canonical_iface_uri(x) if options.offline: config.network_use = model.network_offline if config.network_use != model.network_offline and config.iface_cache.is_stale(x, config.freshness): blocker = config.fetcher.download_and_import_feed(x, config.iface_cache) print(_("Downloading feed; please wait...")) tasks.wait_for_blocker(blocker) print(_("Done")) candidate_interfaces = config.iface_cache.get_feed_targets(x) assert candidate_interfaces interfaces = [] for i in range(len(candidate_interfaces)): iface = candidate_interfaces[i] if find_feed_import(iface, x): if remove_ok: print(_("%(index)d) Remove as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri}) interfaces.append(iface) else: if add_ok: print(_("%(index)d) Add as feed for '%(uri)s'") % {'index': i + 1, 'uri': iface.uri}) interfaces.append(iface) if not interfaces: if remove_ok: raise SafeException(_("%(feed)s is not registered as a feed for %(interface)s") % {'feed': x, 'interface': candidate_interfaces[0]}) else: raise SafeException(_("%(feed)s already registered as a feed for %(interface)s") % {'feed': x, 'interface': candidate_interfaces[0]}) print() while True: try: i = raw_input(_('Enter a number, or CTRL-C to cancel [1]: ')).strip() except KeyboardInterrupt: print() raise SafeException(_("Aborted at user request.")) if i == '': i = 1 else: try: i = int(i) except ValueError: i = 0 if i > 0 and i <= len(interfaces): break print(_("Invalid number. Try again. (1 to %d)") % len(interfaces)) iface = interfaces[i - 1] feed_import = find_feed_import(iface, x) if feed_import: iface.extra_feeds.remove(feed_import) else: iface.extra_feeds.append(model.Feed(x, arch = None, user_override = True)) writer.save_interface(iface) print('\n' + _("Feed list for interface '%s' is now:") % iface.get_name()) if iface.extra_feeds: for f in iface.extra_feeds: print("- " + f.uri) else: print(_("(no feeds)"))