|
1 | | -import argparse |
2 | | -import pandas as pd |
3 | | -import os |
4 | | - |
5 | | - |
6 | | -def main(): |
7 | | - # begin: argument parsing |
8 | | - parser = argparse.ArgumentParser() |
9 | | - |
10 | | - parser.add_argument('-i', '--inventory', required=True, |
11 | | - help='csv file containing the inventory. the path, if given, can be absolute or relative to this script') |
12 | | - |
13 | | - parser.add_argument('-d', '--dataDir', |
14 | | - help='directory containing the data. if omitted, data will be read from the directory containing the inventory file') |
15 | | - |
16 | | - parser.add_argument('-f', '--field', |
17 | | - help='field in the csv containing the fileNames. default: name') |
18 | | - |
19 | | - parser.add_argument('-v', '--verbose', action='store_true', |
20 | | - help='increase output verbosity') |
21 | | - |
22 | | - args = parser.parse_args() |
23 | | - |
24 | | - if not args.dataDir: |
25 | | - (args.dataDir, null) = os.path.split(args.inventory) |
26 | | - |
27 | | - if not args.field: |
28 | | - args.field = 'name' |
29 | | - |
30 | | - if args.verbose: |
31 | | - print('verbosity turned on') |
32 | | - print('reading inventory from {}'.format(args.inventory)) |
33 | | - print('fileNames read from field named {}'.format(args.field)) |
34 | | - print('searching for files in {}'.format(args.dataDir)) |
35 | | - # end: argument parsing |
36 | | - |
37 | | - inventory = pd.read_csv(args.inventory, usecols=[args.field]) |
38 | | - fileNames = inventory[args.field] |
39 | | - foundfiles = 0 |
40 | | - missingfiles = 0 |
41 | | - for fileName in fileNames: |
42 | | - if os.path.isfile(args.dataDir + '/' + fileName): |
43 | | - if args.verbose: print('{} is not missing'.format(fileName)) |
44 | | - foundfiles += 1 |
45 | | - else: |
46 | | - print('{} is missing'.format(fileName)) |
47 | | - missingfiles += 1 |
48 | | - |
49 | | - print('{} files found and {} files missing'.format(foundfiles, missingfiles)) |
50 | | - |
51 | | - |
52 | | -if __name__ == "__main__": main() |
| 1 | +import argparse |
| 2 | +import pandas as pd |
| 3 | +import os |
| 4 | + |
| 5 | + |
| 6 | +def main(): |
| 7 | + # begin: argument parsing |
| 8 | + parser = argparse.ArgumentParser() |
| 9 | + |
| 10 | + parser.add_argument('-i', '--inventory', required=True, |
| 11 | + help='csv file containing the inventory. the path, if given, can be absolute or relative to this script') |
| 12 | + |
| 13 | + parser.add_argument('-d', '--dataDir', |
| 14 | + help='directory containing the data. if omitted, data will be read from the directory containing the inventory file') |
| 15 | + |
| 16 | + parser.add_argument('-f', '--field', |
| 17 | + help='field in the csv containing the fileNames. default: name') |
| 18 | + |
| 19 | + parser.add_argument('-v', '--verbose', action='store_true', |
| 20 | + help='increase output verbosity') |
| 21 | + |
| 22 | + args = parser.parse_args() |
| 23 | + |
| 24 | + if not args.dataDir: |
| 25 | + (args.dataDir, null) = os.path.split(args.inventory) |
| 26 | + |
| 27 | + if not args.field: |
| 28 | + args.field = 'name' |
| 29 | + |
| 30 | + if args.verbose: |
| 31 | + print('verbosity turned on') |
| 32 | + print('reading inventory from {}'.format(args.inventory)) |
| 33 | + print('fileNames read from field named {}'.format(args.field)) |
| 34 | + print('searching for files in {}'.format(args.dataDir)) |
| 35 | + # end: argument parsing |
| 36 | + |
| 37 | + inventory = pd.read_csv(args.inventory, usecols=[args.field]) |
| 38 | + fileNames = inventory[args.field] |
| 39 | + foundfiles = 0 |
| 40 | + missingfiles = 0 |
| 41 | + for fileName in fileNames: |
| 42 | + if os.path.isfile(args.dataDir + '/' + fileName): |
| 43 | + if args.verbose: print('{} is not missing'.format(fileName)) |
| 44 | + foundfiles += 1 |
| 45 | + else: |
| 46 | + print('{} is missing'.format(fileName)) |
| 47 | + missingfiles += 1 |
| 48 | + |
| 49 | + print('{} files found and {} files missing'.format(foundfiles, missingfiles)) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": main() |
0 commit comments