1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
26
30
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
76
78 return """Usage: %s PATH PATH
79 PATH is a relative or absolute path.
80
81 """ % (name,)
82
84 return "Moves a resource."
85