예제 #1
0
    def test_calendar_query_bogus_timezone_id(self):
        """
        Partial retrieval of events by time range.
        (CalDAV-access-09, section 7.6.1)
        """
        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        calendar_properties = (
            davxml.GETETag(),
            caldavxml.CalendarData(),
        )

        query_timerange = caldavxml.TimeRange(
            start="%04d1001T000000Z" % (DateTime.getToday().getYear(), ),
            end="%04d1101T000000Z" % (DateTime.getToday().getYear(), ),
        )

        query = caldavxml.CalendarQuery(
            davxml.PropertyContainer(*calendar_properties),
            caldavxml.Filter(
                caldavxml.ComponentFilter(
                    caldavxml.ComponentFilter(
                        query_timerange,
                        name="VEVENT",
                    ),
                    name="VCALENDAR",
                ), ),
            caldavxml.TimeZoneID.fromString("bogus"),
        )

        result = yield self.calendar_query(
            query, got_xml=None, expected_code=responsecode.FORBIDDEN)
        self.assertTrue("valid-timezone" in result)
예제 #2
0
 def __init__(self, store, options, output, reactor, config):
     super(PodMigrationService, self).__init__(store)
     self.options = options
     self.output = output
     self.reactor = reactor
     self.config = config
     TimezoneCache.create()
예제 #3
0
    def test_copyPackage(self):
        """
        Test that copying of the tz package works.
        """

        self.patch(config, "UsePackageTimezones", True)
        TimezoneCache.clear()
        TimezoneCache.create()

        self.assertFalse(
            os.path.exists(os.path.join(config.DataRoot, "zoneinfo")))
        self.assertFalse(
            os.path.exists(
                os.path.join(config.DataRoot, "zoneinfo", "America",
                             "New_York.ics")))

        pkg_tz = readTZ("America/New_York")

        self.patch(config, "UsePackageTimezones", False)
        TimezoneCache.clear()
        TimezoneCache.create()

        self.assertTrue(
            os.path.exists(os.path.join(config.DataRoot, "zoneinfo")))
        self.assertTrue(
            os.path.exists(
                os.path.join(config.DataRoot, "zoneinfo", "America",
                             "New_York.ics")))

        copy_tz = readTZ("America/New_York")

        self.assertEqual(str(pkg_tz), str(copy_tz))
    def test_calendar_query_bogus_timezone_id(self):
        """
        Partial retrieval of events by time range.
        (CalDAV-access-09, section 7.6.1)
        """
        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        calendar_properties = (
            davxml.GETETag(),
            caldavxml.CalendarData(),
        )

        query_timerange = caldavxml.TimeRange(
            start="%04d1001T000000Z" % (DateTime.getToday().getYear(),),
            end="%04d1101T000000Z" % (DateTime.getToday().getYear(),),
        )

        query = caldavxml.CalendarQuery(
            davxml.PropertyContainer(*calendar_properties),
            caldavxml.Filter(
                caldavxml.ComponentFilter(
                    caldavxml.ComponentFilter(
                        query_timerange,
                        name="VEVENT",
                    ),
                    name="VCALENDAR",
                ),
            ),
            caldavxml.TimeZoneID.fromString("bogus"),
        )

        result = yield self.calendar_query(query, got_xml=None, expected_code=responsecode.FORBIDDEN)
        self.assertTrue("valid-timezone" in result)
예제 #5
0
 def __init__(self, store, options, output, reactor, config):
     super(PodMigrationService, self).__init__(store)
     self.options = options
     self.output = output
     self.reactor = reactor
     self.config = config
     TimezoneCache.create()
