jslint
[Portfolio.git] / _zctl / updateDateTimeOriginal.py
1 # -*- coding: utf-8 -*-
2 from argparse import ArgumentParser
3 import os
4 from AccessControl import getSecurityManager
5 from Testing.makerequest import makerequest
6 from zope.globalrequest import setRequest
7 from zope.site.hooks import setSite
8 from ZODB.POSException import ConflictError
9 import transaction
10
11 def main(app, portal_path, userid) :
12 portal = app.unrestrictedTraverse(portal_path)
13 portal = makerequest(portal)
14 setRequest(portal.REQUEST)
15 setSite(portal)
16 user = portal.acl_users.getUser(userid)
17 sm = getSecurityManager()
18 sm._context.user = user
19 ctool = portal.portal_catalog
20 brains = ctool.unrestrictedSearchResults(portal_type='Photo', tiles_available=1)
21
22 for i, brain in enumerate(brains) :
23 photo = brain.getObject()
24 print photo.absolute_url()
25 if photo._methodResultsCache.has_key('DateTimeOriginal') :
26 del photo._methodResultsCache['DateTimeOriginal']
27 photo.reindexObject(idxs=['DateTimeOriginal'])
28 if i and i % 100 == 0 :
29 transaction.commit()
30 transaction.commit()
31 print 'Done.'
32
33
34 if __name__ == '__main__':
35 parser = ArgumentParser(description="Update DateTimeOriginal index")
36 parser.add_argument('portal_path', help='portal object path')
37 parser.add_argument('userid', help='zope user id')
38 args = parser.parse_args()
39 main(app,
40 args.portal_path,
41 args.userid)