1 | #!/usr/bin/env python |
---|
2 | #----------------------------------# |
---|
3 | # -- Author: V. Garonne |
---|
4 | # -- Mail: garonne@lal.in2p3.fr |
---|
5 | # -- Date: 08/25/2006 |
---|
6 | # -- Name: tbroadcast |
---|
7 | # -- Description: main program |
---|
8 | #----------------------------------# |
---|
9 | |
---|
10 | import sys |
---|
11 | import time |
---|
12 | |
---|
13 | def usage(): |
---|
14 | print """ |
---|
15 | Usage: tbroadcast [global options] [<command>] |
---|
16 | # |
---|
17 | # <command> is executed in <package>/cmt |
---|
18 | # |
---|
19 | # global options : |
---|
20 | # -help : Print help |
---|
21 | # -local : Reach packages only within the current project |
---|
22 | # : if not specified reach packages in all CMTPATH/CMTPROJECTPATH items |
---|
23 | # -ignore[_cycles] : Suppress automatically the cycles |
---|
24 | # -sort : Compile packages in order of use count, most significant first |
---|
25 | # -nb=<num_worker> : Change the total number of threads[default is 20] |
---|
26 | # -output=<location> : Output directory to store output files with the form <package>_output.log |
---|
27 | # -error=<location> : Output directory to store error output with the form <package>_error.log |
---|
28 | # -perf=<file> : Store for each package the time for executing the command in the <file> file |
---|
29 | # -make=<file> : Generate a recursive Make, [see: http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html] |
---|
30 | # -print : Print dependencies for each package and exit |
---|
31 | # -version : Print version of tbroadcast and exit |
---|
32 | # -test : Simulate execution and exit |
---|
33 | # - : is accepted and does nothing |
---|
34 | # |
---|
35 | # Example: |
---|
36 | # tbroadcast -local -ignore -nb=4 'make -j6' |
---|
37 | """ |
---|
38 | |
---|
39 | # Unused options |
---|
40 | # -f=<file> : Input file (option for debug only) |
---|
41 | # -no_keep_going : Exit after the first exit code > 1 found and return it in the shell |
---|
42 | # -silent : Disable print |
---|
43 | |
---|
44 | if __name__ == '__main__': |
---|
45 | # check python version |
---|
46 | req_version = (2,5) |
---|
47 | cur_version = sys.version_info |
---|
48 | |
---|
49 | if not (cur_version[0] > req_version[0] or (cur_version[0] == req_version[0] and cur_version[1] >= req_version[1])): |
---|
50 | print "tbroadcast: must use python 2.5 or greater" |
---|
51 | sys.exit(-1) |
---|
52 | |
---|
53 | from tbroadcast import Scheduler |
---|
54 | |
---|
55 | # Default options |
---|
56 | num_worker = 20 |
---|
57 | command = '' |
---|
58 | version = 'v2.0.7' |
---|
59 | test = False |
---|
60 | print_graph = False |
---|
61 | local = False |
---|
62 | ignore_cycles = False |
---|
63 | silent = False |
---|
64 | perf = False |
---|
65 | sort = False |
---|
66 | output = None |
---|
67 | error = None |
---|
68 | file = None |
---|
69 | make = None |
---|
70 | makefile = 'Makefile' |
---|
71 | keep_going = True |
---|
72 | |
---|
73 | if len(sys.argv) == 1: |
---|
74 | usage() |
---|
75 | sys.exit(-1) |
---|
76 | else: |
---|
77 | for arg in sys.argv[1:len(sys.argv)]: |
---|
78 | # print "Argument is",arg |
---|
79 | if arg[0]=='-': |
---|
80 | option = arg.split('=')[0] |
---|
81 | if option == '-version': |
---|
82 | print version |
---|
83 | sys.exit(-1) |
---|
84 | elif option == '-nb': |
---|
85 | num_worker = int (arg.split('=')[1]) |
---|
86 | elif option == '-f': |
---|
87 | file = arg.split('=')[1] |
---|
88 | elif option == '-perf': |
---|
89 | perf = arg.split('=')[1] |
---|
90 | elif option == '-output': |
---|
91 | output = arg.split('=')[1] |
---|
92 | elif option == '-error': |
---|
93 | error = arg.split('=')[1] |
---|
94 | elif option == '-local': |
---|
95 | local = True |
---|
96 | elif option == '-sort': |
---|
97 | sort = True |
---|
98 | elif option[:7] == '-ignore': |
---|
99 | ignore_cycles = True |
---|
100 | elif option == '-silent': |
---|
101 | silent = True |
---|
102 | elif option == '-no_keep_going': |
---|
103 | keep_going = False |
---|
104 | elif option == '-help': |
---|
105 | usage() |
---|
106 | sys.exit(-1) |
---|
107 | elif option == '-test': |
---|
108 | test = True |
---|
109 | elif option == '-print': |
---|
110 | print_graph = True |
---|
111 | elif option == '-make': |
---|
112 | make = True |
---|
113 | makefile = arg.split('=')[1] |
---|
114 | elif option == '-': |
---|
115 | pass |
---|
116 | else: |
---|
117 | print 'tbroadcast: bad option "%s", use -help for help' % option |
---|
118 | sys.exit(-1) |
---|
119 | else: |
---|
120 | command = arg |
---|
121 | |
---|
122 | # print "End of arguments. Command to execute", command |
---|
123 | |
---|
124 | if not (command or test or print_graph): |
---|
125 | print 'tbroadcast: no command specified' |
---|
126 | sys.exit(-1) |
---|
127 | |
---|
128 | master = Scheduler (num_workers=num_worker, file=file, ignore_cycles=ignore_cycles, |
---|
129 | local=local, output=output, error=error, silent=silent, perf=perf, |
---|
130 | keep_going=keep_going, sort=sort) |
---|
131 | if test: |
---|
132 | master.simulate_execution() |
---|
133 | elif print_graph: |
---|
134 | master.print_dependencies() |
---|
135 | elif make: |
---|
136 | master.generate_make (makefile, command) |
---|
137 | else: |
---|
138 | print 'tbroadcast: start of job at', time.strftime('%d-%b-%Y %T') |
---|
139 | master.execute_all (command) |
---|
140 | print 'tbroadcast: end of job at', time.strftime('%d-%b-%Y %T') |
---|
141 | #sys.exit(-1) |
---|
142 | #--------- EoF --------# |
---|