예제 #6
0
    def __init__(self,
                 records,
                 populator,
                 random,
                 parameters,
                 reactor,
                 servers,
                 principalPathTemplate,
                 serializationPath,
                 workerIndex=0,
                 workerCount=1):
        self._records = records
        self.populator = populator
        self._random = random
        self.reactor = reactor
        self.servers = servers
        self.principalPathTemplate = principalPathTemplate
        self.serializationPath = serializationPath
        self._pop = self.populator.populate(parameters)
        self._user = 0
        self._stopped = False
        self.workerIndex = workerIndex
        self.workerCount = workerCount
        self.clients = []

        TimezoneCache.create()
예제 #7
0
    def __init__(self, store, options, reactor, config):
        super(ImporterService, self).__init__(store)
        self.options = options
        self.reactor = reactor
        self.config = config
        self._directory = self.store.directoryService()

        TimezoneCache.create()
예제 #8
0
    def __init__(self, store, options, reactor, config):
        super(ImporterService, self).__init__(store)
        self.options = options
        self.reactor = reactor
        self.config = config
        self._directory = self.store.directoryService()

        TimezoneCache.create()
    def _calendarTimezoneUpgrade_setup(self):

        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        tz1 = Component(None, pycalendar=readVTZ("Etc/GMT+1"))
        tz2 = Component(None, pycalendar=readVTZ("Etc/GMT+2"))
        tz3 = Component(None, pycalendar=readVTZ("Etc/GMT+3"))

        # Share user01 calendar with user03
        calendar = (yield self.calendarUnderTest(name="calendar_1", home="user01"))
        home3 = yield self.homeUnderTest(name="user03")
        shared_name = yield calendar.shareWith(home3, _BIND_MODE_WRITE)

        user_details = (
            ("user01", "calendar_1", tz1),
            ("user02", "calendar_1", tz2),
            ("user03", "calendar_1", None),
            ("user03", shared_name, tz3),
        )

        # Set dead properties on calendars
        for user, calname, tz in user_details:
            calendar = (yield self.calendarUnderTest(name=calname, home=user))
            if tz:
                calendar.properties()[PropertyName.fromElement(caldavxml.CalendarTimeZone)] = caldavxml.CalendarTimeZone.fromString(str(tz))

            # Force data version to previous
            home = (yield self.homeUnderTest(name=user))
            ch = home._homeSchema
            yield Update(
                {ch.DATAVERSION: 4},
                Where=ch.RESOURCE_ID == home._resourceID,
            ).on(self.transactionUnderTest())

        yield self.commit()

        for user, calname, tz in user_details:
            calendar = (yield self.calendarUnderTest(name=calname, home=user))
            self.assertEqual(calendar.getTimezone(), None)
            self.assertEqual(PropertyName.fromElement(caldavxml.CalendarTimeZone) in calendar.properties(), tz is not None)
        yield self.commit()

        # Create "fake" entry for non-existent share
        txn = self.transactionUnderTest()
        calendar = (yield self.calendarUnderTest(name="calendar_1", home="user01"))
        rp = schema.RESOURCE_PROPERTY
        yield Insert(
            {
                rp.RESOURCE_ID: calendar._resourceID,
                rp.NAME: PropertyName.fromElement(caldavxml.CalendarTimeZone).toString(),
                rp.VALUE: caldavxml.CalendarTimeZone.fromString(str(tz3)).toxml(),
                rp.VIEWER_UID: "user04",
            }
        ).on(txn)
        yield self.commit()

        returnValue(user_details)
예제 #10
0
    def test_truncatedDec(self):
        """
        Custom VTZ valid from 2007. Daylight 2007 OK.
        """

        TimezoneCache.create(empty=True)
        TimezoneCache.clear()

        self.doTest("TruncatedDec10.ics",
                    DateTime(2007, 12, 10, 17, 0, 0, Timezone.UTCTimezone),
                    DateTime(2007, 12, 10, 18, 0, 0, Timezone.UTCTimezone))
