[CalendarServer-changes] [4664] CalDAVClientLibrary/trunk/src/browser/commands

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 29 11:42:19 PDT 2009


Revision: 4664
          http://trac.macosforge.org/projects/calendarserver/changeset/4664
Author:   cdaboo at apple.com
Date:     2009-10-29 11:42:19 -0700 (Thu, 29 Oct 2009)
Log Message:
-----------
Allow command line PUTs.

Modified Paths:
--------------
    CalDAVClientLibrary/trunk/src/browser/commands/__init__.py

Added Paths:
-----------
    CalDAVClientLibrary/trunk/src/browser/commands/put.py

Modified: CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/__init__.py	2009-10-29 18:41:54 UTC (rev 4663)
+++ CalDAVClientLibrary/trunk/src/browser/commands/__init__.py	2009-10-29 18:42:19 UTC (rev 4664)
@@ -27,6 +27,7 @@
     "principal",
     "props",
     "proxies",
+    "put",
     "quit",
     "rm",
     "server",

Added: CalDAVClientLibrary/trunk/src/browser/commands/put.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/put.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/browser/commands/put.py	2009-10-29 18:42:19 UTC (rev 4664)
@@ -0,0 +1,96 @@
+##
+# Copyright (c) 2007-2009 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 os
+import getopt
+
+class Cmd(Command):
+    
+    def __init__(self):
+        super(Command, self).__init__()
+        self.cmds = ("put", "write",)
+        
+    def execute(self, name, options):
+        
+        fname = None
+        content_type = "text/plain"
+        path = None
+
+        opts, args = getopt.getopt(options.split(), 'f:t:')
+
+        for name, value in opts:
+            
+            if name == "-f":
+                fname = value
+            elif name == "-t":
+                content_type = value
+            else:
+                print "Unknown option: %s" % (name,)
+                print self.usage(name)
+                raise WrongOptions
+        
+        if not fname:
+            print "File name must be provided"
+            print self.usage(name)
+            raise WrongOptions
+            
+        elif len(args) > 1:
+            print "Wrong number of arguments: %d" % (len(args),)
+            print self.usage(name)
+            raise WrongOptions
+        elif args:
+            path = args[0]
+            if not path.startswith("/"):
+                path = os.path.join(self.shell.wd, path)
+            if path.endswith("/"):
+                print "Cannot PUT to a directory: %s" % (path,)
+                print self.usage(name)
+                raise WrongOptions
+        else:
+            print "Path to PUT to must be provided"
+            print self.usage(name)
+            raise WrongOptions
+
+        # Read in data
+        try:
+            data = open(fname, "r").read()
+        except IOError:
+            print "Unable to read data from file: %s" % (fname,)
+            print self.usage(name)
+            raise WrongOptions
+
+        resource = URL(url=path)
+        self.shell.account.session.writeResource(resource, data, content_type)
+
+        return True
+
+    def complete(self, text):
+        return self.shell.wdcomplete(text)
+
+    def usage(self, name):
+        return """Usage: %s OPTIONS PATH
+PATH is a relative or absolute path.
+
+Options:
+-f   file name of data to put [REQUIRED]
+-t   content-type of data being put [DEFAULT: text/plain]
+""" % (name,)
+
+    def helpDescription(self):
+        return "Write data to a file on the server."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091029/a811c985/attachment.html>


More information about the calendarserver-changes mailing list