a6f5596d791e4099eb0e36bc2b0851241a01f694
1 # -*- coding: utf-8 -*-
2 from argparse
import ArgumentParser
3 from AccessControl
import getSecurityManager
4 from Testing
.makerequest
import makerequest
5 from zope
.globalrequest
import setRequest
6 from zope
.site
.hooks
import setSite
7 from ZODB
.POSException
import ConflictError
8 from Products
.Photo
.cache
import aggregateIndex
11 GET_RI_SIGNATURE
= (('size', 1), ('keepAspectRatio', 2))
14 def main(app
, portal_path
, userid
) :
15 portal
= app
.unrestrictedTraverse(portal_path
)
16 portal
= makerequest(portal
)
17 setRequest(portal
.REQUEST
)
19 user
= portal
.acl_users
.getUser(userid
)
20 sm
= getSecurityManager()
21 sm
._context
.user
= user
23 thumb_size
= portal
.thumb_size
25 ctool
= portal
.portal_catalog
26 brains
= ctool
.unrestrictedSearchResults(portal_type
='Photo', tiles_available
=1)
30 for i
, b
in enumerate(brains
) :
32 p
= b
._unrestrictedGetObject
()
34 print '%d/%d: %s' % (i
+1, len(brains
), p
.absolute_url())
37 if hasattr(p
, 'thumbnail'):
38 print 'make thumbnail'
39 delattr(p
, 'thumbnail')
40 p
.thumb_width
= thumb_size
41 p
.thumb_height
= thumb_size
45 for size
in ((500, 500), (600, 600), (800, 800)) :
46 index
= aggregateIndex(GET_RI_SIGNATURE
, (size
, True))
47 if p
._methodResultsCache
['_getResizedImage'].has_key(index
) :
48 del p
._methodResultsCache
['_getResizedImage'][index
]
49 print 'resize at', size
50 p
._getResizedImage
(size
, True)
53 zMin
= p
.tiles_min_zoom
54 zMax
= p
.tiles_max_zoom
55 zStep
= p
.tiles_step_zoom
56 levels
= range(zMin
, zMax
+ zStep
, zStep
)
57 zooms
= [l
/100. for l
in levels
]
59 if p
.tileGenerationLock
.locked() :
60 print 'skip %s: already tiling.' % p
.absolute_url()
63 p
.tileGenerationLock
.acquire()
68 print 'tiling at', zoom
70 rppm
= ppm
.resize(ratio
=zoom
)
73 p
._makeTilesAt
(zoom
, rppm
)
78 except UnboundLocalError : pass
79 p
.tileGenerationLock
.release()
82 delattr(p
, '_v__methodResultsCache')
83 except AttributeError:
86 # _skipDict[path] = True
87 # skipFile.write('%s\n' % path)
89 except ConflictError
:
90 print 'Resync after ZODB ConflicError'
93 brains
= ctool
.unrestrictedSearchResults(portal_type
='Photo', tiles_available
=1)
94 # brains = [b for b in brains if not toSkip(b.getPath())]
97 except KeyboardInterrupt:
100 p
.tiles_available
= 1
102 p
.reindexObject(idxs
=['tiles_available'])
105 print 'queue finished.'
109 print 'Objects deleted during processing'
111 brains
= ctool
.unrestrictedSearchResults(portal_type
='Photo', tiles_available
=1)
112 # brains = [b for b in brains if not toSkip(b.getPath())]
114 except ConflictError
:
115 print 'Resync after ZODB ConflicError'
118 brains
= ctool
.unrestrictedSearchResults(portal_type
='Photo', tiles_available
=1)
119 # brains = [b for b in brains if not toSkip(b.getPath())]
121 except KeyboardInterrupt:
128 if __name__
== '__main__':
129 parser
= ArgumentParser(description
="Thumbnails regeneration")
130 parser
.add_argument('portal_path', help='portal object path')
131 parser
.add_argument('userid', help='zope user id')
132 args
= parser
.parse_args()
133 portal_path
, userid
= args
.portal_path
, args
.userid
134 main(app
, portal_path
, userid
)