Package zeroinstall :: Package cmd :: Module remove_feed
[frames] | no frames]

Source Code for Module zeroinstall.cmd.remove_feed

 1  """ 
 2  The B{0install remove-feed} command-line interface. 
 3  """ 
 4   
 5  # Copyright (C) 2011, Thomas Leonard 
 6  # See the README file for details, or visit http://0install.net. 
 7   
 8  syntax = "[INTERFACE] FEED" 
 9   
10  from zeroinstall import SafeException, _ 
11  from zeroinstall.injector import model, writer, reader 
12  from zeroinstall.cmd import add_feed, UsageError, list_feeds 
13   
14  add_options = add_feed.add_options 
15   
16 -def handle(config, options, args):
17 """@type args: [str]""" 18 if len(args) == 2: 19 iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0])) 20 try: 21 feed_url = model.canonical_iface_uri(args[1]) 22 except SafeException: 23 feed_url = args[1] # File might not exist any longer 24 25 feed_import = add_feed.find_feed_import(iface, feed_url) 26 if not feed_import: 27 raise SafeException(_('Interface %(interface)s has no feed %(feed)s') % 28 {'interface': iface.uri, 'feed': feed_url}) 29 iface.extra_feeds.remove(feed_import) 30 writer.save_interface(iface) 31 elif len(args) == 1: 32 add_feed.handle(config, options, args, add_ok = False, remove_ok = True) 33 else: 34 raise UsageError()
35
36 -def complete(completion, args, cword):
37 """@type completion: L{zeroinstall.cmd._Completion} 38 @type args: [str] 39 @type cword: int""" 40 if cword > 1: return 41 if cword == 0: 42 list_feeds.complete(completion, args[:1], 1) 43 # Or it could be a feed directly 44 completion.expand_files() 45 46 if cword == 1: 47 # With two arguments, we can only remove a feed that is registered 48 dummy = model.Interface(args[0]) 49 reader.update_user_overrides(dummy) 50 for feed in dummy.extra_feeds: 51 completion.add_filtered(feed.uri)
52