[CalendarServer-changes] [8265] CalendarServer/trunk/calendarserver/tools/shell.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Nov 8 16:31:30 PST 2011


Revision: 8265
          http://trac.macosforge.org/projects/calendarserver/changeset/8265
Author:   wsanchez at apple.com
Date:     2011-11-08 16:31:30 -0800 (Tue, 08 Nov 2011)
Log Message:
-----------
cd works

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/shell.py

Modified: CalendarServer/trunk/calendarserver/tools/shell.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell.py	2011-11-08 23:21:12 UTC (rev 8264)
+++ CalendarServer/trunk/calendarserver/tools/shell.py	2011-11-09 00:31:30 UTC (rev 8265)
@@ -26,6 +26,7 @@
 import termios
 from shlex import shlex
 
+from twisted.python import log
 from twisted.python.log import startLogging
 from twisted.python.text import wordWrap
 from twisted.python.usage import Options, UsageError
@@ -93,8 +94,8 @@
         Start the service.
         """
         # For debugging
-        #f = open("/tmp/shell.log", "w")
-        #startLogging(f)
+        f = open("/tmp/shell.log", "w")
+        startLogging(f)
 
         super(ShellService, self).startService()
 
@@ -217,10 +218,10 @@
                     self.terminal.write("%s\n" % (f.value,))
 
                 def handleException(f):
-                    self.terminal.write("Error: %s\n" % (e,))
-                    self.terminal.write("-"*80 + "\n")
-                    self.terminal.write(f.getTraceback())
-                    self.terminal.write("-"*80 + "\n")
+                    self.terminal.write("Error: %s\n" % (f.value,))
+                    log.msg("-"*80 + "\n")
+                    log.msg(f.getTraceback())
+                    log.msg("-"*80 + "\n")
 
                 def next(_):
                     self.activeCommand = None
@@ -229,8 +230,7 @@
                         line = self.inputLines.pop(0)
                         self.lineReceived(line)
 
-                d = Deferred()
-                self.activeCommand = d
+                d = self.activeCommand = Deferred()
                 d.addCallback(lambda _: m(tokens))
                 if True:
                     d.callback(None)
@@ -239,7 +239,7 @@
                     self.service.reactor.callLater(4, d.callback, None)
                 d.addErrback(handleUnknownArguments)
                 d.addErrback(handleException)
-                d.addBoth(next)
+                d.addCallback(next)
             else:
                 self.terminal.write("Unknown command: %s\n" % (cmd,))
                 self.drawInputLine()
@@ -268,18 +268,12 @@
             raise UnknownArguments(tokens)
             return
 
-        path = dirname.split("/")
-
-        def notFound(f):
-            f.trap(NotFoundError)
-            self.terminal.write("No such directory: %s\n" % (dirname,))
-
         def setWD(wd):
+            log.msg("wd -> %s" % (wd,))
             self.wd = wd
 
-        d = self.wd.locate(path)
+        d = self.wd.locate(dirname.split("/"))
         d.addCallback(setWD)
-        d.addErrback(notFound)
         return d
 
     def cmd_ls(self, tokens):
@@ -337,14 +331,18 @@
         return succeed(str(self))
 
     def locate(self, path):
+        #log.msg("locate(%r)" % (path,))
+
         if not path:
             return succeed(RootDirectory(self.store))
 
         name = path[0]
+        #log.msg("  name: %s" % (name,))
         if not name:
-            return succeed(self.locate(path[1:]))
+            return self.locate(path[1:])
 
         path = list(path)
+        #log.msg("  path: %s" % (path,))
 
         if name.startswith("/"):
             path[0] = path[0][1:]
@@ -352,19 +350,24 @@
         else:
             path.pop(0)
             subdir = self.subdir(name)
+        #log.msg("  subdir: %s" % (subdir,))
 
         if path:
-            return subdir.addCallback(lambda path: self.locate(path))
+            return subdir.addCallback(lambda subdir: subdir.locate(path))
         else:
             return subdir
 
     def subdir(self, name):
+        #log.msg("subdir(%r)" % (name,))
         if not name:
             return succeed(self)
         if name == ".":
             return succeed(self)
         if name == "..":
-            return succeed(RootDirectory(self.store).locate(self.path[:-1]))
+            path = self.path[:-1]
+            if not path:
+                path = "/"
+            return RootDirectory(self.store).locate(path)
 
         return fail(NotFoundError("Directory %r has no subdirectory %r" % (str(self), name)))
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111108/b92f5258/attachment.html>


More information about the calendarserver-changes mailing list