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

Source Code for Module caldavclientlibrary.browser.commands.mv

 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 = ("mv", "move",)
30
31 - def execute(self, name, options):
32 33 opts, args = getopt.getopt(shlex.split(options), 'n') 34 35 doURLDecode = False 36 for name, _ignore_value in opts: 37 38 if name == "-n": 39 doURLDecode = True 40 else: 41 print "Unknown option: %s" % (name,) 42 print self.usage(name) 43 raise WrongOptions 44 45 if len(args) != 2: 46 print "Wrong number of arguments: %d" % (len(args),) 47 print self.usage(name) 48 raise WrongOptions 49 50 while True: 51 result = raw_input("Really move resource '%s' to '%s' [y/n]: " % (args[0], args[1],)) 52 if readline.get_current_history_length(): 53 readline.remove_history_item(readline.get_current_history_length() - 1) 54 if not result: 55 continue 56 if result[0] == "n": 57 return True 58 elif result[0] == "y": 59 break 60 61 fromResource = args[0] 62 if not fromResource.startswith("/"): 63 fromResource = os.path.join(self.shell.wd, fromResource) 64 toResource = args[1] 65 if not toResource.startswith("/"): 66 toResource = os.path.join(self.shell.wd, toResource) 67 68 resourceFrom = URL(url=fromResource, decode=doURLDecode) 69 resourceTo = URL(url=self.shell.server + toResource, decode=doURLDecode) 70 self.shell.account.session.moveResource(resourceFrom, resourceTo) 71 72 return True
73
74 - def complete(self, text):
76
77 - def usage(self, name):
78 return """Usage: %s PATH PATH 79 PATH is a relative or absolute path. 80 81 """ % (name,)
82
83 - def helpDescription(self):
84 return "Moves a resource."
85