From c2c71282455b5f2ad78c4d2ef3dae5873b8b9561 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 30 Jan 2014 17:22:09 +1100 Subject: [PATCH] Put the generated driver where we got the input --- site_ansto/instrument/util/gen_sct.py | 33 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index 4413d349..e895627b 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -25,6 +25,7 @@ # should some hset commands be hupdate commands? # +import os import ply.lex as lex import ply.yacc as yacc @@ -215,8 +216,9 @@ def p_driver(p): p[0] = [{ 'Driver' : {p[2] : p[4]}}] if Verbose: print "Driver:", p[0] + global PathName global TheDrivers - TheDrivers[p[2]] = p[4] + TheDrivers[p[2]] = p[4] + [{'PathName':PathName}] def p_driver_block(p): 'driver_block : LBRACE driver_statement_list RBRACE' @@ -1204,8 +1206,10 @@ def generate_driver(MyDriver): global NumberOfLinesOut global fdo NumberOfLinesOut = 0 - filename = "sct_%s.tcl" % MyDriver['name'] - fdo = open(filename, 'w') + full_filename = filename = "sct_%s.tcl" % MyDriver['name'] + if 'PathName' in MyDriver: + full_filename = os.path.join(MyDriver['PathName'], filename) + fdo = open(full_filename, 'w') put_preamble(MyDriver) put_standard_code(MyDriver) if 'driveable' in MyDriver: @@ -1244,7 +1248,8 @@ def process_drivers(TheDrivers): if DriverDump or Verbose: dump_driver(MyDriver) -def process_source(source_file): +def process_source(source_files): + global PathName global TheDrivers global NumberOfLinesIn @@ -1261,12 +1266,15 @@ def process_source(source_file): # yaccer = yacc.yacc() - fd = open(source_file, 'r') - data = fd.read() - fd.close() - NumberOfLinesIn = data.count('\n') - print 'Consumed file %s with %d lines' % (source_file, NumberOfLinesIn) - yaccer.parse(data) + for source_file in source_files: + PathName = os.path.realpath(os.path.abspath(os.path.dirname(source_file))) + fd = open(source_file, 'r') + data = fd.read() + fd.close() + NumberOfLinesIn = data.count('\n') + print 'Consumed file %s with %d lines' % (source_file, NumberOfLinesIn) + yaccer.parse(data) + process_drivers(TheDrivers) def main(): @@ -1297,8 +1305,9 @@ def main(): Verbose = True else: Verbose = False - for source_file in args.driver_source: - process_source(source_file) + source_files = args.driver_source + if source_files: + process_source(source_files) if __name__ == "__main__": main()