[240] | 1 | #!/usr/bin/env python |
---|
[232] | 2 | #----------------------------------# |
---|
[242] | 3 | # -- Author: V. Garonne |
---|
| 4 | # -- Mail: garonne@lal.in2p3.fr |
---|
[517] | 5 | # -- Date: 08/25/2006 |
---|
[232] | 6 | # -- Name: tbroadcast |
---|
| 7 | # -- Description: main program |
---|
| 8 | #----------------------------------# |
---|
| 9 | |
---|
| 10 | import sys |
---|
[517] | 11 | import time |
---|
[232] | 12 | |
---|
[240] | 13 | def usage(): |
---|
[517] | 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 | """ |
---|
[240] | 38 | |
---|
[517] | 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 | |
---|
[232] | 44 | if __name__ == '__main__': |
---|
[508] | 45 | # check python version |
---|
| 46 | req_version = (2,5) |
---|
| 47 | cur_version = sys.version_info |
---|
| 48 | |
---|
[517] | 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) |
---|
[508] | 52 | |
---|
| 53 | from tbroadcast import Scheduler |
---|
| 54 | |
---|
[240] | 55 | # Default options |
---|
[243] | 56 | num_worker = 20 |
---|
| 57 | command = '' |
---|
[517] | 58 | version = 'v2.0.7' |
---|
[243] | 59 | test = False |
---|
| 60 | print_graph = False |
---|
| 61 | local = False |
---|
| 62 | ignore_cycles = False |
---|
[244] | 63 | silent = False |
---|
[517] | 64 | perf = False |
---|
| 65 | sort = False |
---|
[243] | 66 | output = None |
---|
[244] | 67 | error = None |
---|
[243] | 68 | file = None |
---|
[306] | 69 | make = None |
---|
| 70 | makefile = 'Makefile' |
---|
[393] | 71 | keep_going = True |
---|
[517] | 72 | |
---|
[259] | 73 | if len(sys.argv) == 1: |
---|
[517] | 74 | usage() |
---|
| 75 | sys.exit(-1) |
---|
| 76 | else: |
---|
| 77 | for arg in sys.argv[1:len(sys.argv)]: |
---|
| 78 | # print "Argument is",arg |
---|
[259] | 79 | if arg[0]=='-': |
---|
[517] | 80 | option = arg.split('=')[0] |
---|
[259] | 81 | if option == '-version': |
---|
| 82 | print version |
---|
| 83 | sys.exit(-1) |
---|
[517] | 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': |
---|
[259] | 99 | ignore_cycles = True |
---|
[517] | 100 | elif option == '-silent': |
---|
| 101 | silent = True |
---|
| 102 | elif option == '-no_keep_going': |
---|
[393] | 103 | keep_going = False |
---|
[517] | 104 | elif option == '-help': |
---|
| 105 | usage() |
---|
| 106 | sys.exit(-1) |
---|
| 107 | elif option == '-test': |
---|
| 108 | test = True |
---|
[259] | 109 | elif option == '-print': |
---|
[517] | 110 | print_graph = True |
---|
| 111 | elif option == '-make': |
---|
[306] | 112 | make = True |
---|
[517] | 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) |
---|
[259] | 119 | else: |
---|
[517] | 120 | command = arg |
---|
[240] | 121 | |
---|
[517] | 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) |
---|
[242] | 131 | if test: |
---|
| 132 | master.simulate_execution() |
---|
| 133 | elif print_graph: |
---|
[517] | 134 | master.print_dependencies() |
---|
[306] | 135 | elif make: |
---|
[517] | 136 | master.generate_make (makefile, command) |
---|
[242] | 137 | else: |
---|
[517] | 138 | print 'tbroadcast: start of job at', time.strftime('%d-%b-%Y %T') |
---|
[242] | 139 | master.execute_all (command) |
---|
[517] | 140 | print 'tbroadcast: end of job at', time.strftime('%d-%b-%Y %T') |
---|
| 141 | #sys.exit(-1) |
---|
[508] | 142 | #--------- EoF --------# |
---|