1 | #!/usr/bin/env python |
---|
2 | #************************************************************************************** |
---|
3 | #nappyCheck.py |
---|
4 | #Tries to open files with NAPPY (NASA Ames Processing in PYthon) and |
---|
5 | # reports on results |
---|
6 | #Dominic Lowe, BADC, 11th May 2005 |
---|
7 | #************************************************************************************** |
---|
8 | |
---|
9 | import nappy |
---|
10 | import getopt |
---|
11 | import sys |
---|
12 | import csmllibs |
---|
13 | |
---|
14 | def main(optargs=None): |
---|
15 | #get commandline args |
---|
16 | if optargs: |
---|
17 | #if called as main(args) from another python module use these args, else use |
---|
18 | #sys.argv if called from command line. |
---|
19 | sys.argv =optargs |
---|
20 | try: |
---|
21 | opts, args = getopt.getopt(sys.argv[1:], "d:o:", ["directory=", "outputfile=",]) |
---|
22 | except getopt.error, msg: |
---|
23 | print "Invalid options, use --help for help" |
---|
24 | sys.exit() |
---|
25 | print opts |
---|
26 | for o, v in opts: |
---|
27 | if o in ("-d", "--directory"): |
---|
28 | directory = v |
---|
29 | elif o in ("-o", "--outputfile"): |
---|
30 | outputfile = v |
---|
31 | |
---|
32 | tree = csmllibs.csmldirectory.DirectoryTree() |
---|
33 | tree.setTopDirectory(directory) |
---|
34 | tree.readDirectory() |
---|
35 | |
---|
36 | success=[] |
---|
37 | failure=[] |
---|
38 | nonNA=[] |
---|
39 | for subdir in tree.getSubDirectories(): |
---|
40 | for file in tree.getFilesInSubDir(subdir): |
---|
41 | naformat = nappy.readFFI(file) |
---|
42 | if naformat in [1001,1010,1020,2010,2110,2160,2310,3010,4010]: |
---|
43 | try: |
---|
44 | nappy.openNAFile(file) |
---|
45 | success.append(str(file)) |
---|
46 | #print '%s opened successfully' % str(file) |
---|
47 | except: |
---|
48 | failure.append(str(file)) |
---|
49 | #print 'could not open file %s' % str(file) |
---|
50 | else: |
---|
51 | nonNA.append(str(file)) |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | outf = open(outputfile, "w") |
---|
56 | outf.write('\n Results for directory; %s' % directory) |
---|
57 | outf.write('\n \n Executive Summary:') |
---|
58 | outf.write('\n %d files can be read by NAPPY' % len(success)) |
---|
59 | outf.write('\n %d files are unreadable NASA Ames' % len(failure)) |
---|
60 | outf.write('\n %d files seem not to be NASA Ames (eg gifs, jpegs etc)' % len(nonNA)) |
---|
61 | outf.write('\n \n \n The following NASA Ames files appeared to open OK:') |
---|
62 | for f in success: |
---|
63 | outf.write('\n %s'%f) |
---|
64 | outf.write('\n \n \n The following NASA Ames files are incorrectly formatted and would NOT open:') |
---|
65 | for f in failure: |
---|
66 | outf.write('\n %s'%f) |
---|
67 | outf.write('\n \n \n The following files are not believed to be NASA Ames files') |
---|
68 | for f in nonNA: |
---|
69 | outf.write('\n %s'%f) |
---|
70 | |
---|
71 | |
---|
72 | outf.close() |
---|
73 | print 'Results written to %s' % outputfile |
---|
74 | |
---|
75 | if __name__=='__main__': |
---|
76 | main() |
---|