From: Benoît Pin Date: Sat, 28 Jun 2014 15:44:08 +0000 (+0200) Subject: Ajout utilitaire pour mettre à jour les dates de prise de vues (nécessaire suite... X-Git-Url: https://scm.cri.ensmp.fr/git/Portfolio.git/commitdiff_plain/afd6dda3d1889df6ac322a9175efc80564fd2a8c?ds=inline;hp=74ee75fa9915771af5c9585cc8adbdf52877496a Ajout utilitaire pour mettre à jour les dates de prise de vues (nécessaire suite aux évolutions de xmp / LR4-5) --- diff --git a/_zctl/updateDateTimeOriginal.py b/_zctl/updateDateTimeOriginal.py new file mode 100644 index 0000000..5e73cb8 --- /dev/null +++ b/_zctl/updateDateTimeOriginal.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +from argparse import ArgumentParser +import os +from AccessControl import getSecurityManager +from Testing.makerequest import makerequest +from zope.globalrequest import setRequest +from zope.site.hooks import setSite +from ZODB.POSException import ConflictError +import transaction + +def main(app, portal_path, userid) : + portal = app.unrestrictedTraverse(portal_path) + portal = makerequest(portal) + setRequest(portal.REQUEST) + setSite(portal) + user = portal.acl_users.getUser(userid) + sm = getSecurityManager() + sm._context.user = user + ctool = portal.portal_catalog + brains = ctool.unrestrictedSearchResults(portal_type='Photo', tiles_available=1) + + for i, brain in enumerate(brains) : + photo = brain.getObject() + print photo.absolute_url() + if photo._methodResultsCache.has_key('DateTimeOriginal') : + del photo._methodResultsCache['DateTimeOriginal'] + photo.reindexObject(idxs=['DateTimeOriginal']) + if i and i % 100 == 0 : + transaction.commit() + transaction.commit() + print 'Done.' + + +if __name__ == '__main__': + parser = ArgumentParser(description="Update DateTimeOriginal index") + parser.add_argument('portal_path', help='portal object path') + parser.add_argument('userid', help='zope user id') + args = parser.parse_args() + main(app, + args.portal_path, + args.userid) \ No newline at end of file