-
Notifications
You must be signed in to change notification settings - Fork 26
/
git-cms-showtags
executable file
·63 lines (55 loc) · 2.22 KB
/
git-cms-showtags
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
#!/bin/bash
""":"
python_cmd="python"
python3 -V >/dev/null 2>&1 && python_cmd="python3"
exec ${python_cmd} $0 ${1+"$@"}
"""
from optparse import OptionParser
from commands import getstatusoutput
from os import environ
from os.path import join, exists
from sys import exit
def format(s, **kwds):
return s % kwds
if __name__ == "__main__":
parser = OptionParser()
opts, args = parser.parse_args()
if not "CMSSW_VERSION" in environ:
parser.error("You do not have CMSSW environment setup. Please do cmsenv.")
if not "CMSSW_BASE" in environ:
parser.error("You need to be in a CMSSW workarea for this. Create one with scram project CMSSW_X_Y_Z.")
if 'CMSSW_GIT_HASH' in environ:
cmssw_tag = environ['CMSSW_GIT_HASH']
else:
cmssw_tag = environ['CMSSW_VERSION']
# If no git area is found. We are in a vanilla area.
if not exists(join(environ["CMSSW_BASE"], "src/.git")):
parser.error("You do not have any code checked out WRT the release")
cmd = "cd $CMSSW_BASE/src ; git ls-tree --abbrev -d -r %(tag)s"
error, out = getstatusoutput(format(cmd, tag="HEAD"))
if error:
parser.error("Error while getting tags for the current working area")
lines = [x.replace("\t", " ") for x in out.split("\n") if x.count("/") == 1]
table = [x.split(" ") for x in lines if x]
baseTags = dict([(x[3], x[2]) for x in table])
error, out = getstatusoutput(format(cmd, tag = cmssw_tag))
if error:
parser.error("Error while getting tags for this CMSSW release, %s" % cmssw_tag)
lines = [x.replace("\t", " ") for x in out.split("\n") if x.count("/") == 1]
table = [x.split(" ") for x in lines if x]
newTags = dict([(x[3], x[2]) for x in table])
minPkg = max([len(x) for x in baseTags])
minTag = max([len(x) for x in baseTags.itervalues()])
for (k,v) in sorted(baseTags.iteritems()):
if not k in newTags:
print (format("%(package)s\t%(old)s\t%(new)s",
package=k.ljust(minPkg, " "),
old=v.ljust(minTag, " "),
new="REMOVED"))
continue
if newTags[k] == v:
continue
print (format("%(package)s\t%(old)s\t%(new)s",
package=k.ljust(minPkg, " "),
old=v.ljust(minTag, " "),
new=newTags[k]))