otsdaq_utilities  v2_05_02_indev
AddNewInterface.py
1 #!/usr/bin/env python
2 #____________________________________________________________
3 #
4 # addNewFrontEndInterface.py --help
5 #
6 #____________________________________________________________
7 #
8 
9 #//For example:
10 #// ./addNewFrontEndInterface.py -n MyInterface
11 #// -- copy FrontEndGenericInterface.cc MyInterface.cc
12 #// -- replace sed /FrontEndGenericInterface/MyInterface/g
13 
14 import argparse
15 import os #for isdir abspath dirname
16 
17 #//Steps:
18 #// - copy source to destination
19 #// - swap in new name
20 #// - Add entry in destination CMakeLists.txt
21 
22 
23 print
24 print "***********************\n"
25 print "Setting up and Installing...\n" + \
26  "Look for 'Success!' at end of print out.\n"
27 print
28 
29 
30 parser = argparse.ArgumentParser(description='Setup Firmware Component')
31 
32 parser.add_argument('-s','--src',
33  help='Source path for new Interface')
34 parser.add_argument('-d','--dest',
35  help='Destination path for new Interface')
36 parser.add_argument('-n','--name',
37  help='Name of new Interface')
38 parser.add_argument('-hw','--hardwareName',
39  help='Name of new Interface')
40 parser.add_argument('-fw','--firmwareName',
41  help='Name of new Interface')
42 
43 args = parser.parse_args()
44 
45 print
46 print 'Arguments parsed...'
47 print args
48 print
49 print
50 
51 ########
52 # at this point call is legal according to argparse
53 
54 scriptDir = os.path.dirname(os.path.abspath(__file__))
55 
56 
57 print 'Script directory is:'
58 print scriptDir
59 print
60 
61 ##################################
62 print 'Validating source path...'
63 
64 source = scriptDir + "/../../otsdaq_demo/" #default destination path
65 if (args.dest): #if option used, then use args.dest
66  dest = args.dest
67 
68 print 'Destination directory is:'
69 print dest
70 print
71 print
72 
73 #validate destination directory
74 if ((not os.path.isdir(dest + "/"))):
75  print "Error!\n Check usage. "
76  parser.print_help()
77  print
78  print "****************"
79  exit("Error: Invalid destination path '" + (args.dest) + "')\n\n")
80 
81 ##################################
82 dest = scriptDir + "/" #default destination path
83 if (args.dest): #if option used, then use args.dest
84  dest = args.dest
85 
86 print 'Destination directory is:'
87 print dest
88 print
89 print
90 
91 #validate destination directory
92 if ((not os.path.isdir(dest + "/"))):
93  print "Error!\n Check usage. "
94  parser.print_help()
95  print
96  print "****************"
97  exit("Error: Invalid destination path '" + (args.dest) + "')\n\n")
98 
99 
100 print 'Copy files...'
101 
102 srcFile = scriptDir + "/../../otsdaq/otsdaq/DetectorWriter/FrontEndInterfaceTemplate.cc"
103 os.system("cp " + srcFile + " " + args.dest + "/" + args.name + ".cc");
104 os.system("sed -i s/FrontEndInterfaceTemplate/" + args.name + "/g " + \
105  args.dest + "/" + args.name + ".cc");
106 os.system("sed -i s/FrontEndHardwareTemplate/" + args.hardwareName + "/g " + \
107  args.dest + "/" + args.name + ".cc");
108 os.system("sed -i s/FrontEndFirmwareTemplate/" + args.firmwareName + "/g " + \
109  args.dest + "/" + args.name + ".cc");
110 
111 srcFile = scriptDir + "/../../otsdaq/otsdaq/DetectorWriter/FrontEndInterfaceTemplate.h"
112 os.system("cp " + srcFile + " " + args.dest + "/" + args.name + ".h");
113 os.system("sed -i s/FrontEndInterfaceTemplate/" + args.name + "/g " + \
114  args.dest + "/" + args.name + ".h");
115 os.system("sed -i s/FrontEndHardwareTemplate/" + args.hardwareName + "/g " + \
116  args.dest + "/" + args.name + ".h");
117 os.system("sed -i s/FrontEndFirmwareTemplate/" + args.firmwareName + "/g " + \
118  args.dest + "/" + args.name + ".h");
119 
120 
121 
122 
123 
124 print
125 print "***********************\n"
126 print 'Success!'
127 print
128 print
129