1 | #! /usr/bin/python |
---|
2 | |
---|
3 | from glob import glob |
---|
4 | from os.path import splitext, exists, join, dirname, basename |
---|
5 | import sys |
---|
6 | |
---|
7 | def check_tst_against_src(src_dir, src_ext, ext_dir, verbose = False, tst_prefix = ''): |
---|
8 | src_files = [ basename(file) for file in glob( join(src_dir, '*'+src_ext) ) ] |
---|
9 | src_files.sort() |
---|
10 | status = 0 |
---|
11 | for src_file in src_files: |
---|
12 | tst_file = (splitext(src_file)[0] + tst_ext).replace(tst_prefix,"") |
---|
13 | if not exists(join(tst_dir,tst_prefix+tst_file)): |
---|
14 | print "%20s [X]" % src_file, "[ ] %s" % tst_file |
---|
15 | status = 1 |
---|
16 | elif verbose: |
---|
17 | print "%20s [X]" % src_file, "[X] %s" % tst_file |
---|
18 | return status |
---|
19 | |
---|
20 | def check_src_against_tst(tst_dir, tst_ext, src_dir, verbose = False, tst_prefix = 'test-'): |
---|
21 | tst_files = [ basename(file) for file in glob( join(tst_dir, '*'+tst_ext) ) ] |
---|
22 | tst_files.sort() |
---|
23 | status = 0 |
---|
24 | for tst_file in tst_files: |
---|
25 | src_file = (splitext(tst_file)[0] + src_ext).replace(tst_prefix,"") |
---|
26 | if not exists(join(src_dir,src_file)): |
---|
27 | print "%20s [ ]" % src_file, "[X] %s" % tst_file |
---|
28 | status = 2 |
---|
29 | elif verbose: |
---|
30 | print "%20s [X]" % src_file, "[X] %s" % tst_file |
---|
31 | return status |
---|
32 | |
---|
33 | if __name__ == '__main__': |
---|
34 | |
---|
35 | if len(sys.argv) > 1: verbose = True |
---|
36 | else: verbose = False |
---|
37 | |
---|
38 | src_dir = join(dirname(sys.argv[0]),'..','src') |
---|
39 | src_ext = '.c' |
---|
40 | |
---|
41 | tst_dir = join(dirname(sys.argv[0]),'python') |
---|
42 | tst_ext = '.py' |
---|
43 | print "%20s " % (" FILES IN " + src_dir) + "|" + " FILES IN " + tst_dir |
---|
44 | status = check_tst_against_src(src_dir, src_ext, tst_dir, verbose=verbose) |
---|
45 | status += check_src_against_tst(tst_dir, tst_ext, src_dir, verbose=verbose) |
---|
46 | |
---|
47 | tst_dir = join(dirname(sys.argv[0]),'src') |
---|
48 | tst_ext = '.c' |
---|
49 | print "%20s " % (" FILES IN " + src_dir) + "|" + " FILES IN " + tst_dir |
---|
50 | status += check_tst_against_src(src_dir, src_ext, tst_dir, verbose=verbose, tst_prefix = 'test-') |
---|
51 | status += check_src_against_tst(tst_dir, tst_ext, src_dir, verbose=verbose, tst_prefix = 'test-') |
---|
52 | |
---|
53 | sys.exit(status) |
---|