8 CHANGE_LOG_ARG = 'changes'
11 search = re.compile('^(Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)', re.MULTILINE)
13 searchStartInsert = re.compile('^\.\. INSERT CHANGE LOG HERE', re.MULTILINE)
14 searchEndInsert = re.compile('^\.\. END INSERT CHANGE LOG', re.MULTILINE)
17 .. INSERT CHANGE LOG HERE
18 .. END INSERT CHANGE LOG
21 def getBuildCount(data):
22 """returns number of latest build (a.k.a. total number of builds)
24 return len(search.findall(data))
27 def process(filePath, buildsToShow=BUILDS_TO_SHOW):
28 p = subprocess.Popen([COMMAND, CHANGE_LOG_ARG], stdout=subprocess.PIPE)
30 data = p.stdout.read()
31 buildCount = getBuildCount(data)
33 buildNumIter = iter(range(buildCount, 0, -1))
37 for line in data.split('\n'):
38 #Find a new build or move on
39 if not search.search(line):
42 if count < buildsToShow:
43 new_data.append('Build: %s - %s\n' % (buildNumIter.next(), line))
48 #Time to insert changelog
49 f = open(filePath, 'r')
53 new_data = ".. INSERT CHANGE LOG HERE\n\n::\n\n " \
54 + '\n '.join(new_data) + "\n.. END INSERT CHANGE LOG\n"
56 moStart = searchStartInsert.search(dataInsert)
57 moEnd = searchEndInsert.search(dataInsert)
59 if moStart is None or moEnd is None:
60 msg = 'Document %s must have the folling within the file: %s' % (filePath, MUST_HAVE)
63 data = dataInsert[:moStart.start()] + new_data + dataInsert[moEnd.end():]
65 f = open(filePath, 'w')
71 if __name__ == '__main__':
72 if len(sys.argv) != 3:
73 print 'Usage: %s <n_builds_to_show> <insert_into_filename> ' % (sys.argv[0])
76 filePath = sys.argv[2]
77 buildsToShow = int(sys.argv[1])
78 process(filePath, buildsToShow)