예제 #11
0
    def test_truncatedApr(self):
        """
        Custom VTZ with truncated standard time - 2006. Daylight 2007 OK.
        """

        TimezoneCache.create(empty=True)
        TimezoneCache.clear()

        self.doTest("TruncatedApr01.ics",
                    DateTime(2007, 04, 01, 16, 0, 0, Timezone.UTCTimezone),
                    DateTime(2007, 04, 01, 17, 0, 0, Timezone.UTCTimezone))
    def test_truncatedDec(self):
        """
        Properties in components
        """
        TimezoneCache.create("")
        TimezoneCache.clear()

        self.doTest(
            "TruncatedDec10.ics",
            PyCalendarDateTime(2007, 12, 10, 17, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 12, 10, 18, 0, 0, PyCalendarTimezone(utc=True))
        )
    def test_truncatedDec(self):
        """
        Custom VTZ valid from 2007. Daylight 2007 OK.
        """

        TimezoneCache.create(empty=True)
        TimezoneCache.clear()

        self.doTest(
            "TruncatedDec10.ics",
            PyCalendarDateTime(2007, 12, 10, 17, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 12, 10, 18, 0, 0, PyCalendarTimezone(utc=True))
        )
    def test_truncatedApr(self):
        """
        Custom VTZ with truncated standard time - 2006. Daylight 2007 OK.
        """

        TimezoneCache.create(empty=True)
        TimezoneCache.clear()

        self.doTest(
            "TruncatedApr01.ics",
            PyCalendarDateTime(2007, 04, 01, 16, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 04, 01, 17, 0, 0, PyCalendarTimezone(utc=True))
        )
    def test_truncatedApr(self):
        """
        Properties in components
        """
        
        TimezoneCache.create("")
        TimezoneCache.clear()

        self.doTest(
            "TruncatedApr01.ics",
            PyCalendarDateTime(2007, 04, 01, 16, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 04, 01, 17, 0, 0, PyCalendarTimezone(utc=True))
        )
예제 #16
0
    def test_truncatedDecThenApr(self):
        """
        Custom VTZ valid from 2007 loaded first. Daylight 2007 OK.
        """

        TimezoneCache.create(empty=True)
        TimezoneCache.clear()

        self.doTest("TruncatedDec10.ics",
                    DateTime(2007, 12, 10, 17, 0, 0, Timezone.UTCTimezone),
                    DateTime(2007, 12, 10, 18, 0, 0, Timezone.UTCTimezone))
        self.doTest("TruncatedApr01.ics",
                    DateTime(2007, 04, 01, 16, 0, 0, Timezone.UTCTimezone),
                    DateTime(2007, 04, 01, 17, 0, 0, Timezone.UTCTimezone))
    def test_truncatedAprThenDecOK(self):
        """
        Properties in components
        """
        TimezoneCache.create()

        self.doTest(
            "TruncatedApr01.ics",
            PyCalendarDateTime(2007, 04, 01, 16, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 04, 01, 17, 0, 0, PyCalendarTimezone(utc=True)),
        )
        self.doTest(
            "TruncatedDec10.ics",
            PyCalendarDateTime(2007, 12, 10, 17, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 12, 10, 18, 0, 0, PyCalendarTimezone(utc=True)),
        )
예제 #18
0
    def __init__(self, records, populator, parameters, reactor, server,
                 principalPathTemplate, serializationPath, workerIndex=0, workerCount=1):
        self._records = records
        self.populator = populator
        self.reactor = reactor
        self.server = server
        self.principalPathTemplate = principalPathTemplate
        self.serializationPath = serializationPath
        self._pop = self.populator.populate(parameters)
        self._user = 0
        self._stopped = False
        self.workerIndex = workerIndex
        self.workerCount = workerCount
        self.clients = []

        TimezoneCache.create()
