# -*- coding: utf-8 -*-
from argparse import ArgumentParser
+import os
from AccessControl import getSecurityManager
from Testing.makerequest import makerequest
from zope.globalrequest import setRequest
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)
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 :
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:
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()
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