Mercurial > bitten > bitten-test
annotate scripts/build.py @ 162:8d071396dc1f
Forgot to add new module in [169].
author | cmlenz |
---|---|
date | Sat, 27 Aug 2005 07:32:37 +0000 |
parents | 3ab91c56d7bc |
children | 634be6cbb808 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
5 | 2 # -*- coding: iso8859-1 -*- |
3 # | |
4 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de> | |
5 # | |
6 # Bitten is free software; you can redistribute it and/or | |
7 # modify it under the terms of the GNU General Public License as | |
8 # published by the Free Software Foundation; either version 2 of the | |
9 # License, or (at your option) any later version. | |
10 # | |
11 # Trac is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 # General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 # | |
20 # Author: Christopher Lenz <cmlenz@gmx.de> | |
0 | 21 |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
22 import itertools |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
23 import logging |
4 | 24 import sys |
0 | 25 |
61
47ab019508dd
Moved {{{BuildError}}} class into package {{{bitten.build}}}.
cmlenz
parents:
60
diff
changeset
|
26 from bitten.build import BuildError |
4 | 27 from bitten.recipe import Recipe |
148
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
28 from bitten.util import xmlio |
4 | 29 |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
30 def main(): |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
31 from bitten import __version__ as VERSION |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
32 from optparse import OptionParser |
4 | 33 |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
34 parser = OptionParser(usage='usage: %prog [options] [step1] [step2] ...', |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
35 version='%%prog %s' % VERSION) |
148
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
36 parser.add_option('-f', '--recipe-file', action='store', dest='recipe_file', |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
37 metavar='FILE', help='read build recipe from FILE') |
144
76dea27af878
* Make the `<python:unittest>` command strip the base dir from file names in the report. Fixes #42.
cmlenz
parents:
131
diff
changeset
|
38 parser.add_option('--print-reports', action='store_const', |
76dea27af878
* Make the `<python:unittest>` command strip the base dir from file names in the report. Fixes #42.
cmlenz
parents:
131
diff
changeset
|
39 dest='print_reports', const=True, |
76dea27af878
* Make the `<python:unittest>` command strip the base dir from file names in the report. Fixes #42.
cmlenz
parents:
131
diff
changeset
|
40 help='print generated reports') |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
41 parser.add_option('-v', '--verbose', action='store_const', dest='loglevel', |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
42 const=logging.DEBUG, help='print as much as possible') |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
43 parser.add_option('-q', '--quiet', action='store_const', dest='loglevel', |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
44 const=logging.ERROR, help='print as little as possible') |
148
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
45 parser.set_defaults(loglevel=logging.INFO, recipe_file='recipe.xml') |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
46 options, args = parser.parse_args() |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
47 |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
48 log = logging.getLogger('bitten') |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
49 log.setLevel(options.loglevel) |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
50 handler = logging.StreamHandler() |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
51 handler.setLevel(options.loglevel) |
109
5bf22bb87915
Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents:
103
diff
changeset
|
52 formatter = logging.Formatter('%(message)s') |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
53 handler.setFormatter(formatter) |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
54 log.addHandler(handler) |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
55 |
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
56 steps_to_run = dict([(step, False) for step in args]) |
148
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
57 |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
58 recipe_file = file(options.recipe_file, 'r') |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
59 try: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
60 recipe = Recipe(xmlio.parse(recipe_file)) |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
61 for step in recipe: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
62 if not steps_to_run or step.id in steps_to_run: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
63 print |
153 | 64 print '-->', step.id |
148
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
65 for type, function, output in step.execute(recipe.ctxt): |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
66 if type == Recipe.ERROR: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
67 log.error('Failure in step "%s": %s', step.id, output) |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
68 elif type == Recipe.REPORT and options.print_reports: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
69 output.write(sys.stdout, newlines=True) |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
70 if step.id in steps_to_run: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
71 steps_to_run[step.id] = True |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
72 finally: |
f3f5895e373c
Fixes to problems in recipe handling introduced in [155].
cmlenz
parents:
144
diff
changeset
|
73 recipe_file.close() |
0 | 74 |
75 if __name__ == '__main__': | |
4 | 76 try: |
103
f1baf05a49dd
* Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents:
72
diff
changeset
|
77 main() |
4 | 78 except BuildError, e: |
153 | 79 print |
8 | 80 print>>sys.stderr, 'FAILED: %s' % e |
4 | 81 sys.exit(-1) |
153 | 82 print |
8 | 83 print 'SUCCESS' |