def setUp(self): # The "local" directory service self.directory = DirectoryService(None) # The "remote" directory service if testMode == "xml": # Need a copy as it might change path = FilePath(os.path.join(os.path.dirname(__file__), "test.xml")) copy = FilePath(self.mktemp()) path.copyTo(copy) remoteDirectory = CalendarXMLDirectoryService(copy) elif testMode == "od": remoteDirectory = CalendarODDirectoryService() # Connect the two services directly via an IOPump client = AMP() server = DirectoryProxyAMPProtocol(remoteDirectory) pump = returnConnected(server, client) # Replace the normal _getConnection method with one that bypasses any # actual networking self.patch(self.directory, "_getConnection", lambda: succeed(client)) # Wrap the normal _sendCommand method with one that flushes the IOPump # afterwards origCall = self.directory._sendCommand def newCall(*args, **kwds): d = origCall(*args, **kwds) pump.flush() return d self.patch(self.directory, "_sendCommand", newCall)
def _doRefresh(tzpath, xmlfile, tzdb, tzvers): """ Refresh data from IANA. """ print("Downloading latest data from IANA") if tzvers: path = "https://www.iana.org/time-zones/repository/releases/tzdata%s.tar.gz" % (tzvers,) else: path = "https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz" data = urllib.urlretrieve(path) print("Extract data at: %s" % (data[0])) rootdir = tempfile.mkdtemp() zonedir = os.path.join(rootdir, "tzdata") os.mkdir(zonedir) with tarfile.open(data[0], "r:gz") as t: t.extractall(zonedir) # Get the version from the Makefile try: makefile = open(os.path.join(zonedir, "Makefile")).read() lines = makefile.splitlines() for line in lines: if line.startswith("VERSION="): tzvers = line[8:].strip() break except IOError: pass if not tzvers: tzvers = PyCalendarDateTime.getToday().getText() print("Converting data (version: %s) at: %s" % (tzvers, zonedir,)) startYear = 1800 endYear = PyCalendarDateTime.getToday().getYear() + 10 PyCalendar.sProdID = "-//calendarserver.org//Zonal//EN" zonefiles = "northamerica", "southamerica", "europe", "africa", "asia", "australasia", "antarctica", "etcetera", "backward" parser = tzconvert() for file in zonefiles: parser.parse(os.path.join(zonedir, file)) parser.generateZoneinfoFiles(os.path.join(rootdir, "zoneinfo"), startYear, endYear, filterzones=()) print("Copy new zoneinfo to destination: %s" % (tzpath,)) z = FilePath(os.path.join(rootdir, "zoneinfo")) tz = FilePath(tzpath) z.copyTo(tz) print("Updating XML file at: %s" % (xmlfile,)) tzdb.readDatabase() tzdb.updateDatabase() print("Current total: %d" % (len(tzdb.timezones),)) print("Total Changed: %d" % (tzdb.changeCount,)) if tzdb.changeCount: print("Changed:") for k in sorted(tzdb.changed): print(" %s" % (k,)) versfile = os.path.join(os.path.dirname(xmlfile), "version.txt") print("Updating version file at: %s" % (versfile,)) with open(versfile, "w") as f: f.write(TimezoneCache.IANA_VERSION_PREFIX + tzvers)
def _doRefresh(tzpath, xmlfile, tzdb, tzvers): """ Refresh data from IANA. """ print("Downloading latest data from IANA") if tzvers: path = "https://www.iana.org/time-zones/repository/releases/tzdata%s.tar.gz" % ( tzvers, ) else: path = "https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz" data = urllib.urlretrieve(path) print("Extract data at: %s" % (data[0])) rootdir = tempfile.mkdtemp() zonedir = os.path.join(rootdir, "tzdata") os.mkdir(zonedir) with tarfile.open(data[0], "r:gz") as t: t.extractall(zonedir) # Get the version from the Makefile try: makefile = open(os.path.join(zonedir, "Makefile")).read() lines = makefile.splitlines() for line in lines: if line.startswith("VERSION="): tzvers = line[8:].strip() break except IOError: pass if not tzvers: tzvers = DateTime.getToday().getText() print("Converting data (version: %s) at: %s" % ( tzvers, zonedir, )) startYear = 1800 endYear = DateTime.getToday().getYear() + 10 Calendar.sProdID = "-//calendarserver.org//Zonal//EN" zonefiles = "northamerica", "southamerica", "europe", "africa", "asia", "australasia", "antarctica", "etcetera", "backward" parser = tzconvert() for file in zonefiles: parser.parse(os.path.join(zonedir, file)) # Check for windows aliases print("Downloading latest data from unicode.org") path = "http://unicode.org/repos/cldr/tags/latest/common/supplemental/windowsZones.xml" data = urllib.urlretrieve(path) wpath = data[0] # Generate the iCalendar data print("Generating iCalendar data") parser.generateZoneinfoFiles(os.path.join(rootdir, "zoneinfo"), startYear, endYear, windowsAliases=wpath, filterzones=()) print("Copy new zoneinfo to destination: %s" % (tzpath, )) z = FilePath(os.path.join(rootdir, "zoneinfo")) tz = FilePath(tzpath) z.copyTo(tz) print("Updating XML file at: %s" % (xmlfile, )) tzdb.readDatabase() tzdb.updateDatabase() print("Current total: %d" % (len(tzdb.timezones), )) print("Total Changed: %d" % (tzdb.changeCount, )) if tzdb.changeCount: print("Changed:") for k in sorted(tzdb.changed): print(" %s" % (k, )) versfile = os.path.join(os.path.dirname(xmlfile), "version.txt") print("Updating version file at: %s" % (versfile, )) with open(versfile, "w") as f: f.write(TimezoneCache.IANA_VERSION_PREFIX + tzvers)