Refactor the output filename handling and sct position in the name
add --sct options for before (sct_*.tcl) or after (*_sct.tcl) the driver name
This commit is contained in:
@ -637,6 +637,36 @@ def make_path(MyVar):
|
|||||||
path += MyVar['name']
|
path += MyVar['name']
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def generate_filename(MyDriver):
|
||||||
|
global args
|
||||||
|
old_name = "sct_%s.tcl" % MyDriver['name']
|
||||||
|
new_name = "%s_sct.tcl" % MyDriver['name']
|
||||||
|
if 'PathName' in MyDriver:
|
||||||
|
full_old_name = os.path.join(MyDriver['PathName'], old_name)
|
||||||
|
full_new_name = os.path.join(MyDriver['PathName'], new_name)
|
||||||
|
else:
|
||||||
|
full_old_name = old_name
|
||||||
|
full_new_name = new_name
|
||||||
|
|
||||||
|
# This block of code generates shell commands to help the old->new rename
|
||||||
|
if Move:
|
||||||
|
fd = open("git_mv.sh", "a")
|
||||||
|
fd.write( "git mv " + full_old_name + " " + full_new_name + "\n")
|
||||||
|
fd.close()
|
||||||
|
fd = open("grep_sed.sh", "a")
|
||||||
|
fd.write( "for f in $(grep " + old_name + " instrument -Irl" + "); do\n")
|
||||||
|
fd.write( " echo ${f}\n")
|
||||||
|
fd.write( " sed -i ${f} -e 's/" + old_name + "/" + new_name + "/'\n")
|
||||||
|
fd.write( "done\n")
|
||||||
|
fd.close()
|
||||||
|
|
||||||
|
if args.sct == "before":
|
||||||
|
MyDriver['filename'] = old_name
|
||||||
|
MyDriver['fullname'] = full_old_name
|
||||||
|
else:
|
||||||
|
MyDriver['filename'] = new_name
|
||||||
|
MyDriver['fullname'] = full_new_name
|
||||||
|
|
||||||
def parse_args(arg_str):
|
def parse_args(arg_str):
|
||||||
'''
|
'''
|
||||||
Parse the TCL argument string into a list of identifiers (in order) plus
|
Parse the TCL argument string into a list of identifiers (in order) plus
|
||||||
@ -1714,8 +1744,8 @@ def put_postamble(MyDriver):
|
|||||||
txt += [line]
|
txt += [line]
|
||||||
txt += ['}']
|
txt += ['}']
|
||||||
txt += ['']
|
txt += ['']
|
||||||
txt += ['clientput "file evaluation of sct_%s.tcl"' % MyDriver['name']]
|
txt += ['clientput "file evaluation of %s"' % MyDriver['filename']]
|
||||||
txt += ['%s::sics_log 9 "file evaluation of sct_%s.tcl"' % (MyDriver['namespace'], MyDriver['name'])]
|
txt += ['%s::sics_log 9 "file evaluation of %s"' % (MyDriver['namespace'], MyDriver['filename'])]
|
||||||
emit(txt)
|
emit(txt)
|
||||||
|
|
||||||
def put_read_config(MyDriver):
|
def put_read_config(MyDriver):
|
||||||
@ -1897,16 +1927,8 @@ def generate_driver(MyDriver):
|
|||||||
global NumberOfLinesOut
|
global NumberOfLinesOut
|
||||||
global fdo
|
global fdo
|
||||||
NumberOfLinesOut = 0
|
NumberOfLinesOut = 0
|
||||||
old_name = "sct_%s.tcl" % MyDriver['name']
|
generate_filename(MyDriver)
|
||||||
new_name = "%s_sct.tcl" % MyDriver['name']
|
fdo = open(MyDriver['fullname'], 'w')
|
||||||
if 'PathName' in MyDriver:
|
|
||||||
full_old_name = os.path.join(MyDriver['PathName'], old_name)
|
|
||||||
full_new_name = os.path.join(MyDriver['PathName'], new_name)
|
|
||||||
else:
|
|
||||||
full_old_name = old_name
|
|
||||||
full_new_name = new_name
|
|
||||||
fdo = open(full_new_name, 'w')
|
|
||||||
MyDriver['filename'] = new_name
|
|
||||||
put_preamble(MyDriver)
|
put_preamble(MyDriver)
|
||||||
put_standard_code(MyDriver)
|
put_standard_code(MyDriver)
|
||||||
put_mkDriver(MyDriver)
|
put_mkDriver(MyDriver)
|
||||||
@ -1924,17 +1946,6 @@ def generate_driver(MyDriver):
|
|||||||
if Verbose:
|
if Verbose:
|
||||||
print "Produced file %s with %d lines." % \
|
print "Produced file %s with %d lines." % \
|
||||||
( MyDriver['filename'], NumberOfLinesOut)
|
( MyDriver['filename'], NumberOfLinesOut)
|
||||||
# This block of code generates shell commands to help the old->new rename
|
|
||||||
if Move:
|
|
||||||
fd = open("git_mv.sh", "a")
|
|
||||||
fd.write( "git mv " + full_old_name + " " + full_new_name + "\n")
|
|
||||||
fd.close()
|
|
||||||
fd = open("grep_sed.sh", "a")
|
|
||||||
fd.write( "for f in $(grep " + old_name + " instrument -Irl" + "); do\n")
|
|
||||||
fd.write( " echo ${f}\n")
|
|
||||||
fd.write( " sed -i ${f} -e 's/" + old_name + "/" + new_name + "/'\n")
|
|
||||||
fd.write( "done\n")
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
def process_drivers(TheDrivers):
|
def process_drivers(TheDrivers):
|
||||||
if Verbose:
|
if Verbose:
|
||||||
@ -2075,6 +2086,8 @@ def main():
|
|||||||
action="store_true")
|
action="store_true")
|
||||||
parser.add_argument("-m", "--move", help="generate move commands",
|
parser.add_argument("-m", "--move", help="generate move commands",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
parser.add_argument("--sct", help="where to put the sct in the filename",
|
||||||
|
choices=["before", "after"], default="after")
|
||||||
parser.add_argument("-v", "--verbose", help="verbose output",
|
parser.add_argument("-v", "--verbose", help="verbose output",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
parser.add_argument("driver_source", help="driver source file", nargs="*")
|
parser.add_argument("driver_source", help="driver source file", nargs="*")
|
||||||
|
Reference in New Issue
Block a user