[240] | 1 | #!/usr/bin/env python |
---|
[232] | 2 | #----------------------------------# |
---|
[242] | 3 | # -- Author: V. Garonne |
---|
| 4 | # -- Mail: garonne@lal.in2p3.fr |
---|
[232] | 5 | # -- Date: 08/25/2006 |
---|
| 6 | # -- Name: tbroadcast |
---|
| 7 | # -- Description: main program |
---|
| 8 | #----------------------------------# |
---|
| 9 | |
---|
| 10 | import os |
---|
| 11 | import sys |
---|
[234] | 12 | import string |
---|
[232] | 13 | |
---|
[240] | 14 | def usage(): |
---|
| 15 | print 'Usage : > tbroadcast [global options] [<command>]' |
---|
| 16 | print '# command :' |
---|
| 17 | print '# <command>: command to execute' |
---|
| 18 | print '# global options :' |
---|
[243] | 19 | print '# -f=<file> : Input file' |
---|
| 20 | print '# -help : Print help' |
---|
[248] | 21 | print '# -local : Reach packages only within the current project' |
---|
| 22 | print '# -global : Reach packages in all CMTPATH/CMTPROJECTPATH items' |
---|
| 23 | print '# -ignore_cycles : Suppress automatically the cycles' |
---|
[393] | 24 | print '# -make=<file> : Generate a recursive Make, [see: http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html]' |
---|
[248] | 25 | print '# -nb=<num_worker> : Change the total number of threads[default is 20]' |
---|
[393] | 26 | print '# -no_keep_going : Exit after the first exit code > 1 found and return it in the shell' |
---|
[244] | 27 | print '# -output=<location> : Output directory to store output files with the form <package>_output.log' |
---|
| 28 | print '# -error=<location> : Output directory to store error output with the form <package>_error.log' |
---|
[248] | 29 | print '# -perf=<file> : Store for each package the time for executing the command in the <file> file' |
---|
| 30 | print '# -print : Print dependencies for each package' |
---|
[252] | 31 | print '# -version : version of tbroadcast' |
---|
[248] | 32 | print '# -silent : Disable print' |
---|
[242] | 33 | print '# -test : Simulate execution' |
---|
[240] | 34 | |
---|
[232] | 35 | if __name__ == '__main__': |
---|
[508] | 36 | # check python version |
---|
| 37 | req_version = (2,5) |
---|
| 38 | cur_version = sys.version_info |
---|
| 39 | |
---|
| 40 | if not (cur_version[0] > req_version[0] or (cur_version[0] == req_version[0] and cur_version[1] >= req_version[1])): |
---|
| 41 | raise "must use python 2.5 or greater" |
---|
| 42 | |
---|
| 43 | from tbroadcast import Scheduler |
---|
| 44 | |
---|
[240] | 45 | # Default options |
---|
[243] | 46 | num_worker = 20 |
---|
| 47 | command = '' |
---|
[511] | 48 | version = 'v2.0.6' |
---|
[243] | 49 | test = False |
---|
| 50 | check = False |
---|
| 51 | print_graph = False |
---|
| 52 | local = False |
---|
| 53 | ignore_cycles = False |
---|
[244] | 54 | silent = False |
---|
[245] | 55 | perf = False |
---|
[243] | 56 | output = None |
---|
[244] | 57 | error = None |
---|
[243] | 58 | file = None |
---|
[306] | 59 | make = None |
---|
| 60 | makefile = 'Makefile' |
---|
[393] | 61 | keep_going = True |
---|
[259] | 62 | |
---|
| 63 | if len(sys.argv) == 1: |
---|
| 64 | test = True |
---|
| 65 | else: |
---|
| 66 | for arg in sys.argv[1:len(sys.argv)]: |
---|
| 67 | if arg[0]=='-': |
---|
| 68 | option = string.split(arg,'=')[0] |
---|
| 69 | if option == '-version': |
---|
| 70 | print version |
---|
| 71 | sys.exit(-1) |
---|
| 72 | if option == '-nb': |
---|
| 73 | num_worker = int (string.split(arg,'=')[1]) |
---|
| 74 | if option == '-f': |
---|
| 75 | file = string.split(arg,'=')[1] |
---|
| 76 | if option == '-perf': |
---|
| 77 | perf = string.split(arg,'=')[1] |
---|
| 78 | if option == '-output': |
---|
| 79 | output = string.split(arg,'=')[1] |
---|
| 80 | if option == '-error': |
---|
| 81 | error = string.split(arg,'=')[1] |
---|
| 82 | if option == '-local': |
---|
| 83 | local= True |
---|
| 84 | if option == '-ignore_cycles': |
---|
| 85 | ignore_cycles = True |
---|
| 86 | if option == '-silent': |
---|
[393] | 87 | silent = True |
---|
| 88 | if option == '-no_keep_going': |
---|
| 89 | keep_going = False |
---|
| 90 | |
---|
[259] | 91 | if option == '-help': |
---|
| 92 | usage() |
---|
| 93 | sys.exit(-1) |
---|
| 94 | |
---|
| 95 | if option == '-test': |
---|
| 96 | test = True |
---|
| 97 | elif option == '-check': |
---|
| 98 | check = True |
---|
| 99 | elif option == '-print': |
---|
| 100 | print_graph = True |
---|
[306] | 101 | elif option == '-make': |
---|
| 102 | make = True |
---|
| 103 | makefile = string.split(arg,'=')[1] |
---|
[259] | 104 | else: |
---|
| 105 | command = arg |
---|
[240] | 106 | |
---|
[393] | 107 | master = Scheduler (num_workers=num_worker, file=file, ignore_cycles=ignore_cycles, |
---|
| 108 | local=local, output=output, error=error, silent=silent, perf=perf, |
---|
| 109 | keep_going=keep_going) |
---|
[242] | 110 | if test: |
---|
| 111 | master.simulate_execution() |
---|
| 112 | elif check: |
---|
| 113 | master.check_execution (package=master.get_current_package()) |
---|
| 114 | elif print_graph: |
---|
| 115 | master.print_dependencies () |
---|
[306] | 116 | elif make: |
---|
| 117 | master.generate_make (makefile, command) |
---|
[242] | 118 | else: |
---|
| 119 | master.execute_all (command) |
---|
[393] | 120 | #sys.exit(-1); |
---|
[508] | 121 | #--------- EoF --------# |
---|