예제 #19
0
    def test_copyPackage_missingVersion(self):
        """
        Test that tz data is updated if the version is missing.
        """

        self.patch(config, "UsePackageTimezones", False)
        TimezoneCache.clear()
        TimezoneCache.create()

        self.assertTrue(os.path.exists(os.path.join(config.DataRoot, "zoneinfo")))
        self.assertTrue(os.path.exists(os.path.join(config.DataRoot, "zoneinfo", "version.txt")))
        os.remove(os.path.join(config.DataRoot, "zoneinfo", "version.txt"))
        self.assertFalse(os.path.exists(os.path.join(config.DataRoot, "zoneinfo", "version.txt")))

        TimezoneCache.create()
        self.assertTrue(os.path.exists(os.path.join(config.DataRoot, "zoneinfo", "version.txt")))
예제 #20
0
    def test_not_in_cache(self):

        TimezoneCache.create()

        data = """BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VTIMEZONE
TZID:US-Eastern
LAST-MODIFIED:19870101T000000Z
BEGIN:STANDARD
DTSTART:19671029T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:Eastern Standard Time (US & Canada)
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:19870405T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:Eastern Daylight Time (US & Canada)
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
UID:12345-67890
DTSTART;TZID="US-Eastern":20071225T000000
DTEND;TZID="US-Eastern":20071225T010000
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VEVENT
END:VCALENDAR
"""

        calendar = Component.fromString(data)
        if calendar.name() != "VCALENDAR":
            self.fail("Calendar is not a VCALENDAR")
        instances = calendar.expandTimeRanges(DateTime(2100, 1, 1))
        for key in instances:
            instance = instances[key]
            start = instance.start
            end = instance.end
            self.assertEqual(
                start, DateTime(2007, 12, 25, 05, 0, 0, Timezone.UTCTimezone))
            self.assertEqual(
                end, DateTime(2007, 12, 25, 06, 0, 0, Timezone.UTCTimezone))
            break
예제 #21
0
    def test_truncatedAprThenDecFail(self):
        """
        Custom VTZ with truncated standard time - 2006 loaded first. Daylight 2007 OK, standard 2007 wrong.
        """

        TimezoneCache.create(empty=True)
        TimezoneCache.clear()

        self.doTest(
            "TruncatedApr01.ics",
            DateTime(2007, 04, 01, 16, 0, 0, Timezone.UTCTimezone),
            DateTime(2007, 04, 01, 17, 0, 0, Timezone.UTCTimezone),
        )
        self.doTest("TruncatedDec10.ics",
                    DateTime(2007, 12, 10, 17, 0, 0, Timezone.UTCTimezone),
                    DateTime(2007, 12, 10, 18, 0, 0, Timezone.UTCTimezone),
                    testEqual=False)
예제 #22
0
    def test_truncatedAprThenDecOK(self):
        """
        VTZ loaded from std timezone DB. 2007 OK.
        """

        TimezoneCache.create()

        self.doTest(
            "TruncatedApr01.ics",
            DateTime(2007, 04, 01, 16, 0, 0, Timezone.UTCTimezone),
            DateTime(2007, 04, 01, 17, 0, 0, Timezone.UTCTimezone),
        )
        self.doTest(
            "TruncatedDec10.ics",
            DateTime(2007, 12, 10, 17, 0, 0, Timezone.UTCTimezone),
            DateTime(2007, 12, 10, 18, 0, 0, Timezone.UTCTimezone),
        )
    def test_truncatedAprThenDecOK(self):
        """
        VTZ loaded from std timezone DB. 2007 OK.
        """

        TimezoneCache.create()

        self.doTest(
            "TruncatedApr01.ics",
            PyCalendarDateTime(2007, 04, 01, 16, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 04, 01, 17, 0, 0, PyCalendarTimezone(utc=True)),
        )
        self.doTest(
            "TruncatedDec10.ics",
            PyCalendarDateTime(2007, 12, 10, 17, 0, 0, PyCalendarTimezone(utc=True)),
            PyCalendarDateTime(2007, 12, 10, 18, 0, 0, PyCalendarTimezone(utc=True)),
        )
