[CalendarServer-changes] [14484] CalendarServer/branches/users/sagen/trashcan-5
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 27 12:43:09 PST 2015
Revision: 14484
http://trac.calendarserver.org//changeset/14484
Author: sagen at apple.com
Date: 2015-02-27 12:43:08 -0800 (Fri, 27 Feb 2015)
Log Message:
-----------
Adds basic trash restore cmd line tool; fix problem where trash revision was not properly deleted.
Modified Paths:
--------------
CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/sql.py
Added Paths:
-----------
CalendarServer/branches/users/sagen/trashcan-5/calendarserver/tools/trash.py
Added: CalendarServer/branches/users/sagen/trashcan-5/calendarserver/tools/trash.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan-5/calendarserver/tools/trash.py (rev 0)
+++ CalendarServer/branches/users/sagen/trashcan-5/calendarserver/tools/trash.py 2015-02-27 20:43:08 UTC (rev 14484)
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+# -*- test-case-name: calendarserver.tools.test.test_trash -*-
+##
+# Copyright (c) 2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+from __future__ import print_function
+
+import collections
+import datetime
+from getopt import getopt, GetoptError
+import os
+import sys
+
+from calendarserver.tools import tables
+from calendarserver.tools.cmdline import utilityMain, WorkerService
+
+from pycalendar.datetime import DateTime
+
+from twext.enterprise.dal.record import fromTable
+from twext.enterprise.dal.syntax import Delete, Select, Union
+from twext.enterprise.jobqueue import WorkItem, RegeneratingWorkItem
+from twext.python.log import Logger
+
+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
+
+from twistedcaldav import caldavxml
+from twistedcaldav.config import config
+
+from txdav.caldav.datastore.query.filter import Filter
+from txdav.common.datastore.sql_tables import schema, _HOME_STATUS_NORMAL
+from txdav.caldav.datastore.sql import CalendarStoreFeatures
+
+from argparse import ArgumentParser
+
+
+log = Logger()
+
+
+
+class TrashRestorationService(WorkerService):
+
+ principals = []
+
+ def doWork(self):
+ rootResource = self.rootResource()
+ directory = rootResource.getDirectory()
+ return restoreFromTrash(
+ self.store, directory, rootResource, self.principals
+ )
+
+
+
+def main():
+
+ parser = ArgumentParser(description='Restore events from trash')
+ parser.add_argument('-f', '--config', dest='configFileName', metavar='CONFIGFILE', help='caldavd.plist configuration file path')
+ parser.add_argument('-d', '--debug', action='store_true', help='show debug logging')
+ parser.add_argument('principal', help='one or more principals to restore', nargs='+') # Required
+ args = parser.parse_args()
+
+ TrashRestorationService.principals = args.principal
+
+ utilityMain(
+ args.configFileName,
+ TrashRestorationService,
+ verbose=args.debug,
+ )
+
+
+
+ at inlineCallbacks
+def restoreFromTrash(store, directory, root, principals):
+
+ for principalUID in principals:
+ txn = store.newTransaction(label="Restore trashed events")
+ home = yield txn.calendarHomeWithUID(principalUID)
+ if home is None:
+ continue
+ trash = yield home.childWithName("trash")
+ names = yield trash.listObjectResources()
+ for name in names:
+ cobj = yield trash.calendarObjectWithName(name)
+ print(name, cobj)
+
+ if cobj is not None:
+ # If it's still in the trash, restore it from trash
+ if (yield cobj.isTrash()):
+ print("Restoring:", name)
+ yield cobj.fromTrash()
+
+ yield txn.commit()
+
+
+if __name__ == "__main__":
+ main()
Property changes on: CalendarServer/branches/users/sagen/trashcan-5/calendarserver/tools/trash.py
___________________________________________________________________
Added: svn:executable
+ *
Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/sql.py 2015-02-27 20:14:58 UTC (rev 14483)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/sql.py 2015-02-27 20:43:08 UTC (rev 14484)
@@ -7533,23 +7533,21 @@
# The parent is indeed the trash collection
trash = self._parentCollection
self._parentCollection = yield trash.originalParentForResource(self)
+ trashedName = self._name # for deleting trash revision below
_ignore, newName = trash.parseName(self._name)
else:
# The parent is the original collection because it was retrieved
# via that parent, not the trash collection
home = self._parentCollection.viewerHome()
trash = yield home.childWithName("trash")
+ trashedName = trash.nameForResource(self._parentCollection, self)
newName = self._name
yield self._updateIsTrashQuery.on(
self._txn, isTrash=False, trashed=None, resourceID=self._resourceID
)
- yield trash._deleteRevision(
- trash.nameForResource(
- self._parentCollection,
- self
- )
- )
+ yield trash._deleteRevision(trashedName)
+
self._name = newName
yield self._parentCollection.addedObjectResource(self)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150227/93d7165a/attachment.html>
More information about the calendarserver-changes
mailing list