Refactoring: add find_capture_files()
authorkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 25 Sep 2009 17:47:25 +0000 (17:47 +0000)
committerkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 25 Sep 2009 17:47:25 +0000 (17:47 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@30150 f5534014-38df-0310-8fa8-9805f1628bb7

tools/indexcap.py

index 842c3a2ef8b7d3c0af2c732bd34794896451ae44..4b67e7c0b0503d7a7bc4fb0f879bbb4088bc0c92 100644 (file)
@@ -71,6 +71,17 @@ def list_files(cap_hash):
 def index_file_action(options):
     return options.list_proto or options.list_files
 
+def find_capture_files(paths, cap_hash):
+    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 if os.path.join(root, name) not in cap_hash]
+        elif path not in cap_hash:
+            cap_files.append(path)
+    return cap_files
+
 def main():
     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")
@@ -115,15 +126,7 @@ def main():
         exit(1)
 
     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 if os.path.join(root, name) not in cap_hash]
-        elif path not in cap_hash:
-            cap_files.append(path)
-
+    cap_files = find_capture_files(paths, cap_hash)
     cap_files.sort()
     print len(cap_files), "total files,",
     cap_files = cap_files[:options.max_files]