[CalendarServer-changes] [14585] CalendarServer/trunk/calendarserver/tools/trash.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 12 19:18:07 PDT 2015
Revision: 14585
http://trac.calendarserver.org//changeset/14585
Author: sagen at apple.com
Date: 2015-03-12 19:18:06 -0700 (Thu, 12 Mar 2015)
Log Message:
-----------
Tweaks to trash tool output
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/trash.py
Modified: CalendarServer/trunk/calendarserver/tools/trash.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/trash.py 2015-03-12 23:27:10 UTC (rev 14584)
+++ CalendarServer/trunk/calendarserver/tools/trash.py 2015-03-13 02:18:06 UTC (rev 14585)
@@ -119,25 +119,30 @@
print("No trashed collections for:", prettyRecord(record))
returnValue(None)
- print("Listing trashed collections for:", prettyRecord(record))
+ print("Trashed collections for:", prettyRecord(record))
+
+ nowDT = datetime.datetime.utcnow()
+
for collection in trashedCollections:
displayName = displayNameForCollection(collection)
+ whenTrashed = collection.whenTrashed()
+ ago = nowDT - whenTrashed
+ print()
+ print(" Trashed {}:".format(agoString(ago)))
print(
- "Collection = \"{}\", trashed = {}, id = {}".format(
- displayName.encode("utf-8"), collection.whenTrashed(),
- collection._resourceID
+ " \"{}\" (collection) Recovery ID = {}".format(
+ displayName.encode("utf-8"), collection._resourceID
)
)
- startTime = collection.whenTrashed() - datetime.timedelta(minutes=5)
+ startTime = whenTrashed - datetime.timedelta(minutes=5)
children = yield trash.trashForCollection(
collection._resourceID, start=startTime
)
- print(" ...containing events:")
+ print(" ...containing events:")
for child in children:
component = yield child.component()
summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
- whenTrashed = yield child.whenTrashed()
- print(" \"{}\", trashed = {}".format(summary.encode("utf-8"), whenTrashed))
+ print(" \"{}\"".format(summary.encode("utf-8")))
yield store.inTransaction(label="List trashed collections", operation=doIt)
@@ -175,6 +180,58 @@
@inlineCallbacks
+def printEventDetails(event):
+ nowPyDT = DateTime.getNowUTC()
+ nowDT = datetime.datetime.utcnow()
+ oneYearInFuture = DateTime.getNowUTC()
+ oneYearInFuture.offsetDay(365)
+
+ component = yield event.component()
+ mainSummary = component.mainComponent().propertyValue("SUMMARY", u"<no title>")
+ whenTrashed = yield event.whenTrashed()
+ ago = nowDT - whenTrashed
+ print(" Trashed {}:".format(agoString(ago)))
+
+ if component.isRecurring():
+ print(
+ " \"{}\" (repeating) Recovery ID = {}".format(
+ mainSummary, event._resourceID
+ )
+ )
+ print(" ...upcoming instances:")
+ instances = component.cacheExpandedTimeRanges(oneYearInFuture)
+ instances = sorted(instances.instances.values(), key=lambda x: x.start)
+ limit = 3
+ count = 0
+ for instance in instances:
+ if instance.start >= nowPyDT:
+ summary = instance.component.propertyValue("SUMMARY", u"<no title>")
+ location = locationString(instance.component)
+ tzid = instance.component.getProperty("DTSTART").parameterValue("TZID", None)
+ dtstart = instance.start
+ if tzid is not None:
+ timezone = Timezone(tzid=tzid)
+ dtstart.adjustTimezone(timezone)
+ print(" \"{}\" {} {}".format(summary, startString(dtstart), location))
+ count += 1
+ limit -= 1
+ if limit == 0:
+ break
+ if not count:
+ print(" (none)")
+
+ else:
+ print(
+ " \"{}\" (non-repeating) Recovery ID = {}".format(
+ mainSummary, event._resourceID
+ )
+ )
+ dtstart = component.mainComponent().propertyValue("DTSTART")
+ location = locationString(component.mainComponent())
+ print(" {} {}".format(startString(dtstart), location))
+
+
+ at inlineCallbacks
def listTrashedEventsForPrincipal(service, store, principalUID):
directory = store.directoryService()
record = yield directory.recordWithUID(principalUID)
@@ -200,13 +257,7 @@
print("No untrashed collections for:", prettyRecord(record))
returnValue(None)
- oneYearInFuture = DateTime.getNowUTC()
- oneYearInFuture.offsetDay(365)
- nowPyDT = DateTime.getNowUTC()
-
- nowDT = datetime.datetime.utcnow()
-
for collection in untrashedCollections:
displayName = displayNameForCollection(collection)
children = yield trash.trashForCollection(collection._resourceID)
@@ -216,52 +267,9 @@
print("Trashed events in calendar \"{}\":".format(displayName.encode("utf-8")))
for child in children:
print()
- component = yield child.component()
+ yield printEventDetails(child)
+ print()
- mainSummary = component.mainComponent().propertyValue("SUMMARY", u"<no title>")
- whenTrashed = yield child.whenTrashed()
- ago = nowDT - whenTrashed
- print(" Trashed {}:".format(agoString(ago)))
-
- if component.isRecurring():
- print(
- " \"{}\" (repeating) Recovery ID = {}".format(
- mainSummary, child._resourceID
- )
- )
- print(" ...upcoming instances:")
- instances = component.cacheExpandedTimeRanges(oneYearInFuture)
- instances = sorted(instances.instances.values(), key=lambda x: x.start)
- limit = 3
- count = 0
- for instance in instances:
- if instance.start >= nowPyDT:
- summary = instance.component.propertyValue("SUMMARY", u"<no title>")
- location = locationString(instance.component)
- tzid = instance.component.getProperty("DTSTART").parameterValue("TZID", None)
- dtstart = instance.start
- if tzid is not None:
- timezone = Timezone(tzid=tzid)
- dtstart.adjustTimezone(timezone)
- print(" \"{}\" {} {}".format(summary, startString(dtstart), location))
- count += 1
- limit -= 1
- if limit == 0:
- break
- if not count:
- print(" (none)")
-
- else:
- print(
- " \"{}\" (non-repeating) Recovery ID = {}".format(
- mainSummary, child._resourceID
- )
- )
- dtstart = component.mainComponent().propertyValue("DTSTART")
- location = locationString(component.mainComponent())
- print(" {} {}".format(startString(dtstart), location))
-
-
yield store.inTransaction(label="List trashed events", operation=doIt)
@@ -370,19 +378,14 @@
continue
if verbose:
- print("Collection = \"{}\"".format(displayName.encode("utf-8")))
+ print("Collection \"{}\":".format(displayName.encode("utf-8")))
for child in children:
component = yield child.component()
summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
- whenTrashed = yield child.whenTrashed()
if verbose:
- print(
- " \"{}\", trashed = {}, id = {}".format(
- summary.encode("utf-8"), whenTrashed, child._resourceID
- )
- )
- print("Removing...")
+ print(" Removing \"{}\"...".format(summary))
yield child.reallyRemove()
+ print()
if txn is None:
yield store.inTransaction(label="Empty trash", operation=doIt)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150312/4d9f9ae1/attachment.html>
More information about the calendarserver-changes
mailing list