[CalendarServer-changes] [2646] CalDAVClientLibrary/trunk/src
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 30 19:10:45 PDT 2008
Revision: 2646
http://trac.macosforge.org/projects/calendarserver/changeset/2646
Author: cdaboo at apple.com
Date: 2008-06-30 19:10:45 -0700 (Mon, 30 Jun 2008)
Log Message:
-----------
Some more useful commands.
Modified Paths:
--------------
CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
CalDAVClientLibrary/trunk/src/client/clientsession.py
Added Paths:
-----------
CalDAVClientLibrary/trunk/src/browser/commands/mkcal.py
CalDAVClientLibrary/trunk/src/browser/commands/mkdir.py
CalDAVClientLibrary/trunk/src/browser/commands/rm.py
Modified: CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/__init__.py 2008-06-30 21:12:03 UTC (rev 2645)
+++ CalDAVClientLibrary/trunk/src/browser/commands/__init__.py 2008-07-01 02:10:45 UTC (rev 2646)
@@ -22,10 +22,13 @@
"history",
"logging",
"ls",
+ "mkcal",
+ "mkdir",
"principal",
"props",
"proxies",
"quit",
+ "rm",
"server",
"whoami",
]
Added: CalDAVClientLibrary/trunk/src/browser/commands/mkcal.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/mkcal.py (rev 0)
+++ CalDAVClientLibrary/trunk/src/browser/commands/mkcal.py 2008-07-01 02:10:45 UTC (rev 2646)
@@ -0,0 +1,64 @@
+##
+# 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
+
+class Cmd(Command):
+
+ def __init__(self):
+ super(Command, self).__init__()
+ self.cmds = ("mkcal",)
+
+ def execute(self, name, options):
+
+ opts, args = getopt.getopt(options.split(), '')
+
+ for name, _ignore_value in opts:
+
+ print "Unknown option: %s" % (name,)
+ print self.usage(name)
+ raise WrongOptions
+
+ if len(args) != 1:
+ print "Wrong number of arguments: %d" % (len(args),)
+ print self.usage(name)
+ raise WrongOptions
+
+ path = args[0]
+ if not path.startswith("/"):
+ path = os.path.join(self.shell.wd, path)
+ if not path.endswith("/"):
+ path += "/"
+
+ resource = URL(url=path)
+ self.shell.account.session.makeCalendar(resource)
+ return True
+
+ def complete(self, text):
+ return self.shell.wdcomplete(text)
+
+ def usage(self, name):
+ return """Usage: %s PATH
+PATH is a relative or absolute path.
+
+""" % (name,)
+
+ def helpDescription(self):
+ return "Creates a calendar collection."
Added: CalDAVClientLibrary/trunk/src/browser/commands/mkdir.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/mkdir.py (rev 0)
+++ CalDAVClientLibrary/trunk/src/browser/commands/mkdir.py 2008-07-01 02:10:45 UTC (rev 2646)
@@ -0,0 +1,64 @@
+##
+# 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
+
+class Cmd(Command):
+
+ def __init__(self):
+ super(Command, self).__init__()
+ self.cmds = ("mkdir",)
+
+ def execute(self, name, options):
+
+ opts, args = getopt.getopt(options.split(), '')
+
+ for name, _ignore_value in opts:
+
+ print "Unknown option: %s" % (name,)
+ print self.usage(name)
+ raise WrongOptions
+
+ if len(args) != 1:
+ print "Wrong number of arguments: %d" % (len(args),)
+ print self.usage(name)
+ raise WrongOptions
+
+ path = args[0]
+ if not path.startswith("/"):
+ path = os.path.join(self.shell.wd, path)
+ if not path.endswith("/"):
+ path += "/"
+
+ resource = URL(url=path)
+ self.shell.account.session.makeCollection(resource)
+ return True
+
+ def complete(self, text):
+ return self.shell.wdcomplete(text)
+
+ def usage(self, name):
+ return """Usage: %s PATH
+PATH is a relative or absolute path.
+
+""" % (name,)
+
+ def helpDescription(self):
+ return "Creates a regular collection."
Added: CalDAVClientLibrary/trunk/src/browser/commands/rm.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/rm.py (rev 0)
+++ CalDAVClientLibrary/trunk/src/browser/commands/rm.py 2008-07-01 02:10:45 UTC (rev 2646)
@@ -0,0 +1,78 @@
+##
+# 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 = ("rm",)
+
+ def execute(self, name, options):
+
+ opts, args = getopt.getopt(options.split(), '')
+
+ for name, _ignore_value in opts:
+
+ print "Unknown option: %s" % (name,)
+ print self.usage(name)
+ raise WrongOptions
+
+ paths = []
+ if len(args) == 0:
+ print "Wrong number of arguments: %d" % (len(args),)
+ print self.usage(name)
+ raise WrongOptions
+
+ while True:
+ result = raw_input("Really delete %d resource(s) [y/n]: " % (len(args),))
+ 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
+
+ for arg in args:
+ path = arg
+ if not path.startswith("/"):
+ path = os.path.join(self.shell.wd, path)
+ paths.append(path)
+
+ resource = URL(url=path)
+ self.shell.account.session.deleteResource(resource)
+
+ 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 "Deletes one or more resources."
Modified: CalDAVClientLibrary/trunk/src/client/clientsession.py
===================================================================
--- CalDAVClientLibrary/trunk/src/client/clientsession.py 2008-06-30 21:12:03 UTC (rev 2645)
+++ CalDAVClientLibrary/trunk/src/client/clientsession.py 2008-07-01 02:10:45 UTC (rev 2646)
@@ -31,6 +31,9 @@
from protocol.webdav.propnames import PropNames
from protocol.webdav.propall import PropAll
from protocol.webdav.acl import ACL
+from protocol.webdav.delete import Delete
+from protocol.webdav.makecollection import MakeCollection
+from protocol.caldav.makecalendar import MakeCalendar
import types
import httplib
@@ -421,6 +424,45 @@
if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent):
self.handleHTTPError(request)
+ def makeCollection(self, rurl):
+
+ assert(isinstance(rurl, URL))
+
+ # Create WebDAV MKCOL
+ request = MakeCollection(self, rurl.relativeURL())
+
+ # Process it
+ self.runSession(request)
+
+ if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent):
+ self.handleHTTPError(request)
+
+ def makeCalendar(self, rurl, displayname=None, description=None):
+
+ assert(isinstance(rurl, URL))
+
+ # Create WebDAV MKCALENDAR
+ request = MakeCalendar(self, rurl.relativeURL(), displayname, description)
+
+ # Process it
+ self.runSession(request)
+
+ if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent):
+ self.handleHTTPError(request)
+
+ def deleteResource(self, rurl):
+
+ assert(isinstance(rurl, URL))
+
+ # Create WebDAV DELETE
+ request = Delete(self, rurl.relativeURL())
+
+ # Process it
+ self.runSession(request)
+
+ if request.getStatusCode() not in (statuscodes.OK, statuscodes.NoContent):
+ self.handleHTTPError(request)
+
def readData(self, rurl):
assert(isinstance(rurl, URL))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080630/051929bd/attachment.html
More information about the calendarserver-changes
mailing list