[CalendarServer-changes] [4815] CalDAVClientLibrary/trunk/src
source_changes at macosforge.org
source_changes at macosforge.org
Tue Dec 1 12:50:12 PST 2009
Revision: 4815
http://trac.macosforge.org/projects/calendarserver/changeset/4815
Author: cdaboo at apple.com
Date: 2009-12-01 12:50:11 -0800 (Tue, 01 Dec 2009)
Log Message:
-----------
Add an mv command for MOVE operations.
Modified Paths:
--------------
CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
CalDAVClientLibrary/trunk/src/client/clientsession.py
CalDAVClientLibrary/trunk/src/protocol/http/requestresponse.py
Added Paths:
-----------
CalDAVClientLibrary/trunk/src/browser/commands/mv.py
Modified: CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/__init__.py 2009-12-01 17:59:37 UTC (rev 4814)
+++ CalDAVClientLibrary/trunk/src/browser/commands/__init__.py 2009-12-01 20:50:11 UTC (rev 4815)
@@ -24,6 +24,7 @@
"ls",
"mkcal",
"mkdir",
+ "mv",
"principal",
"props",
"proxies",
Added: CalDAVClientLibrary/trunk/src/browser/commands/mv.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/mv.py (rev 0)
+++ CalDAVClientLibrary/trunk/src/browser/commands/mv.py 2009-12-01 20:50:11 UTC (rev 4815)
@@ -0,0 +1,83 @@
+##
+# Copyright (c) 2007-2008 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from browser.command import Command
+from browser.command import WrongOptions
+from protocol.url import URL
+import getopt
+import os
+import readline
+
+class Cmd(Command):
+
+ def __init__(self):
+ super(Command, self).__init__()
+ self.cmds = ("mv", "move",)
+
+ def execute(self, name, options):
+
+ opts, args = getopt.getopt(options.split(), 'n')
+
+ doURLDecode = False
+ for name, _ignore_value in opts:
+
+ if name == "-n":
+ doURLDecode = True
+ else:
+ print "Unknown option: %s" % (name,)
+ print self.usage(name)
+ raise WrongOptions
+
+ if len(args) != 2:
+ print "Wrong number of arguments: %d" % (len(args),)
+ print self.usage(name)
+ raise WrongOptions
+
+ while True:
+ result = raw_input("Really move resource '%s' to '%s' [y/n]: " % (args[0], args[1],))
+ if readline.get_current_history_length():
+ readline.remove_history_item(readline.get_current_history_length() - 1)
+ if not result:
+ continue
+ if result[0] == "n":
+ return True
+ elif result[0] == "y":
+ break
+
+ fromResource = args[0]
+ if not fromResource.startswith("/"):
+ fromResource = os.path.join(self.shell.wd, fromResource)
+ toResource = args[1]
+ if not toResource.startswith("/"):
+ toResource = os.path.join(self.shell.wd, toResource)
+
+ resourceFrom = URL(url=fromResource, decode=doURLDecode)
+ resourceTo = URL(url=self.shell.server + toResource, decode=doURLDecode)
+ self.shell.account.session.moveResource(resourceFrom, resourceTo)
+
+ return True
+
+ def complete(self, text):
+ return self.shell.wdcomplete(text)
+
+ def usage(self, name):
+ return """Usage: %s PATH PATH
+PATH is a relative or absolute path.
+
+""" % (name,)
+
+ def helpDescription(self):
+ return "Moves a resource."
Modified: CalDAVClientLibrary/trunk/src/client/clientsession.py
===================================================================
--- CalDAVClientLibrary/trunk/src/client/clientsession.py 2009-12-01 17:59:37 UTC (rev 4814)
+++ CalDAVClientLibrary/trunk/src/client/clientsession.py 2009-12-01 20:50:11 UTC (rev 4815)
@@ -30,6 +30,7 @@
from protocol.webdav.delete import Delete
from protocol.webdav.get import Get
from protocol.webdav.makecollection import MakeCollection
+from protocol.webdav.move import Move
from protocol.webdav.principalmatch import PrincipalMatch
from protocol.webdav.propall import PropAll
from protocol.webdav.propfind import PropFind
@@ -468,6 +469,20 @@
if request.getStatusCode() not in (statuscodes.OK, statuscodes.NoContent):
self.handleHTTPError(request)
+ def moveResource(self, rurlFrom, rurlTo):
+
+ assert(isinstance(rurlFrom, URL))
+ assert(isinstance(rurlTo, URL))
+
+ # Create WebDAV MOVE
+ request = Move(self, rurlFrom.relativeURL(), rurlTo.absoluteURL())
+
+ # Process it
+ self.runSession(request)
+
+ if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent):
+ self.handleHTTPError(request)
+
def readData(self, rurl):
assert(isinstance(rurl, URL))
Modified: CalDAVClientLibrary/trunk/src/protocol/http/requestresponse.py
===================================================================
--- CalDAVClientLibrary/trunk/src/protocol/http/requestresponse.py 2009-12-01 17:59:37 UTC (rev 4814)
+++ CalDAVClientLibrary/trunk/src/protocol/http/requestresponse.py 2009-12-01 20:50:11 UTC (rev 4815)
@@ -111,7 +111,7 @@
def addHeaders(self, hdrs):
# Write host
- hdrs.append((headers.Host, self.session.server))
+ hdrs.append((headers.Host, "%s:%s" % (self.session.server, self.session.port,)))
# Do ETag matching
if self.etag:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091201/028f20fa/attachment-0001.html>
More information about the calendarserver-changes
mailing list