This repository was archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogModuleFromTag.py
More file actions
executable file
·204 lines (185 loc) · 5.89 KB
/
logModuleFromTag.py
File metadata and controls
executable file
·204 lines (185 loc) · 5.89 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/env python
usage = """
usage:
logModuleFromTag.py module [tag1 [tag2]]
If tag1 and tag2 are supplied:
do 'svn log -v' for 'module' from 'tag1' to 'tag2',
If tag2 is omitted:
use 'trunk' for tag2
If tag1 is omitted:
Use most recent tag for tag1
"""
import sys
import commands
SVN="https://github.com/epics-modules"
IPAC_SVN="https://github.com/epics-modules"
ASYN_SVN="https://github.com/epics-modules"
def getSVN_ROOT(module):
if (module == "ipac"):
return IPAC_SVN
elif (module == "asyn"):
return ASYN_SVN
else:
return SVN
def tags(module, verbose=False):
"""
Return tags for a module in the synApps repository.
If verbose==False, return tags as a list; ['R1-0', 'R1-1']
else, return tags as a dictionary of dictionaries:
{'.': {'date': ('Mar', '30', '13:32'), 'rev': '10457', 'author': 'mooney'},
'R1-3': {'date': ('Mar', '30', '13:20'), 'rev': '10456', 'author': 'mooney'}}
"""
SVN_ROOT = getSVN_ROOT(module)
if verbose:
tagListRaw = commands.getoutput("svn ls -v %s/%s/tags" % (SVN_ROOT,module)).split('\n')
tagDict = {}
for tag in tagListRaw:
(rev, author, month, day, year_time, tagName) = tag.split()
tagDict[tagName.strip('/')] = {'rev':rev, 'author':author, 'date':(month, day, year_time)}
return(tagDict)
else:
tagListRaw = commands.getoutput("svn ls %s/%s/tags" % (SVN_ROOT,module)).split()
tagList = []
for tag in tagListRaw:
tagList.append(tag.strip('/'))
return(tagList)
def highestRevisionNum(module, dir):
SVN_ROOT = getSVN_ROOT(module)
maxRev = -1
maxTag = "None"
revDate = "None"
tagList = commands.getoutput("svn ls -v %s/%s/%s" % (SVN_ROOT,module,dir)).split('\n')
#print "tagList:", tagList
for tag in tagList:
words = tag.split()
thisRev = int(words[0])
thisTag = words[5]
if (thisRev > maxRev) and (thisTag != "./"):
maxTag = words[5][:-1] # strip trailing slash
maxRev = thisRev
revDate = " ".join(words[2:5])
return (maxRev, maxTag, revDate)
def log(module, tag1=None, tag2=None):
# Find the difference between tag1 and tag2, or between tag1 and trunk
SVN_ROOT = getSVN_ROOT(module)
if tag2 == None:
if tag1 == None:
(tagRevNum, tag1, date1) = highestRevisionNum(module, 'tags')
print "Most recent tag (revision) is %s (%d) on %s" % (tag1, tagRevNum, date1)
else:
reply = commands.getoutput("svn ls -v %s/%s/%s" % (SVN_ROOT,module,'tags/'+tag1))
tagList = reply.split('\n')
words = tagList[0].split()
try:
(tagRevNum, date1) = (int(words[0]), " ".join(words[2:5]))
except:
print "* * * Error: '%s', using most recent tag instead\n" % reply
(tagRevNum, tag1, date1) = highestRevisionNum(module, 'tags')
(trunkRevNum, xx, date2) = highestRevisionNum(module, 'trunk')
print "log from tag '%s' (%s on %s) to trunk (%s on %s)" % (tag1, tagRevNum, date1, trunkRevNum, date2)
if (tagRevNum > trunkRevNum):
l = "No changes"
else:
l = commands.getoutput("svn log -v -r %d:%d %s/%s" % (tagRevNum, trunkRevNum, SVN_ROOT, module))
else:
(tag1RevNum, xx, date1) = highestRevisionNum(module, 'tags/'+tag1)
(tag2RevNum, xx, date2) = highestRevisionNum(module, 'tags/'+tag2)
print "log from tag '%s' (%s) to tag '%s' (%s)" % (tag1, date1, tag2, date2)
l = commands.getoutput("svn log -v -r %d:%d %s/%s" % (tag1RevNum, tag2RevNum, SVN_ROOT, module))
l = l.split('\n')
return(l)
typeName = {'A': 'Added',
'C': 'Conflicted',
'D': 'Deleted',
'I': 'Ignored',
'M': 'Modified',
'R': 'Replaced',
'X': 'unversioned external',
'?': 'unknown',
'!': 'missing'}
def parseLog(lines, debug=False):
revisions = {}
currRev = None
section = None
for l in lines:
if debug>1: print("LINE='%s'" % l)
if len(l) == 0:
if debug>1: print('ignored')
if section == 'files': section = 'message'
continue
if l[0] == '-' and l.strip('-') == '':
if debug>1: print('separator')
currRev = None
section = None
continue
if currRev == None and l[0] == 'r':
currRev = l.split()[0]
if debug: print("revision:'%s'" % currRev)
revisions[currRev] = {'files':[], 'message':[]}
continue
if currRev and l == 'Changed paths:':
section = 'files'
if debug>1: print('ignored')
continue
if currRev and (section == 'files') and l[0].isspace():
(typeLetter,file) = l.lstrip(' ').split(' ', 1)
type = typeName[typeLetter]
if file.count(' '):
file = file.split(' ',1)[0]
if debug: print(" type ='%s', file = '%s'" % (type, file))
revisions[currRev]['files'].append([type, file])
continue
if currRev and (section == 'message'):
if debug: print(" commit message:'%s'" % l)
revisions[currRev]['message'].append(l)
return(revisions)
import os
def printRevisions(revs):
for key in revs.keys():
print(key)
for f in revs[key]['files']:
print("\t%s %s" % (f[0],os.path.basename(f[1])))
for m in revs[key]['message']:
print("\t%s" % m)
import sys
def printRevisionsHTML(revs,file=None):
if file == None:
fp = sys.stdout
else:
fp = open(file,'w')
fp.write("<html>\n")
fp.write("<body>\n")
fp.write('<dl>\n')
for key in revs.keys():
if (len(revs[key]['message'])) > 0 and (
revs[key]['message'][0][:39] == "This commit was manufactured by cvs2svn"):
continue
fp.write('\n<p><dt>')
for f in revs[key]['files']:
fp.write("%s %s<br>\n" % (f[0],os.path.basename(f[1])))
fp.write('<dd>')
for m in revs[key]['message']:
fp.write("<br>%s\n" % m)
fp.write('</dl>\n')
fp.write("</body>\n")
fp.write("</html>\n")
fp.close()
def main():
#print "sys.arvg:", sys.argv
if len(sys.argv) == 4:
s = log(sys.argv[1], sys.argv[2], sys.argv[3])
for line in s: print(line)
elif len(sys.argv) == 3:
s=log(sys.argv[1], sys.argv[2])
for line in s: print(line)
elif len(sys.argv) == 2:
s=log(sys.argv[1])
for line in s: print(line)
# elif len(sys.argv) == 2:
# s=tags(sys.argv[1])
# for line in s: print(line)
else:
print (usage)
return
if __name__ == "__main__":
main()