Refactoring: add find_capture_files()

svn path=/trunk/; revision=30150
This commit is contained in:
Kovarththanan Rajaratnam 2009-09-25 17:47:25 +00:00
parent 8bd432e940
commit 8ff8f868c1
1 changed files with 12 additions and 9 deletions

View 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]