20 parser = argparse.ArgumentParser(description = __doc__, )
21 parser.add_argument('--output', help='JSON output file', required = True)
22 parser.add_argument('--transforms', help='Comma separated list of transforms to process', default='all')
23 cliargs = vars(parser.parse_args())
24
25
26
27 sys.path.insert(1, os.path.join(os.getcwd(), '../scripts'))
28
29 myTrfSigs = {}
30 myTrfSigDesc = {}
31
32 if cliargs['transforms'] == 'all':
33
34
35 myTrfs = [ os.path.basename(t)[:-3] for t in glob.glob('../scripts/*_tf.py') ]
36 else:
37 myTrfs = cliargs[
'transforms'].
split(
',')
38 logging.info('Will process this list of transforms: {0}'.format(' '.join(myTrfs)))
39 processedTrfs = []
40
41 for trf in myTrfs:
42 logging.info('Processing argument signatures for {0}'.format(trf))
43
44 try:
45 trfModule = __import__('{0}'.format(trf), globals(), locals(), ['getTransform'], 0)
46 except ImportError:
47 logging.warning('Failed to import transform {0} - ignored'.format(trf))
48 continue
49 if 'getTransform' not in dir(trfModule):
50 logging.warning('Transform {0} has no getTransform() functionality - ignored for pickle'.format(trf))
51 continue
52 transform = trfModule.getTransform()
53 args = transform.parser.allArgs
54
55 logging.debug('Trf %s: %s', trf, args)
56 processedTrfs.append(trf)
57 myTrfSigs[trf] = args
58 myTrfSigDesc[trf] = transform.parser.getProdsysDesc
59 try:
60 logging.info('Writing JSON signatures to {0}'.format(cliargs['output']))
61 sigFile = open(cliargs['output'], 'wb')
62 json.dump(myTrfSigDesc, sigFile, indent=4)
63 except OSError as e:
64 logging.error('Failed to dump pickled signatures to %s: %s', cliargs['output'], e)
65 sys.exit(1)
66
67 logging.info('Successfully generated signature file "%s" for transforms %s', cliargs['output'], processedTrfs)
68 sys.exit(0)
69
std::vector< std::string > split(const std::string &s, const std::string &t=":")