5 from .errors import FileTypeError
11 '7z': ["7z", "e", "-so"],
15 A map from file extension to the command to run to extract the data to standard out.
18 EXT_RE = re.compile(r'\.([^\.]+)$')
20 A regular expression for extracting the final extension of a file.
26 Verifies that a file exists at a given path and that the file has a
31 the path to a dump file
34 if hasattr(path_or_f, "readline"):
39 path = os.path.expanduser(path)
40 if not os.path.isfile(path):
41 raise FileTypeError("Can't find file %s" % path)
43 match = EXT_RE.search(path)
45 raise FileTypeError("No extension found for %s." % path)
46 elif match.groups()[0] not in EXTENSIONS:
47 raise FileTypeError("File type %r is not supported." % path)
52 def open_file(path_or_f):
54 Turns a path to a dump file into a file-like object of (decompressed)
59 the path to the dump file to read
61 if hasattr(path_or_f, "read"):
66 match = EXT_RE.search(path)
67 ext = match.groups()[0]
69 EXTENSIONS[ext] + [path],
70 stdout=subprocess.PIPE,
71 stderr=open(os.devnull, "w")
73 # sys.stderr.write("\n%s %s\n" % (EXTENSIONS[ext], path))
74 # sys.stderr.write(p.stdout.read(1000))