def getinfo(docs): """Fill up a list of info structures about each file in docs and return this list""" global info infolist=[] for fname in docs: meridian='am' tempinfo=info.copy() temp = os.path.split(fname) tempinfo['Name']=temp[1] tempinfo['Location']=temp[0] if not os.path.exists(fname): tempinfo['Kind']="Non-Existent File" else: # Find file size size,unit = header.get_sizeunits(os.path.getsize(fname)) tempinfo['Size'] = "%4.2f" %size tempinfo['Units'] = unit # Get time and convert to proper AM/PM format junk = header.get_time(time.ctime(os.path.getmtime(fname))) tempinfo['Modified']="%s:%s:%s %s %s %2s, %s" %(junk["hour"], junk["min"],junk["sec"],junk["meridian"],junk["month"], junk["date"],junk["year"]) # Fill in permissions data=commands.getoutput('ls -ld "%s"' %fname).split() tempinfo['Owner']="%s (owner: %s)" %(data[0][1:4],data[2]) tempinfo['Group']="%s (group: %s)" %(data[0][4:7],data[3]) tempinfo['World']="%s (world)" %data[0][7:10] # Find Kind and More info description=commands.getoutput('file -b "%s"' %fname) # If directory, count number of items instead of byte size if description=="directory": temp=int(commands.getoutput('ls -l "%s"|wc -l' %fname))-1 tempinfo['Size']="%d" %temp if temp == 1: tempinfo['Units'] = "item" else: tempinfo['Units']="items" tempinfo['Kind']="Folder" else: # Separate description into kind and more info temp="" i=0 while (i<len(description) and description[i]!=","): temp=temp+description[i] i=i+1 i=i+1 #increment past comma if i<len(description): if description[i]==" ": i=i+1 tempinfo['MoreInfo']=description[i:] tempinfo['Kind']=temp temp = os.path.abspath(fname) r1=re.compile(TRASHDIR) if r1.match(temp): data = header.read_trash() tempinfo['Original'] = 'Unknown' tempinfo['Date_Deleted'] = 'Unknown' for s in data: if s['name'] == tempinfo['Name']: tempinfo['Original'] = s['org_path'] tempinfo['Date_Deleted'] = s['date'] break infolist.append(tempinfo) return infolist
else: print "### Warning! Cannot find the files %s. Skipping." \ %(','.join(args)) if len(tmp) > 0: data = tmp else: raise SystemExit if options.sortType == 2: data.sort(cmdSortName) elif options.sortType == 1: data.sort(cmdSortSize) elif options.sortType == 0: data.sort(cmdSortTime) currenttime = header.get_time(time.asctime()) # get maximum lengths of names, sizes, and dates for pretty formatting maxname = max([len(a['name']) for a in data]) maxsize = max([len(a['size']) for a in data]) junkdate = [] maxdate = 0 for s in data: newdate = getRelativeDate(currenttime,header.get_time(s['date'])) if len(newdate) > maxdate: maxdate = len(newdate) junkdate.append(newdate) # print trash total = 0 # size of trash printHeader(maxname,maxdate)