otsdaq_utilities  v2_05_02_indev
CopyInterface.py
1 #!/usr/bin/env python
2 #____________________________________________________________
3 #
4 # addNewInterface.py --help
5 #
6 #____________________________________________________________
7 #
8 
9 #//./addnewFEWInterface.py -n MyInterface
10 #//-- copy FrontEndGenericInterface.cc MyInterface.cc
11 #//-- replace sed /FrontEndGenericInterface/MyInterface/g
12 
13 import argparse
14 import os #for isdir abspath dirname
15 
16 print
17 print "***********************\n"
18 print "Copying <Interface>.h and <Interface>_interface.cc and renaming...\n" + \
19  "Look for 'Success!' at end of print out.\n"
20 print
21 
22 
23 parser = argparse.ArgumentParser(description='Setup Firmware Component')
24 
25 
26 parser.add_argument('-s','--src',
27  help='Source path to directory of <Interface>.h and <Interface>_interface.cc to copy')
28 parser.add_argument('-o','--old',required=True,
29  help='Name of old Interface')
30 parser.add_argument('-d','--dest',
31  help='Destination path for new Interface')
32 parser.add_argument('-n','--new',required=True,
33  help='Name of new Interface')
34 
35 args = parser.parse_args()
36 
37 print
38 print 'Arguments parsed...'
39 print args
40 print
41 print
42 
43 ########
44 # at this point call is legal according to argparse
45 
46 scriptDir = os.path.dirname(os.path.abspath(__file__))
47 
48 
49 print 'Script directory is:'
50 print scriptDir
51 print
52 
53 if (args.src): #if option used, then use args.src
54  src = args.src
55 else:
56  exit("Error: Must give a path to source interface (arg: --src).\n\n");
57 
58 print 'Source directory is:'
59 print src
60 print
61 print
62 
63 #validate source directory
64 if ((not os.path.isdir(src + "/"))):
65  print "Error!\n Check usage. "
66  parser.print_help()
67  print
68  print "****************"
69  exit("Error: Invalid source path '" + (src) + "'\n\n")
70 
71 dest = src + "/" #default destination path to source path
72 if (args.dest): #if option used, then use args.dest
73  dest = args.dest
74 else:
75  print "No dest argument - assuming same as source path."
76 
77 print 'Destination directory is:'
78 print dest
79 print
80 print
81 
82 
83 #validate destination directory
84 if ((not os.path.isdir(dest + "/"))):
85  print "Error!\n Check usage. "
86  parser.print_help()
87  print
88  print "****************"
89  exit("Error: Invalid destination path '" + (dest) + "'\n\n")
90 
91 
92 print 'Copy files and replace name...'
93 
94 os.system("cp " + src + "/" + args.old + "_interface.cc " + dest + "/" + args.new + "_interface.cc");
95 os.system("sed -i s/" + args.old + "/" + args.new + "/g " + \
96  dest + "/" + args.new + "_interface.cc");
97 
98 os.system("cp " + src + "/" + args.old + ".h " + dest + "/" + args.new + ".h");
99 os.system("sed -i s/" + args.old + "/" + args.new + "/g " + \
100  dest + "/" + args.new + ".h");
101 
102 
103 
104 
105 print
106 print "***********************\n"
107 print 'Success!'
108 print
109 print
110