Skip to content

Commit 76a2c38

Browse files
authored
Merge pull request #5 from dheles/check-inventory
Add check inventory script
2 parents 3c3e049 + a82a17a commit 76a2c38

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

checkInventory.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)