[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' |
---|
[306] | 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]' |
---|
[244] | 28 | print '# -output=<location> : Output directory to store output files with the form <package>_output.log' |
---|
| 29 | print '# -error=<location> : Output directory to store error output with the form <package>_error.log' |
---|
[248] | 30 | print '# -perf=<file> : Store for each package the time for executing the command in the <file> file' |
---|
| 31 | print '# -print : Print dependencies for each package' |
---|
[252] | 32 | print '# -version : version of tbroadcast' |
---|
[248] | 33 | print '# -silent : Disable print' |
---|
[242] | 34 | print '# -test : Simulate execution' |
---|
[240] | 35 | |
---|
[232] | 36 | if __name__ == '__main__': |
---|
[240] | 37 | # Default options |
---|
[243] | 38 | num_worker = 20 |
---|
| 39 | command = '' |
---|
[252] | 40 | version = 'HEAD' |
---|
[243] | 41 | test = False |
---|
| 42 | check = False |
---|
| 43 | print_graph = False |
---|
| 44 | local = False |
---|
| 45 | ignore_cycles = False |
---|
[244] | 46 | silent = False |
---|
[245] | 47 | perf = False |
---|
[243] | 48 | output = None |
---|
[244] | 49 | error = None |
---|
[243] | 50 | file = None |
---|
[306] | 51 | make = None |
---|
| 52 | makefile = 'Makefile' |
---|
[259] | 53 | |
---|
| 54 | if len(sys.argv) == 1: |
---|
| 55 | test = True |
---|
| 56 | else: |
---|
| 57 | for arg in sys.argv[1:len(sys.argv)]: |
---|
| 58 | if arg[0]=='-': |
---|
| 59 | option = string.split(arg,'=')[0] |
---|
| 60 | if option == '-version': |
---|
| 61 | print version |
---|
| 62 | sys.exit(-1) |
---|
| 63 | if option == '-nb': |
---|
| 64 | num_worker = int (string.split(arg,'=')[1]) |
---|
| 65 | if option == '-f': |
---|
| 66 | file = string.split(arg,'=')[1] |
---|
| 67 | if option == '-perf': |
---|
| 68 | perf = string.split(arg,'=')[1] |
---|
| 69 | if option == '-output': |
---|
| 70 | output = string.split(arg,'=')[1] |
---|
| 71 | if option == '-error': |
---|
| 72 | error = string.split(arg,'=')[1] |
---|
| 73 | if option == '-local': |
---|
| 74 | local= True |
---|
| 75 | if option == '-ignore_cycles': |
---|
| 76 | ignore_cycles = True |
---|
| 77 | if option == '-silent': |
---|
| 78 | silent = True |
---|
| 79 | if option == '-help': |
---|
| 80 | usage() |
---|
| 81 | sys.exit(-1) |
---|
| 82 | |
---|
| 83 | if option == '-test': |
---|
| 84 | test = True |
---|
| 85 | elif option == '-check': |
---|
| 86 | check = True |
---|
| 87 | elif option == '-print': |
---|
| 88 | print_graph = True |
---|
[306] | 89 | elif option == '-make': |
---|
| 90 | make = True |
---|
| 91 | makefile = string.split(arg,'=')[1] |
---|
[259] | 92 | else: |
---|
| 93 | command = arg |
---|
[240] | 94 | |
---|
[245] | 95 | master = Scheduler (num_workers=num_worker, file=file, ignore_cycles=ignore_cycles, local=local, output=output, error=error, silent=silent, perf=perf) |
---|
[242] | 96 | if test: |
---|
| 97 | master.simulate_execution() |
---|
| 98 | elif check: |
---|
| 99 | master.check_execution (package=master.get_current_package()) |
---|
| 100 | elif print_graph: |
---|
| 101 | master.print_dependencies () |
---|
[306] | 102 | elif make: |
---|
| 103 | master.generate_make (makefile, command) |
---|
[242] | 104 | else: |
---|
| 105 | master.execute_all (command) |
---|
[232] | 106 | sys.exit(-1); |
---|
[242] | 107 | #--------- EoF --------# |
---|