[prev in list] [next in list] [prev in thread] [next in thread] 

List:       calendarserver-changes
Subject:    [CalendarServer-changes] [15072] CalendarServer/trunk/calendarserver/tools
From:       source_changes () macosforge ! org
Date:       2015-08-27 19:06:30
Message-ID: 20150827190630.5FBD4140F0F () svn ! calendarserver ! org
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Revision: 15072
          http://trac.calendarserver.org//changeset/15072
Author:   cdaboo@apple.com
Date:     2015-08-27 12:06:30 -0700 (Thu, 27 Aug 2015)
Log Message:
-----------
Add missing-location (with fix option) to CalVerify.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/calverify.py
    CalendarServer/trunk/calendarserver/tools/test/test_calverify.py

Modified: CalendarServer/trunk/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/calverify.py	2015-08-27 16:11:05 UTC \
                (rev 15071)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py	2015-08-27 19:06:30 UTC \
(rev 15072) @@ -286,6 +286,13 @@
 --invalid-organizer  : only detect events with an organizer not in the directory
 --disabled-organizer : only detect events with an organizer disabled for calendaring
 
+Options for --missing-location:
+
+--uuid     : only scan specified calendar homes. Can be a partial GUID
+             to scan all GUIDs with that as a prefix or "*" for all GUIDS
+             (that are marked as locations in the directory).
+--summary  : report only which GUIDs have bad events - no details.
+
 Options for --split:
 
 --path     : URI path to resource to split.
@@ -327,6 +334,7 @@
         ['missing', 'm', "Show 'orphaned' homes."],
         ['double', 'd', "Detect double-bookings."],
         ['dark-purge', 'p', "Purge room/resource events with invalid organizer."],
+        ['missing-location', 'g', "Room events with missing location."],
         ['split', 'l', "Split an event."],
         ['fix', 'x', "Fix problems."],
         ['verbose', 'v', "Verbose logging."],
@@ -2570,6 +2578,284 @@
 
 
 