예제 #24
0
    def test_truncatedAprThenDecOK(self):
        """
        VTZ loaded from std timezone DB. 2007 OK.
        """

        TimezoneCache.create()

        self.doTest(
            "TruncatedApr01.ics",
            DateTime(2007, 04, 01, 16, 0, 0, Timezone.UTCTimezone),
            DateTime(2007, 04, 01, 17, 0, 0, Timezone.UTCTimezone),
        )
        self.doTest(
            "TruncatedDec10.ics",
            DateTime(2007, 12, 10, 17, 0, 0, Timezone.UTCTimezone),
            DateTime(2007, 12, 10, 18, 0, 0, Timezone.UTCTimezone),
        )
예제 #25
0
    def test_calendar_query_timezone(self):
        """
        Partial retrieval of events by time range.
        (CalDAV-access-09, section 7.6.1)
        """
        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        tzid1 = "Etc/GMT+1"
        tz1 = Component(None, pycalendar=readVTZ(tzid1))

        calendar_properties = (
            davxml.GETETag(),
            caldavxml.CalendarData(),
        )

        query_timerange = caldavxml.TimeRange(
            start="%04d1001T000000Z" % (DateTime.getToday().getYear(), ),
            end="%04d1101T000000Z" % (DateTime.getToday().getYear(), ),
        )

        query = caldavxml.CalendarQuery(
            davxml.PropertyContainer(*calendar_properties),
            caldavxml.Filter(
                caldavxml.ComponentFilter(
                    caldavxml.ComponentFilter(
                        query_timerange,
                        name="VEVENT",
                    ),
                    name="VCALENDAR",
                ), ),
            caldavxml.TimeZone.fromCalendar(tz1),
        )

        def got_xml(doc):
            if not isinstance(doc.root_element, davxml.MultiStatus):
                self.fail(
                    "REPORT response XML root element is not multistatus: %r" %
                    (doc.root_element, ))

        return self.calendar_query(query, got_xml)
예제 #26
0
    def test_calendar_query_wrong_timezone_elements(self):
        """
        Partial retrieval of events by time range.
        (CalDAV-access-09, section 7.6.1)
        """
        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        tzid1 = "Etc/GMT+1"
        tz1 = Component(None, pycalendar=readVTZ(tzid1))

        calendar_properties = (
            davxml.GETETag(),
            caldavxml.CalendarData(),
        )

        query_timerange = caldavxml.TimeRange(
            start="%04d1001T000000Z" % (DateTime.getToday().getYear(), ),
            end="%04d1101T000000Z" % (DateTime.getToday().getYear(), ),
        )

        query = caldavxml.CalendarQuery(
            davxml.PropertyContainer(*calendar_properties),
            caldavxml.Filter(
                caldavxml.ComponentFilter(
                    caldavxml.ComponentFilter(
                        query_timerange,
                        name="VEVENT",
                    ),
                    name="VCALENDAR",
                ), ),
            caldavxml.TimeZone.fromCalendar(tz1),
        )
        query.children += (caldavxml.TimeZoneID.fromString(tzid1), )

        result = yield self.calendar_query(
            query, got_xml=None, expected_code=responsecode.BAD_REQUEST)
        self.assertTrue("Only one of" in result)
