[CalendarServer-changes] [2067] CalendarServer/branches/users/cdaboo/timezones-2054

source_changes at macosforge.org source_changes at macosforge.org
Wed Dec 12 15:42:27 PST 2007


Revision: 2067
          http://trac.macosforge.org/projects/calendarserver/changeset/2067
Author:   wsanchez at apple.com
Date:     2007-12-12 15:42:24 -0800 (Wed, 12 Dec 2007)

Log Message:
-----------
Install zomeinfo data via distutils, not make.
Make this setuptools-friendly by using pkg_resources, if available.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd-test.plist
    CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd.plist
    CalendarServer/branches/users/cdaboo/timezones-2054/setup.py
    CalendarServer/branches/users/cdaboo/timezones-2054/support/Makefile.Apple
    CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/tap.py
    CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/test/test_timezones.py
    CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/timezones.py

Added Paths:
-----------
    CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/zoneinfo/

Removed Paths:
-------------
    CalendarServer/branches/users/cdaboo/timezones-2054/share/

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd-test.plist
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd-test.plist	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd-test.plist	2007-12-12 23:42:24 UTC (rev 2067)
@@ -86,15 +86,6 @@
 
 
   <!--
-    Ancillary Data
-  -->
-
-  <!-- Data root -->
-  <key>TimezoneCache</key>
-  <string>share/zoneinfo</string>
-
-
-  <!--
     Directory service
 
     A directory service provides information about principals (eg.

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd.plist
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd.plist	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/conf/caldavd.plist	2007-12-12 23:42:24 UTC (rev 2067)
@@ -87,15 +87,6 @@
 
 
   <!--
-    Ancillary Data
-  -->
-
-  <!-- Data root -->
-  <key>TimezoneCache</key>
-  <string>/usr/share/caldavd/zoneinfo</string>
-
-
-  <!--
     Directory service
 
     A directory service provides information about principals (eg.

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/setup.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/setup.py	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/setup.py	2007-12-12 23:42:24 UTC (rev 2067)
@@ -99,13 +99,15 @@
 
 extensions = []
 
-if sys.platform == 'darwin':
+if sys.platform == "darwin":
     extensions.append(
-        Extension('twistedcaldav._sacl',
-                  extra_compile_args = ['-arch', 'ppc', '-arch', 'i386'],
-                  extra_link_args    = ['-framework', 'Security',
-                                        '-arch', 'ppc', '-arch', 'i386'],
-                  sources = ['twistedcaldav/_sacl.c']))
+        Extension(
+            "twistedcaldav._sacl",
+            extra_compile_args = ["-arch", "ppc", "-arch", "i386"],
+            extra_link_args = ["-framework", "Security", "-arch", "ppc", "-arch", "i386"],
+            sources = ["twistedcaldav/_sacl.c"]
+        )
+    )
 
 #
 # Run setup
@@ -120,26 +122,34 @@
     long_description = long_description,
     url              = None,
     classifiers      = classifiers,
-    author           = "Apple Computer, Inc.",
+    author           = "Apple Inc.",
     author_email     = None,
     license          = None,
     platforms        = [ "all" ],
-    packages         = [ "twistedcaldav", "twistedcaldav.directory", 
-                         "twistedcaldav.method", "twistedcaldav.query", 
-                         "twistedcaldav.admin", "twistedcaldav.py", 
-                         "twisted" ],
-    package_data     = { "twisted": ["plugins/caldav.py"] },
+    packages         = [
+                         "twistedcaldav",
+                         "twistedcaldav.directory", 
+                         "twistedcaldav.method",
+                         "twistedcaldav.query", 
+                         "twistedcaldav.admin",
+                         "twistedcaldav.py", 
+                         "twisted"
+                       ],
+    package_data     = {
+                         "twisted": ["plugins/caldav.py"],
+                         "twistedcaldav": ["zoneinfo/*.ics", "zoneinfo/*/*.ics"],
+                       },
     scripts          = [ "bin/caldavd", "bin/caladmin" ],
-    data_files       = [("caldavd", ["conf/caldavd.plist",])],
+    data_files       = [ ("caldavd", ["conf/caldavd.plist"]) ],
     ext_modules      = extensions,
 )
 
-if 'install' in dist.commands:
+if "install" in dist.commands:
     import os
-    install_scripts = dist.command_obj['install'].install_scripts
-    install_lib = dist.command_obj['install'].install_lib
-    root = dist.command_obj['install'].root
-    base = dist.command_obj['install'].install_base
+    install_scripts = dist.command_obj["install"].install_scripts
+    install_lib = dist.command_obj["install"].install_lib
+    root = dist.command_obj["install"].root
+    base = dist.command_obj["install"].install_base
 
     if root:
         install_lib = install_lib[len(root):]
@@ -153,37 +163,34 @@
     
         fileType = None
 
-        for line in file(scriptPath, 'r'):
+        for line in file(scriptPath, "r"):
             if not fileType:
-                if line.startswith('#!'):
-                    if 'python' in line.lower():
-                        fileType = 'python'
-                    elif 'sh' in line.lower():
-                        fileType = 'sh'
+                if line.startswith("#!"):
+                    if "python" in line.lower():
+                        fileType = "python"
+                    elif "sh" in line.lower():
+                        fileType = "sh"
 
-            line = line.rstrip('\n')
-            if fileType == 'sh':
-                if line == '#PYTHONPATH':
-                    script.append(
-                        'PYTHONPATH="%s:$PYTHONPATH"' % (install_lib,))
-                elif line == '#PATH':
-                    script.append(
-                        'PATH="%s:$PATH"' % (os.path.join(base, 'bin'),))
+            line = line.rstrip("\n")
+            if fileType == "sh":
+                if line == "#PYTHONPATH":
+                    script.append('PYTHONPATH="%s:$PYTHONPATH"' % (install_lib,))
+                elif line == "#PATH":
+                    script.append('PATH="%s:$PATH"' % (os.path.join(base, "bin"),))
                 else:
                     script.append(line)
 
-            elif fileType == 'python':
-                if line == '#PYTHONPATH':
+            elif fileType == "python":
+                if line == "#PYTHONPATH":
                     script.append('PYTHONPATH="%s"' % (install_lib,))
-                elif line == '#PATH':
-                    script.append(
-                        'PATH="%s"' % (os.path.join(base, 'bin'),))
+                elif line == "#PATH":
+                    script.append('PATH="%s"' % (os.path.join(base, "bin"),))
                 else:
                     script.append(line)
 
             else:
                 script.append(line)
 
