summaryrefslogtreecommitdiff
path: root/tools/indexcap.py
diff options
context:
space:
mode:
authorKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>2009-09-25 15:41:17 +0000
committerKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>2009-09-25 15:41:17 +0000
commit50b7a98610acb77cbeb3f84531129ad8898b1c7f (patch)
tree569b4bb9e3c532c5b3131cd0b8b3aba542d9a0fb /tools/indexcap.py
parent72ea6d56d251f934d36394ecf96e4697794b537f (diff)
downloadwireshark-50b7a98610acb77cbeb3f84531129ad8898b1c7f.tar.gz
Use pickle to store the results into the index file
svn path=/trunk/; revision=30146
Diffstat (limited to 'tools/indexcap.py')
-rw-r--r--tools/indexcap.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/tools/indexcap.py b/tools/indexcap.py
index 99f79073c2..43a1a0fdc7 100644
--- a/tools/indexcap.py
+++ b/tools/indexcap.py
@@ -45,7 +45,6 @@ def process_capture_file(args):
proto_hash = {}
for line in stdout.splitlines():
- #for line in re.split(r'\r\n|\n', stdout):
if not re.match(r'^[\w:-]+$', line):
continue
@@ -56,7 +55,7 @@ def process_capture_file(args):
return (file, proto_hash)
def main():
- parser = OptionParser(usage="usage: %prog [options] cache_file file_1|dir_1 [.. file_n|dir_n]")
+ parser = OptionParser(usage="usage: %prog [options] index_file file_1|dir_1 [.. file_n|dir_n]")
parser.add_option("-n", "--no-append", dest="append", default=True, action="store_false", help="Do not append to existing cache file")
parser.add_option("-m", "--max-files", dest="max_files", default=sys.maxint, type="int", help="Max number of files to process")
parser.add_option("-b", "--binary-dir", dest="bin_dir", default=os.getcwd(), help="Directory containing tshark executable")
@@ -65,27 +64,39 @@ def main():
(options, args) = parser.parse_args()
if len(args) == 0:
- parser.error("cache_file is a required argument")
+ parser.error("index_file is a required argument")
if len(args) == 1:
parser.error("one capture file/directory must be specified")
tshark = os.path.join(options.bin_dir, "tshark.exe")
if os.access(tshark, os.X_OK):
- print "tshark:", tshark, "[FOUND]\n"
+ print "tshark:", tshark, "[FOUND]"
else:
- print "tshark:", tshark, "[MISSING]\n"
+ print "tshark:", tshark, "[MISSING]"
exit(1)
- cache_file = args.pop(0)
+ index_file_name = args.pop(0)
+ index_file = open(index_file_name, "r")
+ print "index_file:", index_file.name, "[OPENED]",
+
+ try:
+ cap_hash = pickle.load(index_file)
+ print "[REUSING]"
+ except IOError:
+ cap_hash = {}
+ print "[NEW]"
+ finally:
+ index_file.close()
+
paths = args
cap_files = []
for path in paths:
if os.path.isdir(path):
path = os.path.normpath(path)
for root, dirs, files in os.walk(path):
- cap_files += [os.path.join(root, name) for name in files]
- else:
+ cap_files += [os.path.join(root, name) for name in files if os.path.join(root, name) not in cap_hash]
+ elif path not in cap_hash:
cap_files.append(path)
cap_files.sort()
@@ -97,6 +108,9 @@ def main():
cap_hash = dict(results)
print cap_hash
+ index_file = open(index_file_name, "a")
+ pickle.dump(cap_hash, index_file)
+ index_file.close()
if __name__ == "__main__":
main()