예제 #27
0
    def test_copyPackage_missingVersion(self):
        """
        Test that tz data is updated if the version is missing.
        """

        self.patch(config, "UsePackageTimezones", False)
        TimezoneCache.clear()
        TimezoneCache.create()

        self.assertTrue(
            os.path.exists(os.path.join(config.DataRoot, "zoneinfo")))
        self.assertTrue(
            os.path.exists(
                os.path.join(config.DataRoot, "zoneinfo", "version.txt")))
        os.remove(os.path.join(config.DataRoot, "zoneinfo", "version.txt"))
        self.assertFalse(
            os.path.exists(
                os.path.join(config.DataRoot, "zoneinfo", "version.txt")))

        TimezoneCache.create()
        self.assertTrue(
            os.path.exists(
                os.path.join(config.DataRoot, "zoneinfo", "version.txt")))
    def _calendarTimezoneUpgrade_setup(self):

        TimezoneCache.create()
        self.addCleanup(TimezoneCache.clear)

        tz1 = Component(None, pycalendar=readVTZ("Etc/GMT+1"))
        tz2 = Component(None, pycalendar=readVTZ("Etc/GMT+2"))
        tz3 = Component(None, pycalendar=readVTZ("Etc/GMT+3"))

        # Share user01 calendar with user03
        calendar = (yield self.calendarUnderTest(name="calendar_1",
                                                 home="user01"))
        home3 = yield self.homeUnderTest(name="user03")
        shared_name = yield calendar.shareWith(home3, _BIND_MODE_WRITE)

        user_details = (
            ("user01", "calendar_1", tz1),
            ("user02", "calendar_1", tz2),
            ("user03", "calendar_1", None),
            ("user03", shared_name, tz3),
        )

        # Set dead properties on calendars
        for user, calname, tz in user_details:
            calendar = (yield self.calendarUnderTest(name=calname, home=user))
            if tz:
                calendar.properties()[PropertyName.fromElement(
                    caldavxml.CalendarTimeZone
                )] = caldavxml.CalendarTimeZone.fromString(str(tz))

            # Force data version to previous
            home = (yield self.homeUnderTest(name=user))
            ch = home._homeSchema
            yield Update(
                {
                    ch.DATAVERSION: 4
                },
                Where=ch.RESOURCE_ID == home._resourceID,
            ).on(self.transactionUnderTest())

        yield self.commit()

        for user, calname, tz in user_details:
            calendar = (yield self.calendarUnderTest(name=calname, home=user))
            self.assertEqual(calendar.getTimezone(), None)
            self.assertEqual(
                PropertyName.fromElement(caldavxml.CalendarTimeZone)
                in calendar.properties(), tz is not None)
        yield self.commit()

        # Create "fake" entry for non-existent share
        txn = self.transactionUnderTest()
        calendar = (yield self.calendarUnderTest(name="calendar_1",
                                                 home="user01"))
        rp = schema.RESOURCE_PROPERTY
        yield Insert({
            rp.RESOURCE_ID:
            calendar._resourceID,
            rp.NAME:
            PropertyName.fromElement(caldavxml.CalendarTimeZone).toString(),
            rp.VALUE:
            caldavxml.CalendarTimeZone.fromString(str(tz3)).toxml(),
            rp.VIEWER_UID:
            "user04",
        }).on(txn)
        yield self.commit()

        returnValue(user_details)
예제 #29
0
        for urlpiece in urlbits[:-1]:
            child = parent.getChild(urlpiece)
            if child is None:
                child = Resource()
                parent.putChild(urlpiece, child)
            parent = child
        if parent.getChild(urlbits[-1]) is not None:
            log.error("Invalid alias: URL: {url}  Path: {path} already exists", url=url, path=path)
            continue
        resource = FileResource(path)
        parent.putChild(urlbits[-1], resource)
        log.info("Added alias {url} -> {path}", url=url, path=path)

    # Need timezone cache before setting up any timezone service
    log.info("Setting up Timezone Cache")
    TimezoneCache.create()

    # Timezone service is optional
    if config.EnableTimezoneService:
        log.info("Setting up time zone service resource: {cls}",
                      cls=timezoneServiceResourceClass)

        timezoneService = timezoneServiceResourceClass(
            root,
        )
        root.putChild("timezones", timezoneService)

    # Standard Timezone service is optional
    if config.TimezoneService.Enabled:
        log.info("Setting up standard time zone service resource: {cls}",
                      cls=timezoneStdServiceResourceClass)
