[CalendarServer-changes] [14670] CalDAVClientLibrary/trunk/caldavclientlibrary

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 9 11:44:22 PDT 2015


Revision: 14670
          http://trac.calendarserver.org//changeset/14670
Author:   cdaboo at apple.com
Date:     2015-04-09 11:44:22 -0700 (Thu, 09 Apr 2015)
Log Message:
-----------
Commands for calendar trash manipulation.

Modified Paths:
--------------
    CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/__init__.py
    CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py

Added Paths:
-----------
    CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/emptytrash.py
    CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/gettrash.py

Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/__init__.py	2015-04-09 16:57:35 UTC (rev 14669)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/__init__.py	2015-04-09 18:44:22 UTC (rev 14670)
@@ -21,6 +21,8 @@
     "cat",
     "cd",
     "calendars",
+    "emptytrash",
+    "gettrash",
     "help",
     "history",
     "import",

Added: CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/emptytrash.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/emptytrash.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/emptytrash.py	2015-04-09 18:44:22 UTC (rev 14670)
@@ -0,0 +1,49 @@
+##
+# Copyright (c) 2007-2015 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 caldavclientlibrary.browser.command import Command, CommandError
+from caldavclientlibrary.protocol.url import URL
+
+class Cmd(Command):
+
+    def __init__(self):
+        super(Command, self).__init__()
+        self.cmds = ("emptytrash",)
+
+
+    def execute(self, cmdname, options):
+
+        principal = self.shell.account.getPrincipal()
+        homeset = principal.homeset
+        if not homeset:
+            print "No calendar home set found for %s" % (principal.principalPath,)
+            raise CommandError
+
+        homepath = homeset[0].path
+
+        resource = URL(url="{}?action=emptytrash".format(homepath))
+        self.shell.account.session.writeData(resource, None, None, method="POST")
+
+        return True
+
+
+    def usage(self, name):
+        return """Usage: %s
+""" % (name,)
+
+
+    def helpDescription(self):
+        return "Empties the trash of the current user."

Added: CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/gettrash.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/gettrash.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/browser/commands/gettrash.py	2015-04-09 18:44:22 UTC (rev 14670)
@@ -0,0 +1,66 @@
+##
+# Copyright (c) 2007-2015 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 caldavclientlibrary.browser.command import Command, CommandError
+from caldavclientlibrary.protocol.url import URL
+import json
+
+class Cmd(Command):
+
+    def __init__(self):
+        super(Command, self).__init__()
+        self.cmds = ("gettrash",)
+
+
+    def execute(self, cmdname, options):
+
+        principal = self.shell.account.getPrincipal()
+        homeset = principal.homeset
+        if not homeset:
+            print "No calendar home set found for %s" % (principal.principalPath,)
+            raise CommandError
+
+        homepath = homeset[0].path
+
+        resource = URL(url="{}?action=gettrashcontents".format(homepath))
+        result = self.shell.account.session.writeData(resource, None, None, method="POST")
+        jresult = json.loads(result)
+
+        if "trashedcollections" in jresult and jresult["trashedcollections"]:
+            print
+            print "Trashed Calendar Collections:"
+            for calendar in jresult["trashedcollections"]:
+                print "  Name: {0.displayName}  - trashed: {0.whenTrashed} - children: {1}".format(calendar, len(calendar["children"]),)
+
+        if "untrashedcollections" in jresult and jresult["untrashedcollections"]:
+            print
+            print "Trashed Calendar Objects:"
+            for calendar in jresult["untrashedcollections"]:
+                print
+                print "  Calendar Collection: {} - children: {}".format(calendar["displayName"], len(calendar["children"]))
+                for child in calendar["children"]:
+                    print "    Title: {} - Start: {} - Trashed: {}".format(child["summary"], child["starttime"], child["whenTrashed"])
+
+        return True
+
+
+    def usage(self, name):
+        return """Usage: %s
+""" % (name,)
+
+
+    def helpDescription(self):
+        return "Get the contents of the trash of the current user."

Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py	2015-04-09 16:57:35 UTC (rev 14669)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py	2015-04-09 18:44:22 UTC (rev 14670)
@@ -727,12 +727,18 @@
             request = Put(self, rurl.relativeURL())
         elif method == "POST":
             request = Post(self, rurl.relativeURL())
-        dout = RequestDataString(data, contentType)
-        if method == "PUT":
-            request.setData(dout, None, etag=etag)
-        elif method == "POST":
-            request.setData(dout, None)
 
+        dout = ResponseDataString()
+
+        if data is not None:
+            din = RequestDataString(data, contentType)
+            if method == "PUT":
+                request.setData(din, dout, etag=etag)
+            elif method == "POST":
+                request.setData(din, dout)
+        else:
+            request.setData(None, dout)
+
         # Process it
         self.runSession(request)
 
@@ -740,7 +746,10 @@
         if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent,):
             self.handleHTTPError(request)
 
+        # Return data as a string
+        return dout.getData()
 
+
     def importData(self, rurl, data, contentType):
 
         assert(isinstance(rurl, URL))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150409/5da432c3/attachment.html>


More information about the calendarserver-changes mailing list