More updates to support Python 3
[zeroinstall/solver.git] / zeroinstall / cmd / remove_feed.py
blobc690a3ce4f1d3f9298f85e9eb5b15d05622e397e
1 """
2 The B{0install remove-feed} command-line interface.
3 """
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 syntax = "[INTERFACE] FEED"
10 from zeroinstall import SafeException, _
11 from zeroinstall.injector import model, writer
12 from zeroinstall.cmd import add_feed, UsageError
14 add_options = add_feed.add_options
16 def handle(config, options, args):
17 if len(args) == 2:
18 iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0]))
19 try:
20 feed_url = model.canonical_iface_uri(args[1])
21 except SafeException:
22 feed_url = args[1] # File might not exist any longer
24 feed_import = add_feed.find_feed_import(iface, feed_url)
25 if not feed_import:
26 raise SafeException(_('Interface %(interface)s has no feed %(feed)s') %
27 {'interface': iface.uri, 'feed': feed_url})
28 iface.extra_feeds.remove(feed_import)
29 writer.save_interface(iface)
30 elif len(args) == 1:
31 add_feed.handle(config, options, args, add_ok = False, remove_ok = True)
32 else:
33 raise UsageError()