-        newScript = open(scriptPath, 'w')
-        newScript.write('\n'.join(script))
+        newScript = open(scriptPath, "w")
+        newScript.write("\n".join(script))
         newScript.close()

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/support/Makefile.Apple
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/support/Makefile.Apple	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/support/Makefile.Apple	2007-12-12 23:42:24 UTC (rev 2067)
@@ -96,7 +96,6 @@
 	$(_v) $(INSTALL_FILE) $(Sources)/doc/caldavd.8 $(DSTROOT)$(MANDIR)/man8
 	$(_v) $(INSTALL_FILE) $(Sources)/doc/caladmin.8 $(DSTROOT)$(MANDIR)/man8
 	$(_v) gzip -9 -f $(DSTROOT)$(MANDIR)/man8/*.8
-	$(_v) $(INSTALL_DIRECTORY) $(DSTROOT)$(SHAREDIR)/caldavd && cd $(Sources)/share && pax -pe -rw . $(DSTROOT)$(SHAREDIR)/caldavd
 	$(_v) $(INSTALL_DIRECTORY) $(DSTROOT)$(NSLOCALDIR)/$(NSLIBRARYSUBDIR)/$(Project)
 	$(_v) $(INSTALL_DIRECTORY) -o $(USER) -g $(GROUP) -m 0750 $(DSTROOT)$(NSLOCALDIR)/$(NSLIBRARYSUBDIR)/$(Project)/Documents
 	$(_v) $(INSTALL_DIRECTORY) -m 0755 $(DSTROOT)$(VARDIR)/log/caldavd

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/tap.py	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/tap.py	2007-12-12 23:42:24 UTC (rev 2067)
@@ -453,8 +453,8 @@
         # Configure ancillary data
         #
         logging.info("Setting up Timezone Cache", system="startup")
-        TimezoneCache(config.TimezoneCache)
-        
+        TimezoneCache().register()
+
         #
         # Configure the Site and Wrappers
         #

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/test/test_timezones.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/test/test_timezones.py	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/test/test_timezones.py	2007-12-12 23:42:24 UTC (rev 2067)
@@ -30,7 +30,6 @@
     """
 
     data_dir = os.path.join(os.path.dirname(__file__), "data")
-    share_dir = os.path.join(os.path.dirname(__file__), "../../share")
 
     def doTest(self, filename, dtstart, dtend, testEqual=True):
         
@@ -88,7 +87,8 @@
         Properties in components
         """
         registerTzid("America/New_York", None)
-        tzcache = TimezoneCache(os.path.join(self.share_dir, "zoneinfo"))
+        tzcache = TimezoneCache()
+        tzcache.register()
         self.doTest(
             "TruncatedApr01.ics",
             datetime.datetime(2007, 04, 01, 16, 0, 0, tzinfo=utc),
@@ -115,14 +115,14 @@
     """
 
     data_dir = os.path.join(os.path.dirname(__file__), "data")
-    share_dir = os.path.join(os.path.dirname(__file__), "../../share")
 
     def test_basic(self):
         
         registerTzid("America/New_York", None)
         registerTzid("US/Eastern", None)
 
-        tzcache = TimezoneCache(os.path.join(self.share_dir, "zoneinfo"))
+        tzcache = TimezoneCache()
+        tzcache.register()
         self.assertTrue(tzcache.loadTimezone("America/New_York"))
         self.assertTrue(tzcache.loadTimezone("US/Eastern"))
         tzcache.unregister()

Modified: CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/timezones.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/timezones.py	2007-12-12 17:00:55 UTC (rev 2066)
+++ CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/timezones.py	2007-12-12 23:42:24 UTC (rev 2067)
@@ -37,26 +37,18 @@
 calendar data.
 """
 
+__all__ = [
+    "TimezoneException",
+    "TimezoneCache",
+]
+
 class TimezoneException(Exception):
     pass
 
 class TimezoneCache(object):
-    
-    def __init__(self, dirname):
-        """
-        
-        @param dirname: the directory that is the root of the Olson data.
-        @type dirname: str
-        """
-        
-        assert os.path.exists(dirname), "Timezone directory %s does not exist." % (dirname,)
-        assert os.path.isdir(dirname), "%s is not a directory." % (dirname,)
-        assert os.path.exists(os.path.join(dirname, "America/New_York.ics")), "Timezone directory %s does not seem to contain timezones" % (dirname,)
-        self.dirname = dirname
+    def __init__(self):
+        self._caching = False
 
-        self.caching = False
-        self.register()
-
     def register(self):
         self.vobjectRegisterTzid = registerTzid
         vobject.icalendar.registerTzid = self.registerTzidFromCache
@@ -65,16 +57,16 @@
         vobject.icalendar.registerTzid = self.vobjectRegisterTzid
 
     def loadTimezone(self, tzid):
-        
         # Make sure it is not already loaded
         if getTzid(tzid) != None:
             return False
 
-        tzpath = os.path.join(self.dirname, tzid) + ".ics"
-        if not os.path.exists(tzpath):
-            raise TimezoneException("Timezone path %s missing" % (tzpath,))
-        
-        calendar = Component.fromStream(file(tzpath))
+        tzStream = openTZ(tzid)
+        try:
+            calendar = Component.fromStream(tzStream)
+        finally:
+            tzStream.close()
+
         if calendar.name() != "VCALENDAR":
             raise TimezoneException("%s does not contain valid iCalendar data." % (tzpath,))
 
@@ -85,10 +77,31 @@
         return True
 
     def registerTzidFromCache(self, tzid, tzinfo):
-        
-        if not self.caching:
-            self.caching = True
+        if not self._caching:
+            self._caching = True
             self.loadTimezone(tzid)
-            self.caching = False
+            self._caching = False
         else:
             self.vobjectRegisterTzid(tzid, tzinfo)
+
+try:
+    import pkg_resources
+except ImportError:
+    #
+    # We don't have pkg_resources, so assume file paths work, since that's all we have
+    #
+    dirname = os.path.join(os.path.dirname(__file__), "zoneinfo")
+    def openTZ(tzid):
+        tzpath = os.path.join(*tzid.split("/")) # Don't assume "/" from tzid is a path separator
+        tzpath = os.path.join(dirname, tzpath + ".ics")
+        try:
+            return file(tzpath)
+        except IOError:
+            raise TimezoneException("Unknown time zone: %s" % (tzid,))
+else:
+    def openTZ(tzid):
+        # Here, "/" is always the path separator
+        try:
+            return pkg_resources.resource_stream("twistedcaldav", "zoneinfo/%s.ics" % (tzid,))
+        except IOError:
+            raise TimezoneException("Unknown time zone: %s" % (tzid,))

Copied: CalendarServer/branches/users/cdaboo/timezones-2054/twistedcaldav/zoneinfo (from rev 2066, CalendarServer/branches/users/cdaboo/timezones-2054/share/zoneinfo)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20071212/a93ca9f2/attachment-0001.html


More information about the calendarserver-changes mailing list