1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """ This module defines helper functions to be used in python Ant tasks. """
21
22
23 import logging
24 import re
25 import os.path
26
27
29 """ This function return None if a property has not been replaced by Ant. """
30 if len(property_name) > 0 and property_name.startswith('${'):
31 return None
32 return property_name
33
34
36 """ Determines the previous build number if possible. """
37 match = re.match(r'(?P<bn_txt>\w[a-zA-Z0-9_.]*\.)?(?P<bn_num>\d+)', build_number)
38 if match != None:
39 bn_txt = match.group('bn_txt')
40 bn_num = match.group('bn_num')
41 try:
42 bn_num_int = int(bn_num)
43 if bn_num_int > 1:
44 previous_bn_num_int = bn_num_int - 1
45 previous_bn_num = str(previous_bn_num_int).rjust(len(bn_num), '0')
46 previous_bn = previous_bn_num
47 if bn_txt != None:
48 previous_bn = '%s%s' % (bn_txt, previous_bn_num)
49 return previous_bn
50 except ValueError:
51 logging.warning('Parsing of Ant build number failed.')
52 return ''
53
54
56 """ Determines the next build number if possible. """
57 match = re.match(r'(?P<bn_txt>\w[a-zA-Z0-9_.]*\.)?(?P<bn_num>\d+)', build_number)
58 if match != None:
59 bn_txt = match.group('bn_txt')
60 bn_num = match.group('bn_num')
61 try:
62 bn_num_int = int(bn_num)
63 previous_bn_num_int = bn_num_int + 1
64 previous_bn_num = str(previous_bn_num_int).rjust(len(bn_num), '0')
65 previous_bn = previous_bn_num
66 if bn_txt != None:
67 previous_bn = '%s%s' % (bn_txt, previous_bn_num)
68 return previous_bn
69 except ValueError:
70 logging.warning('Parsing of Ant build number failed.')
71 return ''
72
73 -def get_filesets_content(project, task, elements):
74 """ Extract all files selected by the filesets in a script's elements. """
75 for eid in range(elements.get("fileset").size()):
76 dirscanner = elements.get("fileset").get(int(eid)).getDirectoryScanner(project)
77 dirscanner.scan()
78 for jfilename in dirscanner.getIncludedFiles():
79 filename = str(jfilename)
80 task.log("Parsing %s" % filename)
81 filename = os.path.join(str(dirscanner.getBasedir()), filename)
82
83
85 """ Implement a logger hanlder that prints error message using an Ant object.
86 See Python documentation on how to use it.
87 e.g:
88 logging.getLogger("").addHandler(AntHandler(anttask))
89 This line will redirect messages to Ant logging system.
90 """
91 - def __init__(self, task, level=logging.NOTSET):
94
95 - def emit(self, record):
96 """ Handle the recordusing Ant. """
97 self._task.log(str(record.getMessage()))
98