Ejemplo n.º 1
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
         if header.to_lower(s['name']) in files:
            restore.append(s)
         else:
            junk.append(s)
      header.write_trash(junk,mode='w')
Ejemplo n.º 2
0
      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')
      print "Emptying the trash...",
      for s in filelist:
         errorflag = 0 # set to 1 if there is a problem deleting a file/folder
         filename = os.path.join(s['trash_path'],s['name'])
         if os.path.isdir(filename): # is a directory
            for root, dirs, files in os.walk(filename, topdown=False):
               try:
                  for name in files:
                     os.remove(os.path.join(root,name))
                  for name in dirs:
                     os.rmdir(os.path.join(root,name))