annotate scripts/build.py @ 131:3ed8f568f60a

Fix error handling so that reports are still generated even if a command has failed.
author cmlenz
date Fri, 12 Aug 2005 19:11:16 +0000
parents 5bf22bb87915
children 76dea27af878
rev   line source
0
0b2a3581c48d Import initial ''bitten'' source.
cmlenz
parents:
diff changeset
1 #!/usr/bin/env python
5
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
2 # -*- coding: iso8859-1 -*-
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
3 #
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
4 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
5 #
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
6 # Bitten is free software; you can redistribute it and/or
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
7 # modify it under the terms of the GNU General Public License as
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
8 # published by the Free Software Foundation; either version 2 of the
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
9 # License, or (at your option) any later version.
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
10 #
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
11 # Trac is distributed in the hope that it will be useful,
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
14 # General Public License for more details.
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
15 #
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
16 # You should have received a copy of the GNU General Public License
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
17 # along with this program; if not, write to the Free Software
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
19 #
738a0ae251f6 Added GPL boilerplate.
cmlenz
parents: 4
diff changeset
20 # Author: Christopher Lenz <cmlenz@gmx.de>
0
0b2a3581c48d Import initial ''bitten'' source.
cmlenz
parents:
diff changeset
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
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
24 import sys
0
0b2a3581c48d Import initial ''bitten'' source.
cmlenz
parents:
diff changeset
25
61
47ab019508dd Moved {{{BuildError}}} class into package {{{bitten.build}}}.
cmlenz
parents: 60
diff changeset
26 from bitten.build import BuildError
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
27 from bitten.recipe import Recipe
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
28
103
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
29 def main():
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
30 from bitten import __version__ as VERSION
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
31 from optparse import OptionParser
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
32
103
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
33 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
34 version='%%prog %s' % VERSION)
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
35 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
36 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
37 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
38 const=logging.ERROR, help='print as little as possible')
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
39 parser.set_defaults(loglevel=logging.INFO)
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
40 options, args = parser.parse_args()
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
41
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
42 log = logging.getLogger('bitten')
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
43 log.setLevel(options.loglevel)
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
44 handler = logging.StreamHandler()
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
45 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
46 formatter = logging.Formatter('%(message)s')
103
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
47 handler.setFormatter(formatter)
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
48 log.addHandler(handler)
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
49
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
50 steps_to_run = dict([(step, False) for step in args])
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
51 recipe = Recipe()
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
52 for step in recipe:
103
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
53 if not steps_to_run or step.id in steps_to_run:
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 103
diff changeset
54 print
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
55 print '-->', step.description or step.id
109
5bf22bb87915 Transmit build log and generated data back to the build master in XML format. Closes #23.
cmlenz
parents: 103
diff changeset
56 for type, function, output in step.execute(recipe.ctxt):
131
3ed8f568f60a Fix error handling so that reports are still generated even if a command has failed.
cmlenz
parents: 109
diff changeset
57 if type == Recipe.ERROR:
3ed8f568f60a Fix error handling so that reports are still generated even if a command has failed.
cmlenz
parents: 109
diff changeset
58 log.error('Failure in step "%s": %s', step.id, output)
103
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
59 if step.id in steps_to_run:
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
60 steps_to_run[step.id] = True
0
0b2a3581c48d Import initial ''bitten'' source.
cmlenz
parents:
diff changeset
61
0b2a3581c48d Import initial ''bitten'' source.
cmlenz
parents:
diff changeset
62 if __name__ == '__main__':
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
63 try:
103
f1baf05a49dd * Strip extra line separators from recipe command output on windows. Closes #25.
cmlenz
parents: 72
diff changeset
64 main()
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
65 except BuildError, e:
8
45d7bfe64d00 Slightly improved implementation of the python tools.
cmlenz
parents: 5
diff changeset
66 print>>sys.stderr, 'FAILED: %s' % e
4
196009657e5e Simplify the recipe commands interface:
cmlenz
parents: 3
diff changeset
67 sys.exit(-1)
8
45d7bfe64d00 Slightly improved implementation of the python tools.
cmlenz
parents: 5
diff changeset
68 print 'SUCCESS'
Copyright (C) 2012-2017 Edgewall Software