예제 #30
0
def utilityMain(
    configFileName, serviceClass, reactor=None, serviceMaker=None,
    patchConfig=None, onShutdown=None, verbose=False, loadTimezones=False
):
    """
    Shared main-point for utilities.

    This function will:

        - Load the configuration file named by C{configFileName},
        - launch a L{CalDAVServiceMaker}'s with the C{ProcessType} of
          C{"Utility"}
        - run the reactor, with start/stop events hooked up to the service's
          C{startService}/C{stopService} methods.

    It is C{serviceClass}'s responsibility to stop the reactor when it's
    complete.

    @param configFileName: the name of the configuration file to load.
    @type configuration: C{str}

    @param serviceClass: a 1-argument callable which takes an object that
        provides L{ICalendarStore} and/or L{IAddressbookStore} and returns an
        L{IService}.

    @param patchConfig: a 1-argument callable which takes a config object
        and makes and changes necessary for the tool.

    @param onShutdown: a 0-argument callable which will run on shutdown.

    @param reactor: if specified, the L{IReactorTime} / L{IReactorThreads} /
        L{IReactorTCP} (etc) provider to use.  If C{None}, the default reactor
        will be imported and used.
    """

    from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions
    if serviceMaker is None:
        serviceMaker = CalDAVServiceMaker

    # We want to validate that the actual service is always an instance of WorkerService, so wrap the
    # service maker callback inside a function that does that check
    def _makeValidService(store):
        service = serviceClass(store)
        assert isinstance(service, WorkerService)
        return service

    # Install std i/o observer
    observers = []
    if verbose:
        observers.append(FileLogObserver(sys.stdout, lambda event: formatEventAsClassicLogText(event)))

    if reactor is None:
        from twisted.internet import reactor
    try:
        config = loadConfig(configFileName)
        if patchConfig is not None:
            patchConfig(config)

        checkDirectories(config)

        utilityLogFile = LogFile.fromFullPath(
            config.UtilityLogFile,
            rotateLength=config.ErrorLogRotateMB * 1024 * 1024,
            maxRotatedFiles=config.ErrorLogMaxRotatedFiles
        )
        utilityLogObserver = FileLogObserver(utilityLogFile, lambda event: formatEventAsClassicLogText(event))
        utilityLogObserver._encoding = "utf-8"
        observers.append(utilityLogObserver)
        Logger.beginLoggingTo(observers, redirectStandardIO=False)

        config.ProcessType = "Utility"
        config.UtilityServiceClass = _makeValidService

        autoDisableMemcached(config)

        maker = serviceMaker()

        # Only perform post-import duties if someone has explicitly said to
        maker.doPostImport = getattr(maker, "doPostImport", False)

        options = CalDAVOptions
        service = maker.makeService(options)

        reactor.addSystemEventTrigger("during", "startup", service.startService)
        reactor.addSystemEventTrigger("before", "shutdown", service.stopService)
        if onShutdown is not None:
            reactor.addSystemEventTrigger("before", "shutdown", onShutdown)

        if loadTimezones:
            TimezoneCache.create()

    except (ConfigurationError, OSError), e:
        sys.stderr.write("Error: %s\n" % (e,))
        return
예제 #31
0
 def setUp(self):
     super(TestQueryFilter, self).setUp()
     TimezoneCache.create()
예제 #32
0
 def tearDown(self):
     TimezoneCache.clear()
     TimezoneCache.create()
예제 #33
0
 def _try(n):
     try:
         TimezoneCache.create()
     except:
         f = Failure()
         ex[n] = str(f)
예제 #34
0
 def setUp(self):
     super(Dateops, self).setUp()
     TimezoneCache.create()
예제 #35
0
 def setUp(self):
     super(TimezonePackageTest, self).setUp()
     TimezoneCache.clear()
     TimezoneCache.create()
예제 #36
0
 def setUp(self):
     super(LocalizationTests, self).setUp()
     TimezoneCache.create()
예제 #37
0
    def test_basic(self):

        TimezoneCache.create()
        self.assertTrue(readTZ("America/New_York"))
        self.assertTrue(readTZ("US/Eastern"))
예제 #38
0
 def setUp(self):
     TimezoneCache.create()