outlist = [] trashnames = [s['name'] for s in data] # get list of names for f in files: junk = fnmatch.filter(trashnames,header.to_lower(f.strip('/'))) if len(junk) == 0: print "### Warning! File '%s' not in trash. Skipping." %f else: outlist = outlist + junk return set(outlist) # convert to set to make unique list of names if __name__ == "__main__": if '-h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: print __doc__ sys.exit() data = header.read_trash() header.make_trash_backup() if len(data) == 0: print "The trash is empty." header.remove_trash_backup() sys.exit() restore = [] if len(sys.argv) == 1: # undelete last file restore.append(data[-1]) header.write_trash(data[:-1],mode='w') else: files = expand_glob(sys.argv[1:],data) junk = [] for s in data: # loop over deleted file names
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