From 8a525218303715fcf1b977a459947b5b899d9640 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Wed, 2 Apr 2014 10:22:14 +0200 Subject: [PATCH 1/1] =?utf8?q?Ajout=20de=20l'argument=20=C2=AB=C2=A0skipfi?= =?utf8?q?le=C2=A0=C2=BB=20qui=20permet=20de=20marquer=20de=20mani=C3=A8re?= =?utf8?q?=20externe=20les=20=C3=A9l=C3=A9ments=20d=C3=A9j=C3=A0=20trait?= =?utf8?q?=C3=A9s=20(pour=20ne=20pas=20avoir=20=C3=A0=20les=20reg=C3=A9n?= =?utf8?q?=C3=A9rer=20si=20plantage=20intempestif).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- _zctl/regenPhotos.py | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/_zctl/regenPhotos.py b/_zctl/regenPhotos.py index a6f5596..2dcf8f5 100644 --- a/_zctl/regenPhotos.py +++ b/_zctl/regenPhotos.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from argparse import ArgumentParser +import os from AccessControl import getSecurityManager from Testing.makerequest import makerequest from zope.globalrequest import setRequest @@ -11,7 +12,7 @@ import transaction GET_RI_SIGNATURE = (('size', 1), ('keepAspectRatio', 2)) -def main(app, portal_path, userid) : +def main(app, portal_path, userid, skipfile) : portal = app.unrestrictedTraverse(portal_path) portal = makerequest(portal) setRequest(portal.REQUEST) @@ -20,10 +21,23 @@ def main(app, portal_path, userid) : sm = getSecurityManager() sm._context.user = user - thumb_size = portal.thumb_size + absSkipFilePath = os.path.abspath(os.path.expanduser(skipfile)) + if os.path.exists(absSkipFilePath) : + skipFile = open(absSkipFilePath, 'r+') + skip = filter(None, skipFile.readlines()) + _skipDict = dict([(path.strip(), True) for path in skip]) + del skip + else : + skipFile = open(absSkipFilePath, 'w') + _skipDict = {} + + toSkip = _skipDict.has_key + + thumb_size = portal.thumb_size ctool = portal.portal_catalog brains = ctool.unrestrictedSearchResults(portal_type='Photo', tiles_available=1) + brains = [b for b in brains if not toSkip(b.getPath())] while brains : try : @@ -83,15 +97,15 @@ def main(app, portal_path, userid) : except AttributeError: pass - # _skipDict[path] = True - # skipFile.write('%s\n' % path) + _skipDict[path] = True + skipFile.write('%s\n' % path) except ConflictError : print 'Resync after ZODB ConflicError' transaction.abort() portal._p_jar.sync() brains = ctool.unrestrictedSearchResults(portal_type='Photo', tiles_available=1) - # brains = [b for b in brains if not toSkip(b.getPath())] + brains = [b for b in brains if not toSkip(b.getPath())] break except KeyboardInterrupt: @@ -109,19 +123,19 @@ def main(app, portal_path, userid) : print 'Objects deleted during processing' portal._p_jar.sync() brains = ctool.unrestrictedSearchResults(portal_type='Photo', tiles_available=1) - # brains = [b for b in brains if not toSkip(b.getPath())] + brains = [b for b in brains if not toSkip(b.getPath())] except ConflictError : print 'Resync after ZODB ConflicError' transaction.abort() portal._p_jar.sync() brains = ctool.unrestrictedSearchResults(portal_type='Photo', tiles_available=1) - # brains = [b for b in brains if not toSkip(b.getPath())] + brains = [b for b in brains if not toSkip(b.getPath())] except KeyboardInterrupt: - # skipFile.close() break - + + skipFile.close() @@ -129,6 +143,13 @@ if __name__ == '__main__': parser = ArgumentParser(description="Thumbnails regeneration") parser.add_argument('portal_path', help='portal object path') parser.add_argument('userid', help='zope user id') + parser.add_argument('--skipfile', + type=str, + required=False, + default='skipfile.txt', + help="File that log work's progress.") args = parser.parse_args() - portal_path, userid = args.portal_path, args.userid - main(app, portal_path, userid) \ No newline at end of file + main(app, + args.portal_path, + args.userid, + args.skipfile) \ No newline at end of file -- 2.20.1