Package caldavclientlibrary :: Package browser :: Package commands :: Module rm
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.browser.commands.rm

 1  ## 
 2  # Copyright (c) 2007-2016 Apple Inc. All rights reserved. 
 3  # 
 4  # Licensed under the Apache License, Version 2.0 (the "License"); 
 5  # you may not use this file except in compliance with the License. 
 6  # You may obtain a copy of the License at 
 7  # 
 8  # http://www.apache.org/licenses/LICENSE-2.0 
 9  # 
10  # Unless required by applicable law or agreed to in writing, software 
11  # distributed under the License is distributed on an "AS IS" BASIS, 
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13  # See the License for the specific language governing permissions and 
14  # limitations under the License. 
15  ## 
16   
17  from caldavclientlibrary.browser.command import Command 
18  from caldavclientlibrary.browser.command import WrongOptions 
19  from caldavclientlibrary.protocol.url import URL 
20  import getopt 
21  import os 
22  import readline 
23  import shlex 
24   
25 -class Cmd(Command):
26
27 - def __init__(self):
28 super(Command, self).__init__() 29 self.cmds = ("rm",)
30
31 - def execute(self, name, options):
32 33 opts, args = getopt.getopt(shlex.split(options), '') 34 35 for name, _ignore_value in opts: 36 37 print "Unknown option: %s" % (name,) 38 print self.usage(name) 39 raise WrongOptions 40 41 paths = [] 42 if len(args) == 0: 43 print "Wrong number of arguments: %d" % (len(args),) 44 print self.usage(name) 45 raise WrongOptions 46 47 while True: 48 result = raw_input("Really delete %d resource(s) [y/n]: " % (len(args),)) 49 if readline.get_current_history_length(): 50 readline.remove_history_item(readline.get_current_history_length() - 1) 51 if not result: 52 continue 53 if result[0] == "n": 54 return True 55 elif result[0] == "y": 56 break 57 58 for arg in args: 59 path = arg 60 if not path.startswith("/"): 61 path = os.path.join(self.shell.wd, path) 62 paths.append(path) 63 64 resource = URL(url=path) 65 self.shell.account.session.deleteResource(resource) 66 67 return True
68
69 - def complete(self, text):
71
72 - def usage(self, name):
73 return """Usage: %s PATH *[PATH] 74 PATH is a relative or absolute path. 75 76 """ % (name,)
77
78 - def helpDescription(self):
79 return "Deletes one or more resources."
80