babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
rm_zombies.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import argparse
4 import os
5 import glob
6 
7 import ROOT
8 
9 import utilities
10 
11 def killZombies(in_dirs):
12  in_dirs = [ utilities.fullPath(d) for sublist in in_dirs for d in glob.glob(sublist) ]
13  ROOT.gErrorIgnoreLevel = 6000
14  for d in in_dirs:
15  for root, dirs, files in os.walk(d):
16  print "In "+root
17  for f in files:
18  path = os.path.join(root, f)
19  if os.path.splitext(f)[1] != ".root":
20  continue
21  tfile = ROOT.TFile(path, "read")
22  kill = tfile.IsZombie() or not tfile.IsOpen()
23  tfile.Close()
24  if kill:
25  print "Removing "+path
26  os.remove(path)
27 
28 if __name__ == "__main__":
29  parser = argparse.ArgumentParser(description="Recursively removes zombie ROOT files from given directories.",
30  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
31  parser.add_argument("in_dirs", nargs="*", default=["."],
32  help="List of directories from which to purge zombie files.")
33  args = parser.parse_args()
34 
35  killZombies(args.in_dirs)
def killZombies(in_dirs)
Definition: rm_zombies.py:11
def fullPath(path)
Definition: utilities.py:34