00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 import argparse
00014 import os
00015
00016 print
00017 print "***********************\n"
00018 print "Copying <Interface>.h and <Interface>_interface.cc and renaming...\n" + \
00019 "Look for 'Success!' at end of print out.\n"
00020 print
00021
00022
00023 parser = argparse.ArgumentParser(description='Setup Firmware Component')
00024
00025
00026 parser.add_argument('-s','--src',
00027 help='Source path to directory of <Interface>.h and <Interface>_interface.cc to copy')
00028 parser.add_argument('-o','--old',required=True,
00029 help='Name of old Interface')
00030 parser.add_argument('-d','--dest',
00031 help='Destination path for new Interface')
00032 parser.add_argument('-n','--new',required=True,
00033 help='Name of new Interface')
00034
00035 args = parser.parse_args()
00036
00037 print
00038 print 'Arguments parsed...'
00039 print args
00040 print
00041 print
00042
00043
00044
00045
00046 scriptDir = os.path.dirname(os.path.abspath(__file__))
00047
00048
00049 print 'Script directory is:'
00050 print scriptDir
00051 print
00052
00053 if (args.src):
00054 src = args.src
00055 else:
00056 exit("Error: Must give a path to source interface (arg: --src).\n\n");
00057
00058 print 'Source directory is:'
00059 print src
00060 print
00061 print
00062
00063
00064 if ((not os.path.isdir(src + "/"))):
00065 print "Error!\n Check usage. "
00066 parser.print_help()
00067 print
00068 print "****************"
00069 exit("Error: Invalid source path '" + (src) + "'\n\n")
00070
00071 dest = src + "/"
00072 if (args.dest):
00073 dest = args.dest
00074 else:
00075 print "No dest argument - assuming same as source path."
00076
00077 print 'Destination directory is:'
00078 print dest
00079 print
00080 print
00081
00082
00083
00084 if ((not os.path.isdir(dest + "/"))):
00085 print "Error!\n Check usage. "
00086 parser.print_help()
00087 print
00088 print "****************"
00089 exit("Error: Invalid destination path '" + (dest) + "'\n\n")
00090
00091
00092 print 'Copy files and replace name...'
00093
00094 os.system("cp " + src + "/" + args.old + "_interface.cc " + dest + "/" + args.new + "_interface.cc");
00095 os.system("sed -i s/" + args.old + "/" + args.new + "/g " + \
00096 dest + "/" + args.new + "_interface.cc");
00097
00098 os.system("cp " + src + "/" + args.old + ".h " + dest + "/" + args.new + ".h");
00099 os.system("sed -i s/" + args.old + "/" + args.new + "/g " + \
00100 dest + "/" + args.new + ".h");
00101
00102
00103
00104
00105 print
00106 print "***********************\n"
00107 print 'Success!'
00108 print
00109 print
00110