FrontPage
»
WebLog
»
du
## Script (Python) "du" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=folder=None,size=0,final=1,details='',errors='',counter=0 ##title= ## # This script is like folder_contents but with size and Creator thrown in # if you add ?details=1 otherwise it returns # the size of the object recursively going into sub-objects # (c)2002 Bruno Vernier GPL version 0.2 - improvements warmly accepted # this should be redone as a ZPT if not folder: folder=context allitems=folder.objectItems() try: allitems.sort() except: pass for id2,item in allitems: size2 = 0; creator=''; metatype='' id3="""<a href="%s">%s</a>"""%(id2,id2) if hasattr(item, 'get_size'): try: size2 = int(item.get_size()) except StandardError,msg: errors = errors + "<tr><th>%s</th><td>%s</td>"%(id2,msg) if size2: size = size + size2 counter = counter + 1; creator="N/C"; icon="" if details and size2>int(details) : try: creator = context[id2].Creator() except: creator = "" try: metatype = context[id2].meta_type except: metatype ="..." creator = "<i>%s</i> %s"%(creator,metatype) creator = """<a href="%s/manage_workspace">%s</a> %s"""%(id2,creator,icon2) errors = errors + """ <tr><th align=left>%s</th><td align=right>%s</td><td>\n%s<!--%s--></td></tr> """%(id3,size2,creator,size) else: try: size2 = context.du(folder=item,size=0,final=0) if size2: size = size + size2 if details and size2>int(details) : errors = errors + """ <tr><th align=left>%s</th><td align=right>%s</td><td> <a href=%s/du?details=1>folder</a><!--%s--></td></tr>"""%(id2,size2,id2,size) except StandardError,msg: errors = errors + "<li>%s with <i><a href=%s/manage>%s</a></i>"%(msg,id2,id2) if final: return """%s<td align=left width=66%%><table width=100%% border><tr><th>Total %s objects</th> <th align=right>%s</th><th>%s Megs</th></tr>%s</table></td> %s"""%(context.standard_html_header(context,context.REQUEST),int(size),counter, int(float(size/1000000.0)*100)/100.0,errors, context.standard_html_footer(context,context.REQUEST)) else: return size