+class MissingLocationService(CalVerifyService):
+    """
+    Service which detects room/resource events that have an ATTENDEE;CUTYPE=ROOM \
property but no Location. +    """
+
+    def title(self):
+        return "Missing Location Service"
+
+
+    @inlineCallbacks
+    def doAction(self):
+
+        self.output.write("\n---- Scanning calendar data ----\n")
+
+        self.tzid = Timezone(tzid=self.options["tzid"] if self.options["tzid"] else \
"America/Los_Angeles") +        self.now = DateTime.getNowUTC()
+        self.start = self.options["start"] if "start" in self.options else \
DateTime.getToday() +        self.start.setDateOnly(False)
+        self.start.setTimezone(self.tzid)
+        self.fix = self.options["fix"]
+
+        if self.options["verbose"] and self.options["summary"]:
+            ot = time.time()
+
+        # Check loop over uuid
+        UUIDDetails = collections.namedtuple("UUIDDetails", ("uuid", "rname", \
"missing",)) +        self.uuid_details = []
+        if len(self.options["uuid"]) != 36:
+            self.txn = self.store.newTransaction()
+            if self.options["uuid"]:
+                homes = yield self.getMatchingHomeUIDs(self.options["uuid"])
+            else:
+                homes = yield self.getAllHomeUIDs()
+            yield self.txn.commit()
+            self.txn = None
+            uuids = []
+            if self.options["verbose"]:
+                self.output.write("%d uuids to check\n" % (len(homes,)))
+            for uuid in sorted(homes):
+                record = yield self.directoryService().recordWithUID(uuid)
+                if record is not None and record.recordType == \
CalRecordType.location: +                    uuids.append(uuid)
+        else:
+            uuids = [self.options["uuid"], ]
+        if self.options["verbose"]:
+            self.output.write("%d uuids to scan\n" % (len(uuids,)))
+
+        count = 0
+        for uuid in uuids:
+            self.results = {}
+            self.summary = []
+            self.total = 0
+            count += 1
+
+            record = yield self.directoryService().recordWithUID(uuid)
+            if record is None:
+                continue
+            if not record.thisServer() or not record.hasCalendars:
+                continue
+
+            rname = record.displayName
+
+            if len(uuids) > 1 and not self.options["summary"]:
+                self.output.write("\n\n-----------------------------\n")
+
+            self.txn = self.store.newTransaction()
+
+            if self.options["verbose"]:
+                t = time.time()
+            rows = yield self.getAllResourceInfoTimeRangeWithUUID(self.start, uuid)
+            descriptor = "getAllResourceInfoTimeRangeWithUUID"
+
+            yield self.txn.commit()
+            self.txn = None
+
+            if self.options["verbose"]:
+                if not self.options["summary"]:
+                    self.output.write("%s time: %.1fs\n" % (descriptor, time.time() \
- t,)) +                else:
+                    self.output.write("%s (%d/%d)" % (uuid, count, len(uuids),))
+                    self.output.flush()
+
+            self.total = len(rows)
+            if not self.options["summary"]:
+                self.logResult("UUID to process", uuid)
+                self.logResult("Record name", rname)
+                self.addSummaryBreak()
+                self.logResult("Number of events to process", self.total)
+
+            if rows:
+                if not self.options["summary"]:
+                    self.addSummaryBreak()
+                missing = yield self.missingLocation(rows, uuid, rname)
+            else:
+                missing = False
+
+            self.uuid_details.append(UUIDDetails(uuid, rname, missing))
+
+            if not self.options["summary"]:
+                self.printSummary()
+            else:
+                self.output.write(" - %s\n" % ("Bad Events" if missing else "OK",))
+                self.output.flush()
+
+        if count == 0:
+            self.output.write("Nothing to scan\n")
+
+        if self.options["summary"]:
+            table = tables.Table()
+            table.addHeader(("GUID", "Name", "RID", "UID",))
+            missing = 0
+            for item in sorted(self.uuid_details):
+                if not item.purged:
+                    continue
+                uuid = item.uuid
+                rname = item.rname
+                for detail in item.purged:
+                    table.addRow((
+                        uuid,
+                        rname,
+                        detail.resid,
+                        detail.uid,
+                    ))
+                    uuid = ""
+                    rname = ""
+                    missing += 1
+            table.addFooter(("Total", "%d" % (missing,), "", "", "",))
+            self.output.write("\n")
+            table.printTable(os=self.output)
+
+            if self.options["verbose"]:
+                self.output.write("%s time: %.1fs\n" % ("Summary", time.time() - \
ot,)) +
+
+    @inlineCallbacks
+    def missingLocation(self, rows, uuid, rname):
+        """
+        Check each calendar resource by looking at any ORGANIZER property value and \
verifying it is valid. +        """
+
+        if not self.options["summary"]:
+            self.output.write("\n---- Checking for missing location events ----\n")
+        self.txn = self.store.newTransaction()
+
+        if self.options["verbose"]:
+            t = time.time()
+
+        Details = collections.namedtuple("Details", ("resid", "uid",))
+
+        count = 0
+        total = len(rows)
+        details = []
+        fixed = 0
+        rjust = 10
+        for resid in rows:
+            resid = resid[1]
+            caldata = yield self.getCalendar(resid, self.fix)
+            if caldata is None:
+                if self.parseError:
+                    returnValue((False, self.parseError))
+                else:
+                    returnValue((True, "Nothing to scan"))
+
+            cal = Component(None, pycalendar=caldata)
+            uid = cal.resourceUID()
+
+            fail = False
+            if cal.getOrganizer() is not None:
+                for comp in cal.subcomponents():
+                    if comp.name() != "VEVENT":
+                        continue
+                    location = comp.propertyValue("LOCATION")
+                    if location is None:
+                        fail = True
+                        break
+                    else:
+                        # Test the actual location value matches this location name?
+                        pass
+
+            if fail:
+                details.append(Details(resid, uid,))
+                if self.fix:
+                    yield self.fixCalendarData(cal, rname)
+                    fixed += 1
+
+            if self.options["verbose"] and not self.options["summary"]:
+                if count == 1:
+                    self.output.write("Current".rjust(rjust) + "Total".rjust(rjust) \
+ "Complete".rjust(rjust) + "\n") +                if divmod(count, 100)[1] == 0:
+                    self.output.write((
+                        "\r" +
+                        ("%s" % count).rjust(rjust) +
+                        ("%s" % total).rjust(rjust) +
+                        ("%d%%" % safePercent(count, total)).rjust(rjust)
+                    ).ljust(80))
+                    self.output.flush()
+
+            # To avoid holding locks on all the rows scanned, commit every 100 \
resources +            if divmod(count, 100)[1] == 0:
+                yield self.txn.commit()
+                self.txn = self.store.newTransaction()
+
+        yield self.txn.commit()
+        self.txn = None
+        if self.options["verbose"] and not self.options["summary"]:
+            self.output.write((
+                "\r" +
+                ("%s" % count).rjust(rjust) +
+                ("%s" % total).rjust(rjust) +
+                ("%d%%" % safePercent(count, total)).rjust(rjust)
+            ).ljust(80) + "\n")
+
+        # Print table of results
+        if not self.options["summary"]:
+            self.logResult("Number of bad events", len(details))
+
+        self.results["Bad Events"] = details
+        if self.fix:
+            self.results["Fix bad events"] = fixed
+
+        if self.options["verbose"] and not self.options["summary"]:
+            diff_time = time.time() - t
+            self.output.write("Time: %.2f s  Average: %.1f ms/resource\n" % (
+                diff_time,
+                safePercent(diff_time, total, 1000.0),
+            ))
+
+        returnValue(details)
+
+
+    @inlineCallbacks
+    def fixCalendarData(self, cal, rname):
+        """
+        Fix problems in calendar data using store APIs.
+        """
+
+        # Extract organizer (strip off urn:x-uid:) and UID
+        organizer = cal.getOrganizer()[10:]
+        uid = cal.resourceUID()
+        _ignore_calendar, resid, _ignore_created, _ignore_modified = yield \
self.getCalendarForOwnerByUID(organizer, uid) +
+        # Get the organizer's calendar object and data
+        homeID, calendarID = yield self.getAllResourceInfoForResourceID(resid)
+        home = yield self.txn.calendarHomeWithResourceID(homeID)
+        calendar = yield home.childWithID(calendarID)
+        calendarObj = yield calendar.objectResourceWithID(resid)
+
+        try:
+            component = yield calendarObj.componentForUser()
+        except InternalDataStoreError:
+            returnValue((False, "Failed parse: "))
+
+        # Add missing location to all components (need to dup component when \
modifying) +        component = component.duplicate()
+        for comp in component.subcomponents():
+            if comp.name() != "VEVENT":
+                continue
+            location = comp.propertyValue("LOCATION")
+            if location is None:
+                comp.addProperty(Property("LOCATION", rname))
+
+        # Write out fix, commit and get a new transaction
+        result = True
+        message = ""
+        try:
+            yield calendarObj.setComponent(component)
+        except Exception, e:
+            print(e, component)
+            print(traceback.print_exc())
+            result = False
+            message = "Exception fix: "
+        yield self.txn.commit()
+        self.txn = self.store.newTransaction()
+
+        returnValue((result, message,))
+
+
+
 class EventSplitService(CalVerifyService):
     """
     Service which splits a recurring event at a specific date-time value.
@@ -2720,6 +3006,8 @@
             return DoubleBookingService(store, options, output, reactor, config)
         elif options["dark-purge"]:
             return DarkPurgeService(store, options, output, reactor, config)
+        elif options["missing-location"]:
+            return MissingLocationService(store, options, output, reactor, config)
         elif options["split"]:
             return EventSplitService(store, options, output, reactor, config)
         else:

Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py	2015-08-27 \
                16:11:05 UTC (rev 15071)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py	2015-08-27 \
19:06:30 UTC (rev 15072) @@ -14,6 +14,7 @@
 # limitations under the License.
 ##
 from __future__ import print_function
+from twext.enterprise.jobs.jobitem import JobItem
 
 """
 Tests for calendarserver.tools.calverify
