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