def testRead(self): xmlfile = self.mktemp() db1 = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db1.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) db2 = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db2.readDatabase() self.assertEqual(db1.dtstamp, db2.dtstamp) self.assertEqual(len(db1.timezones), len(db2.timezones))
def testRead(self): xmlfile = self.mktemp() db1 = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db1.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) db2 = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db2.readDatabase() self.assertEqual(db1.dtstamp, db2.dtstamp) self.assertEqual(len(db1.timezones), len(db2.timezones))
def _initPrimaryService(self): tzpath = TimezoneCache.getDBPath() xmlfile = os.path.join(tzpath, "timezones.xml") self.timezones = PrimaryTimezoneDatabase(tzpath, xmlfile) if not os.path.exists(xmlfile): self.timezones.createNewDatabase() else: self.timezones.readDatabase() self.info_source = TimezoneCache.version
def _initPrimaryService(self): tzpath = TimezoneCache.getDBPath() xmlfile = os.path.join(tzpath, "timezones.xml") self.timezones = PrimaryTimezoneDatabase(tzpath, xmlfile) if not os.path.exists(xmlfile): self.timezones.createNewDatabase() else: self.timezones.readDatabase() self.info_source = TimezoneCache.version
def testListChangedSince(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) tzids = set([tz.tzid for tz in db.listTimezones(db.dtstamp)]) self.assertTrue(len(tzids) == 0)
def testGetNone(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) tz = db.getTimezone("Bogus") self.assertEqual(tz, None)
def testCreate(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) self.assertTrue(db.dtstamp is not None) self.assertTrue(len(db.timezones) > 0)
def testCreate(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) self.assertTrue(db.dtstamp is not None) self.assertTrue(len(db.timezones) > 0)
def testGetNone(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) tz = db.getTimezone("Bogus") self.assertEqual(tz, None)
def testListChangedSince(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) tzids = set([tz.tzid for tz in db.listTimezones(db.dtstamp)]) self.assertTrue(len(tzids) == 0)
def testList(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) tzids = set([tz.tzid for tz in db.listTimezones(None)]) self.assertTrue("America/New_York" in tzids) self.assertTrue("US/Eastern" not in tzids)
def testList(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) tzids = set([tz.tzid for tz in db.listTimezones(None)]) self.assertTrue("America/New_York" in tzids) self.assertTrue("US/Eastern" not in tzids)
def testUpdate(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) db.updateDatabase() self.assertTrue(db.changeCount == 0) self.assertTrue(len(db.changed) == 0)
def testUpdate(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) db.updateDatabase() self.assertTrue(db.changeCount == 0) self.assertTrue(len(db.changed) == 0)
def _initSecondaryService(self): # Must have writeable paths tzpath = TimezoneCache.getDBPath() xmlfile = config.TimezoneService.XMLInfoPath if not xmlfile: xmlfile = os.path.join(tzpath, "timezones.xml") self.timezones = SecondaryTimezoneDatabase(tzpath, xmlfile, None) try: self.timezones.readDatabase() except: pass self.info_source = "Secondary" self.primary = False
def _initSecondaryService(self): # Must have writeable paths tzpath = TimezoneCache.getDBPath() xmlfile = config.TimezoneService.XMLInfoPath if not xmlfile: xmlfile = os.path.join(tzpath, "timezones.xml") self.timezones = SecondaryTimezoneDatabase(tzpath, xmlfile, None) try: self.timezones.readDatabase() except: pass self.info_source = "Secondary" self.primary = False
def testGetOne(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) # Original tz1 = db.getTimezone("America/New_York") self.assertTrue(str(tz1).find("VTIMEZONE") != -1) self.assertTrue(str(tz1).find("TZID:America/New_York") != -1) # Alias tz1 = db.getTimezone("US/Eastern") self.assertTrue(str(tz1).find("VTIMEZONE") != -1) self.assertTrue(str(tz1).find("TZID:US/Eastern") != -1)
def testGetOne(self): xmlfile = self.mktemp() db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile) db.createNewDatabase() self.assertTrue(os.path.exists(xmlfile)) # Original tz1 = db.getTimezone("America/New_York") self.assertTrue(str(tz1).find("VTIMEZONE") != -1) self.assertTrue(str(tz1).find("TZID:America/New_York") != -1) # Alias tz1 = db.getTimezone("US/Eastern") self.assertTrue(str(tz1).find("VTIMEZONE") != -1) self.assertTrue(str(tz1).find("TZID:US/Eastern") != -1)
if action is None: action = "list" primary = True if tzpath is None: if updatepkg: try: import pkg_resources except ImportError: tzpath = os.path.join(os.path.dirname(__file__), "zoneinfo") else: tzpath = pkg_resources.resource_filename( "twistedcaldav", "zoneinfo") #@UndefinedVariable else: # Setup the correct zoneinfo path based on the config tzpath = TimezoneCache.getDBPath() TimezoneCache.validatePath() if xmlfile is None: xmlfile = os.path.join(tzpath, "timezones.xml") if primary and not os.path.isdir(tzpath): usage("Invalid zoneinfo path: %s" % (tzpath, )) if primary and not os.path.isfile(xmlfile) and action != "create": usage("Invalid XML file path: %s" % (xmlfile, )) if primary and secondary: usage("Cannot use primary and secondary options together") if primary: _doPrimaryActions(action, tzpath, xmlfile, changed, tzvers) else:
sys.exit(1) if action is None: action = "list" primary = True if tzpath is None: if updatepkg: try: import pkg_resources except ImportError: tzpath = os.path.join(os.path.dirname(__file__), "zoneinfo") else: tzpath = pkg_resources.resource_filename("twistedcaldav", "zoneinfo") #@UndefinedVariable else: # Setup the correct zoneinfo path based on the config tzpath = TimezoneCache.getDBPath() TimezoneCache.validatePath() if xmlfile is None: xmlfile = os.path.join(tzpath, "timezones.xml") if primary and not os.path.isdir(tzpath): usage("Invalid zoneinfo path: %s" % (tzpath,)) if primary and not os.path.isfile(xmlfile) and action != "create": usage("Invalid XML file path: %s" % (xmlfile,)) if primary and secondary: usage("Cannot use primary and secondary options together") if primary: _doPrimaryActions(action, tzpath, xmlfile, changed, tzvers) else: