-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtar_reader.py
More file actions
executable file
·46 lines (36 loc) · 1.09 KB
/
tar_reader.py
File metadata and controls
executable file
·46 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import argparse
import tarfile
import time
class NotValidArchive(Exception):
pass
class TarReader(object):
def __init__(self, arch):
self.arch = arch
def peek(self):
try:
if tarfile.is_tarfile(self.arch):
files = tarfile.open(self.arch, "r")
for f in files.getmembers():
print "{} {}".format(time.ctime(f.mtime), f.name)
files.close()
else:
raise NotValidArchive(self.arch + " is not valid archive")
except IOError:
raise NotValidArchive(self.arch + " is not valid archive")
def main():
parser = argparse.ArgumentParser(
description="Read contents of an archive"
)
parser.add_argument(
"archive_name",
help="the name of file archive to be inspected"
)
args = parser.parse_args()
reader = TarReader(args.archive_name)
try:
reader.peek()
except NotValidArchive:
print "{} is not a valid archive".format(args.archive_name)
if __name__ == "__main__":
main()