rm-blacklist

Python wrapper for POSIX rm that checks every argument against a blacklist.
git clone git://git.stephanospavlou.info/rm-blacklist.git
Log | Files | Refs | README | LICENSE

blacklist.py (1097B)


      1 #!/usr/bin/env python
      2 import os
      3 import sys
      4 
      5 blacklistPath = '.blklst' # SET ME!
      6 
      7 usage = '''Usage: blacklist [options] <file | directory> <file | directory> ...
      8 Options:
      9 \t-h, --help\tdisplay this help and exit
     10 \t-r        \tblacklist directory/directories recursively'''
     11 
     12 if len(sys.argv) == 1 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
     13     print(usage)
     14     sys.exit()
     15 
     16 if sys.argv[1] == '-r':
     17     recursiveMode = True
     18     filesToBlacklist = sys.argv[2:]
     19 else:
     20     recursiveMode = False
     21     filesToBlacklist = sys.argv[1:]
     22 
     23 with open(blacklistPath, 'a') as blacklist:
     24     for file in filesToBlacklist:
     25         blacklist.write('\n' + os.path.abspath(file))
     26         if recursiveMode == True:
     27             for dirPath, dirNames, fileNames in os.walk(file, followlinks=True):
     28                 for dirName in dirNames:
     29                     blacklist.write("\n" +
     30                         os.path.abspath(os.path.join(dirPath, dirName)))
     31                 for fileName in fileNames:
     32                     blacklist.write("\n" +
     33                         os.path.abspath(os.path.join(dirPath, fileName)))