Working With Repository
While working on reports, I had several questions about accessing historical information about items in repository. Below is the summary of some answers that I have received on the developer lists, and from Andi and that worked for me. For the original questions and answers in the mailing lists, see:
http://lists.osafoundation.org/pipermail/chandler-dev/2007-June/008413.html
http://lists.osafoundation.org/pipermail/chandler-dev/2007-June/008414.html
http://lists.osafoundation.org/pipermail/chandler-dev/2007-July/008552.html
http://lists.osafoundation.org/pipermail/chandler-dev/2007-July/008572.html
http://lists.osafoundation.org/pipermail/chandler-dev/2007-July/008575.html
http://lists.osafoundation.org/pipermail/chandler-dev/2007-July/008553.html
Chandler headless
Command-Line Options
headless accepts most of the same command-line optoins as
Chandler.py. For a current list, type
./release/RunPython tools/headless.py --help
Running scripts non-interactively
If you pass in a python script via the
--scriptFile command-line option,
headless will execute the script
and terminate. The same globals and functions as in the interactive version are available to your script: Type
readme() in
headless for a list.
Chandler headless examples
Debug info for collections in the sidebar
./release/RunPython tools/headless.py
sb = schema.ns('osaf.app', view).sidebarCollection
view.repository.printItemVersions(sb)
view.printItemChanges(sb)
view.printItemVersions(sb)
Accessing deleted items
- deleted items do not exist in the user interface of chandler, but their uuids are stored in previous versions in the repository
- to play with deleted items in headless:
ac = schema.ns('osaf.pim', view).allCollection
list(ac)
item = list(ac)[0]
uuid = item.itsUUID
item.delete(True)
view.commit()
view.findUUID(uuid)
Deleted Items
- deleted items are dead items and it is impossible to access them in the recent view, or use them.
- it is possible to get a dictionary with the values associated with a deleted item or values associated with previous versions of existing items (not deleted).
- it is also possible to get some of the references associated with old items.
- to retrieve values for items that were deleted from a collection in the previous version in the code:
def getDeletedItems(collection):
# create a new view, to be able to access its previous versions
newView = items.itsView.repository.createView()
existingItems = [item.itsUUID for item in collection]
deletedItems = []
# go to the previous version of the view
if newView.itsVersion > 1:
newView.itsVersion -= 1
previousCollection = newView.findUUID(collection.itsUUID)
if previousCollection is not None:
for item in previousCollection:
if not item.itsUUID in existingItems:
values = {}
values.update(item.itsValues)
refs = {}
values.update(item.itsRefs)
deletedItems.append((values,refs))
return deletedItems
Timestamp a repository version
- each version has the timestamp of when it was commited to repository
- it can be retrieved:
def getTimestampForView(view):
store = view.store
timestamp, viewSize, commitCount, name = store.getCommit(view.itsVersion)
return timestamp
--
VeraSheinman - 09 Aug 2007