[prev in list] [next in list] [prev in thread] [next in thread]
List: calendarserver-changes
Subject: [CalendarServer-changes] [3300]
From: source_changes () macosforge ! org
Date: 2008-10-31 18:28:58
Message-ID: 20081031182859.01FDC5FC201 () beta ! macosforge ! org
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Revision: 3300
http://trac.macosforge.org/projects/calendarserver/changeset/3300
Author: wsanchez@apple.com
Date: 2008-10-31 11:28:58 -0700 (Fri, 31 Oct 2008)
Log Message:
-----------
Add -u option.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/export.py
Modified: CalendarServer/trunk/calendarserver/tools/export.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/export.py 2008-10-31 18:11:21 UTC (rev \
3299)
+++ CalendarServer/trunk/calendarserver/tools/export.py 2008-10-31 18:28:58 UTC (rev \
3300) @@ -21,8 +21,9 @@
from getopt import getopt, GetoptError
from os.path import dirname, abspath
-from twistedcaldav.ical import Component as iComponent, Property as iProperty,\
- iCalendarProductID
+from twisted.python.reflect import namedClass
+from twistedcaldav.ical import Component as iComponent, Property as iProperty
+from twistedcaldav.ical import iCalendarProductID
from twistedcaldav.resource import isCalendarCollectionResource
from twistedcaldav.static import CalDAVFile, CalendarHomeFile
from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
@@ -36,15 +37,17 @@
print ""
name = os.path.basename(sys.argv[0])
- print "usage: %s [-c collection_path] [-H calendar_home_path]" % (name,)
+ print "usage: %s [-f config] [-c collection_path] [-H calendar_home_path] [-u \
user]" % (name,) print ""
print "Generate an iCalendar file containing the merged content of each \
calendar" print "collection read."
print ""
print "options:"
print " -h --help: print this help"
+ print " -f --config: Specify caldavd.plist configuration path"
print " -c --collection: add a calendar collection"
print " -H --home: add a calendar home (and all calendars within it)"
+ print " -u --user: add a user's calendar home (and all calendars within it)"
if e:
sys.exit(64)
@@ -54,16 +57,20 @@
def main():
try:
(optargs, args) = getopt(
- sys.argv[1:], "hc:H:", [
+ sys.argv[1:], "hf:c:H:u:", [
+ "config=",
"help",
- "collection=", "home="
+ "collection=", "home=", "user=",
],
)
except GetoptError, e:
usage(e)
+ configFileName = None
+
collections = set()
calendarHomes = set()
+ users = set()
def checkExists(resource):
if not resource.exists():
@@ -74,6 +81,9 @@
if opt in ("-h", "--help"):
usage()
+ elif opt in ("-f", "--config"):
+ configFileName = arg
+
elif opt in ("-c", "--collection"):
path = abspath(arg)
collection = CalDAVFile(path)
@@ -90,9 +100,20 @@
checkExists(calendarHome)
calendarHomes.add(calendarHome)
+ elif opt in ("-u", "--user"):
+ users.add(arg)
+
if args:
usage("Too many arguments: %s" % (" ".join(args),))
+ if users:
+ config = getConfig(configFileName)
+ directory = getDirectory(config)
+
+ for user in users:
+ calendarHome = \
directory.calendarHomeForShortName(directory.recordType_users, user) + \
calendarHomes.add(calendarHome) +
for calendarHome in calendarHomes:
for childName in calendarHome.listChildren():
child = calendarHome.getChild(childName)
@@ -140,6 +161,7 @@
except UsageError, e:
usage(e)
+_dummyDirectoryRecord = None
def dummyDirectoryRecord():
global _dummyDirectoryRecord
if _dummyDirectoryRecord is None:
@@ -163,7 +185,55 @@
autoSchedule = False,
)
return _dummyDirectoryRecord
-_dummyDirectoryRecord = None
+_config = None
+def getConfig(configFileName):
+ global _config
+ if _config is None:
+ from twistedcaldav.config import config, defaultConfigFile
+
+ if configFileName is None:
+ configFileName = defaultConfigFile
+
+ if not os.path.isfile(configFileName):
+ sys.stderr.write("No config file: %s\n" % (configFileName,))
+ sys.exit(1)
+
+ config.loadConfig(configFileName)
+
+ _config = config
+
+ return _config
+
+_directory = None
+def getDirectory(config):
+ global _directory
+ if _directory is None:
+ BaseDirectoryService = namedClass(config.DirectoryService["type"])
+
+ class MyDirectoryService (BaseDirectoryService):
+ def principalCollection(self):
+ if not hasattr(self, "_principalCollection"):
+ #
+ # Instantiating a CalendarHomeProvisioningResource with a \
directory + # will register it with the directory (still smells \
like a hack). + #
+ # We need that in order to locate calendar homes via the \
directory. + #
+ from twistedcaldav.static import CalendarHomeProvisioningFile
+ CalendarHomeProvisioningFile(os.path.join(config.DocumentRoot, \
"calendars"), self, "/calendars/") +
+ from twistedcaldav.directory.principal import \
DirectoryPrincipalProvisioningResource + self._principalCollection \
= DirectoryPrincipalProvisioningResource("/principals/", self) +
+ return self._principalCollection
+
+ def calendarHomeForShortName(self, recordType, shortName):
+ return self.principalCollection().principalForShortName(recordType, \
shortName).calendarHome() +
+ _directory = MyDirectoryService(**config.DirectoryService["params"])
+
+ return _directory
+
if __name__ == "__main__":
main()
[Attachment #5 (text/html)]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[3300] CalendarServer/trunk/calendarserver/tools/export.py</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: \
verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: \
bold} #msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: \
bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: \
6px; } #logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em \
0; } #logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg \
h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; } \
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; \
} #logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: \
-1.5em; padding-left: 1.5em; } #logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em \
1em 0 1em; background: white;} #logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid \
#fa0; border-bottom: 1px solid #fa0; background: #fff; } #logmsg table th { \
text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted \
#fa0; } #logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: \
0.2em 0.5em; } #logmsg table thead th { text-align: center; border-bottom: 1px solid \
#fa0; } #logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: \
6px; } #patch { width: 100%; }
#patch h4 {font-family: \
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, \
#patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins \
{background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del \
{background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, \
.info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a \
href="http://trac.macosforge.org/projects/calendarserver/changeset/3300">3300</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2008-10-31 11:28:58 -0700 (Fri, 31 Oct 2008)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add -u option.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsexportpy">CalendarServer/trunk/calendarserver/tools/export.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsexportpy"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/trunk/calendarserver/tools/export.py (3299 => 3300)</h4> <pre \
class="diff"><span> <span class="info">--- \
CalendarServer/trunk/calendarserver/tools/export.py 2008-10-31 18:11:21 UTC (rev \
3299)
+++ CalendarServer/trunk/calendarserver/tools/export.py 2008-10-31 18:28:58 UTC (rev \
3300) </span><span class="lines">@@ -21,8 +21,9 @@
</span><span class="cx"> from getopt import getopt, GetoptError
</span><span class="cx"> from os.path import dirname, abspath
</span><span class="cx">
</span><del>-from twistedcaldav.ical import Component as iComponent, Property as \
iProperty,\
- iCalendarProductID
</del><ins>+from twisted.python.reflect import namedClass
+from twistedcaldav.ical import Component as iComponent, Property as iProperty
+from twistedcaldav.ical import iCalendarProductID
</ins><span class="cx"> from twistedcaldav.resource import \
isCalendarCollectionResource </span><span class="cx"> from twistedcaldav.static \
import CalDAVFile, CalendarHomeFile </span><span class="cx"> from \
twistedcaldav.directory.directory import DirectoryService, DirectoryRecord \
</span><span class="lines">@@ -36,15 +37,17 @@ </span><span class="cx"> print \
"" </span><span class="cx">
</span><span class="cx"> name = os.path.basename(sys.argv[0])
</span><del>- print "usage: %s [-c collection_path] [-H \
calendar_home_path]" % (name,) </del><ins>+ print "usage: %s [-f config] \
[-c collection_path] [-H calendar_home_path] [-u user]" % (name,) </ins><span \
class="cx"> print "" </span><span class="cx"> print "Generate \
an iCalendar file containing the merged content of each calendar" </span><span \
class="cx"> print "collection read." </span><span class="cx"> print \
"" </span><span class="cx"> print "options:"
</span><span class="cx"> print " -h --help: print this help"
</span><ins>+ print " -f --config: Specify caldavd.plist configuration \
path" </ins><span class="cx"> print " -c --collection: add a calendar \
collection" </span><span class="cx"> print " -H --home: add a calendar \
home (and all calendars within it)" </span><ins>+ print " -u --user: \
add a user's calendar home (and all calendars within it)" </ins><span \
class="cx"> </span><span class="cx"> if e:
</span><span class="cx"> sys.exit(64)
</span><span class="lines">@@ -54,16 +57,20 @@
</span><span class="cx"> def main():
</span><span class="cx"> try:
</span><span class="cx"> (optargs, args) = getopt(
</span><del>- sys.argv[1:], "hc:H:", [
</del><ins>+ sys.argv[1:], "hf:c:H:u:", [
+ "config=",
</ins><span class="cx"> "help",
</span><del>- "collection=", "home="
</del><ins>+ "collection=", "home=", \
"user=", </ins><span class="cx"> ],
</span><span class="cx"> )
</span><span class="cx"> except GetoptError, e:
</span><span class="cx"> usage(e)
</span><span class="cx">
</span><ins>+ configFileName = None
+
</ins><span class="cx"> collections = set()
</span><span class="cx"> calendarHomes = set()
</span><ins>+ users = set()
</ins><span class="cx">
</span><span class="cx"> def checkExists(resource):
</span><span class="cx"> if not resource.exists():
</span><span class="lines">@@ -74,6 +81,9 @@
</span><span class="cx"> if opt in ("-h", "--help"):
</span><span class="cx"> usage()
</span><span class="cx">
</span><ins>+ elif opt in ("-f", "--config"):
+ configFileName = arg
+
</ins><span class="cx"> elif opt in ("-c", \
"--collection"): </span><span class="cx"> path = abspath(arg)
</span><span class="cx"> collection = CalDAVFile(path)
</span><span class="lines">@@ -90,9 +100,20 @@
</span><span class="cx"> checkExists(calendarHome)
</span><span class="cx"> calendarHomes.add(calendarHome)
</span><span class="cx">
</span><ins>+ elif opt in ("-u", "--user"):
+ users.add(arg)
+
</ins><span class="cx"> if args:
</span><span class="cx"> usage("Too many arguments: %s" % (" \
".join(args),)) </span><span class="cx">
</span><ins>+ if users:
+ config = getConfig(configFileName)
+ directory = getDirectory(config)
+
+ for user in users:
+ calendarHome = \
directory.calendarHomeForShortName(directory.recordType_users, user) + \
calendarHomes.add(calendarHome) +
</ins><span class="cx"> for calendarHome in calendarHomes:
</span><span class="cx"> for childName in calendarHome.listChildren():
</span><span class="cx"> child = calendarHome.getChild(childName)
</span><span class="lines">@@ -140,6 +161,7 @@
</span><span class="cx"> except UsageError, e:
</span><span class="cx"> usage(e)
</span><span class="cx">
</span><ins>+_dummyDirectoryRecord = None
</ins><span class="cx"> def dummyDirectoryRecord():
</span><span class="cx"> global _dummyDirectoryRecord
</span><span class="cx"> if _dummyDirectoryRecord is None:
</span><span class="lines">@@ -163,7 +185,55 @@
</span><span class="cx"> autoSchedule = False,
</span><span class="cx"> )
</span><span class="cx"> return _dummyDirectoryRecord
</span><del>-_dummyDirectoryRecord = None
</del><span class="cx">
</span><ins>+_config = None
+def getConfig(configFileName):
+ global _config
+ if _config is None:
+ from twistedcaldav.config import config, defaultConfigFile
+
+ if configFileName is None:
+ configFileName = defaultConfigFile
+
+ if not os.path.isfile(configFileName):
+ sys.stderr.write("No config file: %s\n" % (configFileName,))
+ sys.exit(1)
+
+ config.loadConfig(configFileName)
+
+ _config = config
+
+ return _config
+
+_directory = None
+def getDirectory(config):
+ global _directory
+ if _directory is None:
+ BaseDirectoryService = namedClass(config.DirectoryService["type"])
+
+ class MyDirectoryService (BaseDirectoryService):
+ def principalCollection(self):
+ if not hasattr(self, "_principalCollection"):
+ #
+ # Instantiating a CalendarHomeProvisioningResource with a \
directory + # will register it with the directory (still smells \
like a hack). + #
+ # We need that in order to locate calendar homes via the \
directory. + #
+ from twistedcaldav.static import CalendarHomeProvisioningFile
+ CalendarHomeProvisioningFile(os.path.join(config.DocumentRoot, \
"calendars"), self, "/calendars/") +
+ from twistedcaldav.directory.principal import \
DirectoryPrincipalProvisioningResource + self._principalCollection \
= DirectoryPrincipalProvisioningResource("/principals/", self) +
+ return self._principalCollection
+
+ def calendarHomeForShortName(self, recordType, shortName):
+ return self.principalCollection().principalForShortName(recordType, \
shortName).calendarHome() +
+ _directory = \
MyDirectoryService(**config.DirectoryService["params"]) +
+ return _directory
+
</ins><span class="cx"> if __name__ == "__main__":
</span><span class="cx"> main()
</span></span></pre>
</div>
</div>
</body>
</html>
_______________________________________________
calendarserver-changes mailing list
calendarserver-changes@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/calendarserver-changes
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic