def get_free_space(): """Returns free space on current disk""" junk = os.statvfs(os.getcwd()) free = junk[1] * junk[4] # space in bytes available for non-root size,unit = header.get_sizeunits(free) return '%.1f %s' %(size,unit)
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) #print "~"*(maxname+maxdate+13) for s,newdate in zip(data,junkdate): total += float(s['size']) size,unit = header.get_sizeunits(float(s['size'])) size = '%6.1f' %size # convert to string if size[-1] == '0': # chop off decimal point if is a whole number size = size[:-2] junk = "%s %6s %2s %s" %(s['name'].ljust(maxname),size,unit, newdate.rjust(maxdate)) if options.longList: junk = junk + " %s" %(s['org_path']) print junk size,unit = header.get_sizeunits(total) #print "~"*(maxname+maxdate+13) if len(data) == 1: print "### %d item, %.2f %s used" %(len(data),size,unit) else: print "### %d items, %.2f %s used" %(len(data),size,unit)
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
print "### Fatal Error! Cannot understand number of days: %s" %sys.argv[1] sys.exit() data = header.read_trash() header.make_trash_backup() filelist = [] for s in data: if s['date'].lower() == 'unknown' or checkdate(s['date'],old_delete): size = size + int(s['size']) filelist.append(s) else: newtrashdata.append(s) # Convert size to units size,unit = header.get_sizeunits(size) if len(filelist) == 1: print "There is 1 item older than %d days, using %4.2f %s" \ %(old_delete,size,unit) choice = raw_input('Do you wish to delete it (y/n)? ') elif len(filelist) > 1: print "There are %d items older than %d days, using %4.2f %s" \ %(len(filelist),old_delete,size,unit) choice = raw_input('Do you wish to delete them (y/n)? ' ) else: print "There are no items in the trash older than %d days." %old_delete header.remove_trash_backup() sys.exit() if choice.lower() in ["y","yes"]: if len(filelist) > 0: header.write_trash(newtrashdata,'w')