@@ -21,7 +22,7 @@
 
 from calendarserver.tools.calverify import BadDataService, \
     SchedulingMismatchService, DoubleBookingService, DarkPurgeService, \
-    EventSplitService
+    EventSplitService, MissingLocationService
 
 from pycalendar.datetime import DateTime
 
@@ -505,7 +506,7 @@
         sync_token_new = (yield (yield self.calendarUnderTest()).syncToken())
         self.assertNotEqual(sync_token_old, sync_token_new)
 
-        # Make sure mailto: fix results in urn:uuid value without SCHEDULE-AGENT
+        # Make sure mailto: fix results in urn:x-uid value without SCHEDULE-AGENT
         obj = yield self.calendarObjectUnderTest(name="bad10.ics")
         ical = yield obj.component()
         org = ical.getOrganizerProperty()
@@ -2793,3 +2794,209 @@
         self.assertTrue("%(now_fwd10)s" % self.subs in result)
         self.assertTrue("%(now_fwd11)s *" % self.subs in result)
         self.assertTrue("%(now_fwd12)s" % self.subs in result)
+
+
+
+class CalVerifyMissingLocations(CalVerifyMismatchTestsBase):
+    """
+    Tests calverify for events.
+    """
+
+    subs = {
+        "year": nowYear,
+        "month": nowMonth,
+        "uuid1": CalVerifyMismatchTestsBase.uuid1,
+        "uuid2": CalVerifyMismatchTestsBase.uuid2,
+        "uuid3": CalVerifyMismatchTestsBase.uuid3,
+        "uuidl1": CalVerifyMismatchTestsBase.uuidl1,
+    }
+
+    # Valid event
+    VALID_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:VALID_ICS
+TRANSP:OPAQUE
+SUMMARY:VALID_ICS
+DTSTART:%(year)s%(month)02d08T100000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE:urn:x-uid:%(uuidl1)s
+LOCATION:Location 1
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n") % subs
+
+    # Invalid event
+    INVALID_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:INVALID_ICS
+TRANSP:OPAQUE
+SUMMARY:INVALID_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE:urn:x-uid:%(uuidl1)s
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n") % subs
+
+    allEvents = {
+        "invite1.ics"      : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite2.ics"      : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+    }
+
+    requirements = {
+        CalVerifyMismatchTestsBase.uuid1 : {
+            "calendar" : allEvents,
+            "inbox" : {},
+        },
+        CalVerifyMismatchTestsBase.uuid2 : {
+            "calendar" : allEvents,
+            "inbox" : {},
+        },
+        CalVerifyMismatchTestsBase.uuid3 : {
+            "calendar" : {},
+            "inbox" : {},
+        },
+        CalVerifyMismatchTestsBase.uuidl1 : {
+            "calendar" : allEvents,
+            "inbox" : {},
+        },
+    }
+
+    @inlineCallbacks
+    def test_scanMissingLocations(self):
+        """
+        MissingLocationService.doAction without fix for missing locations. Make sure \
it detects +        as much as it can. Make sure sync-token is not changed.
+        """
+
+        sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name="calendar")).syncToken()) +        yield self.commit()
+
+        options = {
+            "ical": False,
+            "badcua": False,
+            "mismatch": False,
+            "nobase64": False,
+            "double": False,
+            "dark-purge": False,
+            "missing-location": True,
+            "fix": False,
+            "verbose": False,
+            "details": False,
+            "summary": False,
+            "days": 365,
+            "uid": "",
+            "uuid": self.uuidl1,
+            "tzid": "utc",
+            "start": DateTime(nowYear, 1, 1, 0, 0, 0),
+            "no-organizer": False,
+            "invalid-organizer": False,
+            "disabled-organizer": False,
+        }
+        output = StringIO()
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, \
reactor, config) +        yield calverify.doAction()
+
+        self.assertEqual(calverify.results["Number of events to process"], \
len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"])) +        \
self.assertEqual( +            sorted([i.uid for i in calverify.results["Bad \
Events"]]), +            ["INVALID_ICS", ]
+        )
+        self.assertEqual(calverify.results["Number of bad events"], 1)
+        self.assertTrue("Fix bad events" not in calverify.results)
+
+        sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name="calendar")).syncToken()) +        self.assertEqual(sync_token_oldl1, \
sync_token_newl1) +
+
+    @inlineCallbacks
+    def test_fixMissingLocations(self):
+        """
+        MissingLocationService.doAction with fix for missing locations. Make sure it \
detects +        as much as it can. Make sure sync-token is changed.
+        """
+
+        # Make sure location is in each users event
+        for uid in (self.uuid1, self.uuid2, self.uuidl1,):
+            calobj = yield self.calendarObjectUnderTest(home=uid, \
calendar_name="calendar", name="invite2.ics") +            caldata = yield \
calobj.componentForUser() +            self.assertTrue("LOCATION:" not in \
str(caldata)) +        yield self.commit()
+
+        sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name="calendar")).syncToken()) +        yield self.commit()
+
+        options = {
+            "ical": False,
+            "badcua": False,
+            "mismatch": False,
+            "nobase64": False,
+            "double": False,
+            "dark-purge": False,
+            "missing-location": True,
+            "fix": True,
+            "verbose": False,
+            "details": False,
+            "summary": False,
+            "days": 365,
+            "uid": "",
+            "uuid": self.uuidl1,
+            "tzid": "utc",
+            "start": DateTime(nowYear, 1, 1, 0, 0, 0),
+            "no-organizer": False,
+            "invalid-organizer": False,
+            "disabled-organizer": False,
+        }
+        output = StringIO()
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, \
reactor, config) +        yield calverify.doAction()
+
+        self.assertEqual(calverify.results["Number of events to process"], \
len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"])) +        \
self.assertEqual( +            sorted([i.uid for i in calverify.results["Bad \
Events"]]), +            ["INVALID_ICS", ]
+        )
+        self.assertEqual(calverify.results["Number of bad events"], 1)
+        self.assertEqual(calverify.results["Fix bad events"], 1)
+
+        sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name="calendar")).syncToken()) +        self.assertNotEqual(sync_token_oldl1, \
sync_token_newl1) +        yield self.commit()
+
+        # Wait for it to complete
+        yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+
+        # Re-scan after changes to make sure there are no errors
+        options["fix"] = False
+        options["uuid"] = self.uuidl1
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, \
reactor, config) +        yield calverify.doAction()
+
+        self.assertEqual(calverify.results["Number of events to process"], \
len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"])) +        \
self.assertEqual(len(calverify.results["Bad Events"]), 0) +        \
self.assertTrue("Fix bad events" not in calverify.results) +
+        # Make sure location is in each users event
+        for uid in (self.uuid1, self.uuid2, self.uuidl1,):
+            calobj = yield self.calendarObjectUnderTest(home=uid, \
calendar_name="calendar", name="invite2.ics") +            caldata = yield \
calobj.componentForUser() +            self.assertTrue("LOCATION:" in str(caldata))
+        yield self.commit()


[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>[15072] CalendarServer/trunk/calendarserver/tools</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.calendarserver.org//changeset/15072">15072</a></dd> <dt>Author</dt> \
<dd>cdaboo@apple.com</dd> <dt>Date</dt> <dd>2015-08-27 12:06:30 -0700 (Thu, 27 Aug \
2015)</dd> </dl>

<h3>Log Message</h3>
<pre>Add missing-location (with fix option) to CalVerify.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolscalverifypy">CalendarServer/trunk/calendarserver/tools/calverify.py</a></li>
 <li><a href="#CalendarServertrunkcalendarservertoolstesttest_calverifypy">CalendarServer/trunk/calendarserver/tools/test/test_calverify.py</a></li>
 </ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolscalverifypy"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/trunk/calendarserver/tools/calverify.py (15071 => 15072)</h4> <pre \
class="diff"><span> <span class="info">--- \
CalendarServer/trunk/calendarserver/tools/calverify.py	2015-08-27 16:11:05 UTC (rev \
                15071)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py	2015-08-27 19:06:30 UTC \
(rev 15072) </span><span class="lines">@@ -286,6 +286,13 @@
</span><span class="cx"> --invalid-organizer  : only detect events with an organizer \
not in the directory </span><span class="cx"> --disabled-organizer : only detect \
events with an organizer disabled for calendaring </span><span class="cx"> 
</span><ins>+Options for --missing-location:
+
+--uuid     : only scan specified calendar homes. Can be a partial GUID
+             to scan all GUIDs with that as a prefix or &quot;*&quot; for all GUIDS
+             (that are marked as locations in the directory).
+--summary  : report only which GUIDs have bad events - no details.
+
</ins><span class="cx"> Options for --split:
</span><span class="cx"> 
</span><span class="cx"> --path     : URI path to resource to split.
</span><span class="lines">@@ -327,6 +334,7 @@
</span><span class="cx">         ['missing', 'm', &quot;Show 'orphaned' \
homes.&quot;], </span><span class="cx">         ['double', 'd', &quot;Detect \
double-bookings.&quot;], </span><span class="cx">         ['dark-purge', 'p', \
&quot;Purge room/resource events with invalid organizer.&quot;], </span><ins>+        \
['missing-location', 'g', &quot;Room events with missing location.&quot;], \
</ins><span class="cx">         ['split', 'l', &quot;Split an event.&quot;], \
</span><span class="cx">         ['fix', 'x', &quot;Fix problems.&quot;], \
</span><span class="cx">         ['verbose', 'v', &quot;Verbose logging.&quot;], \
</span><span class="lines">@@ -2570,6 +2578,284 @@ </span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class MissingLocationService(CalVerifyService):
+    &quot;&quot;&quot;
+    Service which detects room/resource events that have an ATTENDEE;CUTYPE=ROOM \
property but no Location. +    &quot;&quot;&quot;
+
+    def title(self):
+        return &quot;Missing Location Service&quot;
+
+
+    @inlineCallbacks
+    def doAction(self):
+
+        self.output.write(&quot;\n---- Scanning calendar data ----\n&quot;)
+
+        self.tzid = Timezone(tzid=self.options[&quot;tzid&quot;] if \
self.options[&quot;tzid&quot;] else &quot;America/Los_Angeles&quot;) +        \
self.now = DateTime.getNowUTC() +        self.start = self.options[&quot;start&quot;] \
if &quot;start&quot; in self.options else DateTime.getToday() +        \
self.start.setDateOnly(False) +        self.start.setTimezone(self.tzid)
+        self.fix = self.options[&quot;fix&quot;]
+
+        if self.options[&quot;verbose&quot;] and self.options[&quot;summary&quot;]:
+            ot = time.time()
+
+        # Check loop over uuid
+        UUIDDetails = collections.namedtuple(&quot;UUIDDetails&quot;, \
(&quot;uuid&quot;, &quot;rname&quot;, &quot;missing&quot;,)) +        \
self.uuid_details = [] +        if len(self.options[&quot;uuid&quot;]) != 36:
+            self.txn = self.store.newTransaction()
+            if self.options[&quot;uuid&quot;]:
+                homes = yield \
self.getMatchingHomeUIDs(self.options[&quot;uuid&quot;]) +            else:
+                homes = yield self.getAllHomeUIDs()
+            yield self.txn.commit()
+            self.txn = None
+            uuids = []
+            if self.options[&quot;verbose&quot;]:
+                self.output.write(&quot;%d uuids to check\n&quot; % (len(homes,)))
+            for uuid in sorted(homes):
+                record = yield self.directoryService().recordWithUID(uuid)
+                if record is not None and record.recordType == \
CalRecordType.location: +                    uuids.append(uuid)
+        else:
+            uuids = [self.options[&quot;uuid&quot;], ]
+        if self.options[&quot;verbose&quot;]:
+            self.output.write(&quot;%d uuids to scan\n&quot; % (len(uuids,)))
+
+        count = 0
+        for uuid in uuids:
+            self.results = {}
+            self.summary = []
+            self.total = 0
+            count += 1
+
+            record = yield self.directoryService().recordWithUID(uuid)
+            if record is None:
+                continue
+            if not record.thisServer() or not record.hasCalendars:
+                continue
+
+            rname = record.displayName
+
+            if len(uuids) &gt; 1 and not self.options[&quot;summary&quot;]:
+                self.output.write(&quot;\n\n-----------------------------\n&quot;)
+
+            self.txn = self.store.newTransaction()
+
+            if self.options[&quot;verbose&quot;]:
+                t = time.time()
+            rows = yield self.getAllResourceInfoTimeRangeWithUUID(self.start, uuid)
+            descriptor = &quot;getAllResourceInfoTimeRangeWithUUID&quot;
+
+            yield self.txn.commit()
+            self.txn = None
+
+            if self.options[&quot;verbose&quot;]:
+                if not self.options[&quot;summary&quot;]:
+                    self.output.write(&quot;%s time: %.1fs\n&quot; % (descriptor, \
time.time() - t,)) +                else:
+                    self.output.write(&quot;%s (%d/%d)&quot; % (uuid, count, \
len(uuids),)) +                    self.output.flush()
+
+            self.total = len(rows)
+            if not self.options[&quot;summary&quot;]:
+                self.logResult(&quot;UUID to process&quot;, uuid)
+                self.logResult(&quot;Record name&quot;, rname)
+                self.addSummaryBreak()
+                self.logResult(&quot;Number of events to process&quot;, self.total)
+
+            if rows:
+                if not self.options[&quot;summary&quot;]:
+                    self.addSummaryBreak()
+                missing = yield self.missingLocation(rows, uuid, rname)
+            else:
+                missing = False
+
+            self.uuid_details.append(UUIDDetails(uuid, rname, missing))
+
+            if not self.options[&quot;summary&quot;]:
+                self.printSummary()
+            else:
+                self.output.write(&quot; - %s\n&quot; % (&quot;Bad Events&quot; if \
missing else &quot;OK&quot;,)) +                self.output.flush()
+
+        if count == 0:
+            self.output.write(&quot;Nothing to scan\n&quot;)
+
+        if self.options[&quot;summary&quot;]:
+            table = tables.Table()
+            table.addHeader((&quot;GUID&quot;, &quot;Name&quot;, &quot;RID&quot;, \
&quot;UID&quot;,)) +            missing = 0
+            for item in sorted(self.uuid_details):
+                if not item.purged:
+                    continue
+                uuid = item.uuid
+                rname = item.rname
+                for detail in item.purged:
+                    table.addRow((
+                        uuid,
+                        rname,
+                        detail.resid,
+                        detail.uid,
+                    ))
+                    uuid = &quot;&quot;
+                    rname = &quot;&quot;
+                    missing += 1
+            table.addFooter((&quot;Total&quot;, &quot;%d&quot; % (missing,), \
&quot;&quot;, &quot;&quot;, &quot;&quot;,)) +            \
self.output.write(&quot;\n&quot;) +            table.printTable(os=self.output)
+
+            if self.options[&quot;verbose&quot;]:
+                self.output.write(&quot;%s time: %.1fs\n&quot; % \
(&quot;Summary&quot;, time.time() - ot,)) +
+
+    @inlineCallbacks
+    def missingLocation(self, rows, uuid, rname):
+        &quot;&quot;&quot;
+        Check each calendar resource by looking at any ORGANIZER property value and \
verifying it is valid. +        &quot;&quot;&quot;
+
+        if not self.options[&quot;summary&quot;]:
+            self.output.write(&quot;\n---- Checking for missing location events \
----\n&quot;) +        self.txn = self.store.newTransaction()
+
+        if self.options[&quot;verbose&quot;]:
+            t = time.time()
+
+        Details = collections.namedtuple(&quot;Details&quot;, (&quot;resid&quot;, \
&quot;uid&quot;,)) +
+        count = 0
+        total = len(rows)
+        details = []
+        fixed = 0
+        rjust = 10
+        for resid in rows:
+            resid = resid[1]
+            caldata = yield self.getCalendar(resid, self.fix)
+            if caldata is None:
+                if self.parseError:
+                    returnValue((False, self.parseError))
+                else:
+                    returnValue((True, &quot;Nothing to scan&quot;))
+
+            cal = Component(None, pycalendar=caldata)
+            uid = cal.resourceUID()
+
+            fail = False
+            if cal.getOrganizer() is not None:
+                for comp in cal.subcomponents():
+                    if comp.name() != &quot;VEVENT&quot;:
+                        continue
+                    location = comp.propertyValue(&quot;LOCATION&quot;)
+                    if location is None:
+                        fail = True
+                        break
+                    else:
+                        # Test the actual location value matches this location name?
+                        pass
+
+            if fail:
+                details.append(Details(resid, uid,))
+                if self.fix:
+                    yield self.fixCalendarData(cal, rname)
+                    fixed += 1
+
+            if self.options[&quot;verbose&quot;] and not \
self.options[&quot;summary&quot;]: +                if count == 1:
+                    self.output.write(&quot;Current&quot;.rjust(rjust) + \
&quot;Total&quot;.rjust(rjust) + &quot;Complete&quot;.rjust(rjust) + &quot;\n&quot;) \
+                if divmod(count, 100)[1] == 0: +                    \
self.output.write(( +                        &quot;\r&quot; +
+                        (&quot;%s&quot; % count).rjust(rjust) +
+                        (&quot;%s&quot; % total).rjust(rjust) +
+                        (&quot;%d%%&quot; % safePercent(count, total)).rjust(rjust)
+                    ).ljust(80))
+                    self.output.flush()
+
+            # To avoid holding locks on all the rows scanned, commit every 100 \
resources +            if divmod(count, 100)[1] == 0:
+                yield self.txn.commit()
+                self.txn = self.store.newTransaction()
+
+        yield self.txn.commit()
+        self.txn = None
+        if self.options[&quot;verbose&quot;] and not \
self.options[&quot;summary&quot;]: +            self.output.write((
+                &quot;\r&quot; +
+                (&quot;%s&quot; % count).rjust(rjust) +
+                (&quot;%s&quot; % total).rjust(rjust) +
+                (&quot;%d%%&quot; % safePercent(count, total)).rjust(rjust)
+            ).ljust(80) + &quot;\n&quot;)
+
+        # Print table of results
+        if not self.options[&quot;summary&quot;]:
+            self.logResult(&quot;Number of bad events&quot;, len(details))
+
+        self.results[&quot;Bad Events&quot;] = details
+        if self.fix:
+            self.results[&quot;Fix bad events&quot;] = fixed
+
+        if self.options[&quot;verbose&quot;] and not \
self.options[&quot;summary&quot;]: +            diff_time = time.time() - t
+            self.output.write(&quot;Time: %.2f s  Average: %.1f ms/resource\n&quot; \
% ( +                diff_time,
+                safePercent(diff_time, total, 1000.0),
+            ))
+
+        returnValue(details)
+
+
+    @inlineCallbacks
+    def fixCalendarData(self, cal, rname):
+        &quot;&quot;&quot;
+        Fix problems in calendar data using store APIs.
+        &quot;&quot;&quot;
+
+        # Extract organizer (strip off urn:x-uid:) and UID
+        organizer = cal.getOrganizer()[10:]
+        uid = cal.resourceUID()
+        _ignore_calendar, resid, _ignore_created, _ignore_modified = yield \
self.getCalendarForOwnerByUID(organizer, uid) +
+        # Get the organizer's calendar object and data
+        homeID, calendarID = yield self.getAllResourceInfoForResourceID(resid)
+        home = yield self.txn.calendarHomeWithResourceID(homeID)
+        calendar = yield home.childWithID(calendarID)
+        calendarObj = yield calendar.objectResourceWithID(resid)
+
+        try:
+            component = yield calendarObj.componentForUser()
+        except InternalDataStoreError:
+            returnValue((False, &quot;Failed parse: &quot;))
+
+        # Add missing location to all components (need to dup component when \
modifying) +        component = component.duplicate()
+        for comp in component.subcomponents():
+            if comp.name() != &quot;VEVENT&quot;:
+                continue
+            location = comp.propertyValue(&quot;LOCATION&quot;)
+            if location is None:
+                comp.addProperty(Property(&quot;LOCATION&quot;, rname))
+
+        # Write out fix, commit and get a new transaction
+        result = True
+        message = &quot;&quot;
+        try:
+            yield calendarObj.setComponent(component)
+        except Exception, e:
+            print(e, component)
+            print(traceback.print_exc())
+            result = False
+            message = &quot;Exception fix: &quot;
+        yield self.txn.commit()
+        self.txn = self.store.newTransaction()
+
+        returnValue((result, message,))
+
+
+
</ins><span class="cx"> class EventSplitService(CalVerifyService):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Service which splits a recurring event at a specific \
date-time value. </span><span class="lines">@@ -2720,6 +3006,8 @@
</span><span class="cx">             return DoubleBookingService(store, options, \
output, reactor, config) </span><span class="cx">         elif \
options[&quot;dark-purge&quot;]: </span><span class="cx">             return \
DarkPurgeService(store, options, output, reactor, config) </span><ins>+        elif \
options[&quot;missing-location&quot;]: +            return \
MissingLocationService(store, options, output, reactor, config) </ins><span \
class="cx">         elif options[&quot;split&quot;]: </span><span class="cx">         \
return EventSplitService(store, options, output, reactor, config) </span><span \
class="cx">         else: </span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_calverifypy"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/trunk/calendarserver/tools/test/test_calverify.py (15071 => \
15072)</h4> <pre class="diff"><span>
<span class="info">--- \
CalendarServer/trunk/calendarserver/tools/test/test_calverify.py	2015-08-27 16:11:05 \
                UTC (rev 15071)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py	2015-08-27 \
19:06:30 UTC (rev 15072) </span><span class="lines">@@ -14,6 +14,7 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> from __future__ import print_function
</span><ins>+from twext.enterprise.jobs.jobitem import JobItem
</ins><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> Tests for calendarserver.tools.calverify
</span><span class="lines">@@ -21,7 +22,7 @@
</span><span class="cx"> 
</span><span class="cx"> from calendarserver.tools.calverify import BadDataService, \
</span><span class="cx">     SchedulingMismatchService, DoubleBookingService, \
DarkPurgeService, \ </span><del>-    EventSplitService
</del><ins>+    EventSplitService, MissingLocationService
</ins><span class="cx"> 
</span><span class="cx"> from pycalendar.datetime import DateTime
</span><span class="cx"> 
</span><span class="lines">@@ -505,7 +506,7 @@
</span><span class="cx">         sync_token_new = (yield (yield \
self.calendarUnderTest()).syncToken()) </span><span class="cx">         \
self.assertNotEqual(sync_token_old, sync_token_new) </span><span class="cx"> 
</span><del>-        # Make sure mailto: fix results in urn:uuid value without \
SCHEDULE-AGENT </del><ins>+        # Make sure mailto: fix results in urn:x-uid value \
without SCHEDULE-AGENT </ins><span class="cx">         obj = yield \
self.calendarObjectUnderTest(name=&quot;bad10.ics&quot;) </span><span class="cx">     \
ical = yield obj.component() </span><span class="cx">         org = \
ical.getOrganizerProperty() </span><span class="lines">@@ -2793,3 +2794,209 @@
</span><span class="cx">         self.assertTrue(&quot;%(now_fwd10)s&quot; % \
self.subs in result) </span><span class="cx">         \
self.assertTrue(&quot;%(now_fwd11)s *&quot; % self.subs in result) </span><span \
class="cx">         self.assertTrue(&quot;%(now_fwd12)s&quot; % self.subs in result) \
</span><ins>+ +
+
+class CalVerifyMissingLocations(CalVerifyMismatchTestsBase):
+    &quot;&quot;&quot;
+    Tests calverify for events.
+    &quot;&quot;&quot;
+
+    subs = {
+        &quot;year&quot;: nowYear,
+        &quot;month&quot;: nowMonth,
+        &quot;uuid1&quot;: CalVerifyMismatchTestsBase.uuid1,
+        &quot;uuid2&quot;: CalVerifyMismatchTestsBase.uuid2,
+        &quot;uuid3&quot;: CalVerifyMismatchTestsBase.uuid3,
+        &quot;uuidl1&quot;: CalVerifyMismatchTestsBase.uuidl1,
+    }
+
+    # Valid event
+    VALID_ICS = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:VALID_ICS
+TRANSP:OPAQUE
+SUMMARY:VALID_ICS
+DTSTART:%(year)s%(month)02d08T100000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE:urn:x-uid:%(uuidl1)s
+LOCATION:Location 1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
+    # Invalid event
+    INVALID_ICS = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:INVALID_ICS
+TRANSP:OPAQUE
+SUMMARY:INVALID_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE:urn:x-uid:%(uuidl1)s
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
+    allEvents = {
+        &quot;invite1.ics&quot;      : (VALID_ICS, \
CalVerifyMismatchTestsBase.metadata,), +        &quot;invite2.ics&quot;      : \
(INVALID_ICS, CalVerifyMismatchTestsBase.metadata,), +    }
+
+    requirements = {
+        CalVerifyMismatchTestsBase.uuid1 : {
+            &quot;calendar&quot; : allEvents,
+            &quot;inbox&quot; : {},
+        },
+        CalVerifyMismatchTestsBase.uuid2 : {
+            &quot;calendar&quot; : allEvents,
+            &quot;inbox&quot; : {},
+        },
+        CalVerifyMismatchTestsBase.uuid3 : {
+            &quot;calendar&quot; : {},
+            &quot;inbox&quot; : {},
+        },
+        CalVerifyMismatchTestsBase.uuidl1 : {
+            &quot;calendar&quot; : allEvents,
+            &quot;inbox&quot; : {},
+        },
+    }
+
+    @inlineCallbacks
+    def test_scanMissingLocations(self):
+        &quot;&quot;&quot;
+        MissingLocationService.doAction without fix for missing locations. Make sure \
it detects +        as much as it can. Make sure sync-token is not changed.
+        &quot;&quot;&quot;
+
+        sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name=&quot;calendar&quot;)).syncToken()) +        yield self.commit()
+
+        options = {
+            &quot;ical&quot;: False,
+            &quot;badcua&quot;: False,
+            &quot;mismatch&quot;: False,
+            &quot;nobase64&quot;: False,
+            &quot;double&quot;: False,
+            &quot;dark-purge&quot;: False,
+            &quot;missing-location&quot;: True,
+            &quot;fix&quot;: False,
+            &quot;verbose&quot;: False,
+            &quot;details&quot;: False,
+            &quot;summary&quot;: False,
+            &quot;days&quot;: 365,
+            &quot;uid&quot;: &quot;&quot;,
+            &quot;uuid&quot;: self.uuidl1,
+            &quot;tzid&quot;: &quot;utc&quot;,
+            &quot;start&quot;: DateTime(nowYear, 1, 1, 0, 0, 0),
+            &quot;no-organizer&quot;: False,
+            &quot;invalid-organizer&quot;: False,
+            &quot;disabled-organizer&quot;: False,
+        }
+        output = StringIO()
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, \
reactor, config) +        yield calverify.doAction()
+
+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], \
len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;])) +    \
self.assertEqual( +            sorted([i.uid for i in calverify.results[&quot;Bad \
Events&quot;]]), +            [&quot;INVALID_ICS&quot;, ]
+        )
+        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 1)
+        self.assertTrue(&quot;Fix bad events&quot; not in calverify.results)
+
+        sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name=&quot;calendar&quot;)).syncToken()) +        self.assertEqual(sync_token_oldl1, \
sync_token_newl1) +
+
+    @inlineCallbacks
+    def test_fixMissingLocations(self):
+        &quot;&quot;&quot;
+        MissingLocationService.doAction with fix for missing locations. Make sure it \
detects +        as much as it can. Make sure sync-token is changed.
+        &quot;&quot;&quot;
+
+        # Make sure location is in each users event
+        for uid in (self.uuid1, self.uuid2, self.uuidl1,):
+            calobj = yield self.calendarObjectUnderTest(home=uid, \
calendar_name=&quot;calendar&quot;, name=&quot;invite2.ics&quot;) +            \
caldata = yield calobj.componentForUser() +            \
self.assertTrue(&quot;LOCATION:&quot; not in str(caldata)) +        yield \
self.commit() +
+        sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name=&quot;calendar&quot;)).syncToken()) +        yield self.commit()
+
+        options = {
+            &quot;ical&quot;: False,
+            &quot;badcua&quot;: False,
+            &quot;mismatch&quot;: False,
+            &quot;nobase64&quot;: False,
+            &quot;double&quot;: False,
+            &quot;dark-purge&quot;: False,
+            &quot;missing-location&quot;: True,
+            &quot;fix&quot;: True,
+            &quot;verbose&quot;: False,
+            &quot;details&quot;: False,
+            &quot;summary&quot;: False,
+            &quot;days&quot;: 365,
+            &quot;uid&quot;: &quot;&quot;,
+            &quot;uuid&quot;: self.uuidl1,
+            &quot;tzid&quot;: &quot;utc&quot;,
+            &quot;start&quot;: DateTime(nowYear, 1, 1, 0, 0, 0),
+            &quot;no-organizer&quot;: False,
+            &quot;invalid-organizer&quot;: False,
+            &quot;disabled-organizer&quot;: False,
+        }
+        output = StringIO()
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, \
reactor, config) +        yield calverify.doAction()
+
+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], \
len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;])) +    \
self.assertEqual( +            sorted([i.uid for i in calverify.results[&quot;Bad \
Events&quot;]]), +            [&quot;INVALID_ICS&quot;, ]
+        )
+        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 1)
+        self.assertEqual(calverify.results[&quot;Fix bad events&quot;], 1)
+
+        sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, \
name=&quot;calendar&quot;)).syncToken()) +        \
self.assertNotEqual(sync_token_oldl1, sync_token_newl1) +        yield self.commit()
+
+        # Wait for it to complete
+        yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+
+        # Re-scan after changes to make sure there are no errors
+        options[&quot;fix&quot;] = False
+        options[&quot;uuid&quot;] = self.uuidl1
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, \
reactor, config) +        yield calverify.doAction()
+
+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], \
len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;])) +    \
self.assertEqual(len(calverify.results[&quot;Bad Events&quot;]), 0) +        \
self.assertTrue(&quot;Fix bad events&quot; not in calverify.results) +
+        # Make sure location is in each users event
+        for uid in (self.uuid1, self.uuid2, self.uuidl1,):
+            calobj = yield self.calendarObjectUnderTest(home=uid, \
calendar_name=&quot;calendar&quot;, name=&quot;invite2.ics&quot;) +            \
caldata = yield calobj.componentForUser() +            \
self.assertTrue(&quot;LOCATION:&quot; in str(caldata)) +        yield self.commit()
</ins></span></pre>
</div>
</div>

</body>
</html>



_______________________________________________
calendarserver-changes mailing list
calendarserver-changes@lists.macosforge.org
https://lists.macosforge.org/mailman/listinfo/calendarserver-changes


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic