[CalendarServer-changes] [7680] CalendarServer/trunk/calendarserver/tools/shell.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 27 15:59:53 PDT 2011
Revision: 7680
http://trac.macosforge.org/projects/calendarserver/changeset/7680
Author: wsanchez at apple.com
Date: 2011-06-27 15:59:53 -0700 (Mon, 27 Jun 2011)
Log Message:
-----------
Add cmd_cd
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/shell.py
Modified: CalendarServer/trunk/calendarserver/tools/shell.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell.py 2011-06-27 22:24:39 UTC (rev 7679)
+++ CalendarServer/trunk/calendarserver/tools/shell.py 2011-06-27 22:59:53 UTC (rev 7680)
@@ -22,6 +22,7 @@
import os
import sys
+import posixpath
from shlex import shlex
#from twisted.python import log
@@ -31,6 +32,8 @@
from twisted.conch.recvline import HistoricRecvLine
from twisted.application.service import Service
+from txdav.common.icommondatastore import NotFoundError
+
from twistedcaldav.stdconfig import DEFAULT_CONFIG_FILE
from calendarserver.tools.cmdline import utilityMain
@@ -103,7 +106,24 @@
def __str__(self):
return "/" + "/".join(self.path)
+ def goto(self, path):
+ path = list(path)
+ if path[0].startswith("/"):
+ path[0] = path[0][1:]
+ subdir = RootDirectory()
+ else:
+ subdir = self.subdir(path.pop(0))
+
+ if path:
+ return subdir.goto(path)
+ else:
+ return subdir
+
+ def subdir(self, name):
+ raise NotImplementedError()
+
+
class RootDirectory(Directory):
"""
Root of virtual data hierarchy.
@@ -111,7 +131,10 @@
def __init__(self):
Directory.__init__(self, ())
+ def subdir(self, name):
+ raise NotFoundError("%s/%s" % (self, name))
+
class ShellProtocol(HistoricRecvLine):
"""
Data store shell protocol.
@@ -183,7 +206,7 @@
tokens.append(token)
if tokens:
- cmd = tokens.pop()
+ cmd = tokens.pop(0)
m = getattr(self, "cmd_%s" % (cmd,), None)
if m:
m(tokens)
@@ -196,7 +219,17 @@
return
print self.wd
+ def cmd_cd(self, tokens):
+ if tokens:
+ dirname = tokens.pop(0)
+ if tokens:
+ print "Unknown arguments: %s" % (tokens,)
+ return
+ path = posixpath.split(dirname)
+ self.wd = self.wd.goto(path)
+
+
def main(argv=sys.argv, stderr=sys.stderr, reactor=None):
"""
Do the export.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110627/43ea6328/attachment-0001.html>
More information about the calendarserver-changes
mailing list