-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzp_log_parse
executable file
·101 lines (79 loc) · 3.55 KB
/
zp_log_parse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
import sys
import os
import re
import pprint
import subprocess
from clint.textui import puts, indent
from clint.textui.colored import red, green, white
import xml.etree.ElementTree as ET
SVN_REPO = "http://dev.zenoss.com/svnint"
SVN_RPS = "branches/core/zenoss-4.2.3-patches/packs"
SVN_BRANCH = "branches/zenoss-4.2.x/zenpacks"
def run(cmd, stdin=None):
try:
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT, stdin=stdin)
except Exception:
with indent(4):
puts(red("Error running command: ") + cmd)
raise
return output
def main(zenpack, stop_at_revision):
SVN_ZENPACK = os.path.join(SVN_REPO, SVN_BRANCH, zenpack)
svn_log_cmd = "svn -r0:%s log --xml --stop-on-copy %s" % (stop_at_revision, SVN_ZENPACK)
svn_xml_log_data = run(svn_log_cmd)
root = ET.fromstring(svn_xml_log_data)
revisions = dict()
jira_issue_pattern = re.compile(r'(ZEN\-\d+)', re.M | re.I)
for logentry in root:
commit_msg = logentry.find('msg').text
commit_revision = logentry.attrib['revision']
# find all jira issues referenced
jira_issues = []
jira_issues = jira_issue_pattern.findall(commit_msg)
# if more than one jira issue found, dump the whole message and let
# user decide which to use
if len(jira_issues) > 1:
puts(white(commit_revision + ': ') + red('Found more than one jira issue!'))
with indent(4):
puts(white("Commit message was:"))
puts(commit_msg)
jira_issue = raw_input("Use which issue number? ")
# prepend 'ZEN-' because typing it is annoying
revisions[commit_revision] = (commit_revision, 'ZEN-'+jira_issue, commit_msg.replace("\n", "^"))
elif len(jira_issues) == 1:
puts(white(commit_revision + ": Found one jira issue: ") + green(jira_issues[0]))
revisions[commit_revision] = (commit_revision, jira_issues[0], commit_msg.replace("\n", "^"))
else:
revisions[commit_revision] = (commit_revision, None, commit_msg.replace("\n", "^"))
puts("Done finding issues.")
revision_data = revisions.values()
revision_data.sort(key=lambda d: int(d[0]))
# print out the stuff so the human can see what's going on
for d in revision_data:
print "%s -> %s -> %s" % d
start = None
for changeset, ticket, message in revision_data:
if ticket is not None:
if start is not None:
svn_diff_cmd = "svn diff -r%s:%s %s" % (start, changeset, SVN_ZENPACK)
svn_diff = subprocess.Popen(svn_diff_cmd.split(), stdout=subprocess.PIPE)
output = subprocess.check_output(['filterdiff'], stdin=svn_diff.stdout)
svn_diff.wait()
puts(green("Filtered diff for revisions: %s:%s" % (start, changeset)))
with indent(4):
puts(output)
start = changeset
else:
if ticket is None:
print "Unable to find ticket for r%s:%s" % (start, changeset)
# after we get the diffs, probably shove into files
# after we get all the files, need to use 'patch' and apply them to the
# git repository, which we were assuming would be your current working
# directory. can make another command line arg for that if we really
# want.
if __name__ == '__main__':
# zp_log_parse ZenPack.zenoss.ZenPack 49762
zenpack = sys.argv[1]
stop_at_revision = sys.argv[2]
main(zenpack, stop_at_revision)