-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnorm-tags.py
executable file
·97 lines (87 loc) · 3.56 KB
/
norm-tags.py
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
#!/usr/bin/env python3.2
#
# perform comparison of tags contents between planet-lab and onelab tags
#
import sys
import re
from argparse import ArgumentParser
import subprocess
class TagsFile:
def __init__ (self, filename):
self.filename=filename
m_comment = re.compile('^\s*#')
m_empty = re.compile('^\s*$')
m_gitpath = re.compile(\
'^\s*(?P<module>[\w\.\-]+)-GITPATH\s*'+
':=\s*git://(?P<host>[\w\.\-]+)/'+
'(?P<repo>[\w\.\-]+)(?P<tag>[@\w/:_\.\-]+)?\s*$')
m_svnpath = re.compile(\
'^\s*(?P<module>[\w\-]+)-SVNPATH\s*'+
':=\s*http://(?P<host>[\w\.\-]+)/'+
'(?P<svnpath>[\w/:_\.\-]+)\s*$')
m_branch = re.compile(\
'^\s*(?P<module>[\w\.\-]+)-BRANCH\s*:=\s*(?P<branch>[\w]+)\s*$')
def _parse (self,o):
self.git={}
self.svn={}
self.branch={}
with open(self.filename) as i:
for line in i.readlines():
line=line.strip()
match=TagsFile.m_empty.match(line)
if match: continue
match=TagsFile.m_comment.match(line)
if match: continue
match=TagsFile.m_gitpath.match(line)
if match:
(module,host,repo,tag)=match.groups()
if tag: tag=tag.replace('@','')
if module in self.git: print ('Warning: duplicate GITPATH for',module,file=o)
self.git[module]=tag
continue
match=TagsFile.m_svnpath.match(line)
if match:
(module,host,svnpath)=match.groups()
tag=svnpath.split('/')[-1]
if module in self.svn: print ('Warning: duplicate SVNPATH for',module,file=o)
self.svn[module]=tag
continue
match=TagsFile.m_branch.match(line)
if match:
(module,branch)=match.groups()
if module in self.branch: print ('Warning: duplicate BRANCH for',module,file=o)
self.branch[module]=branch
continue
print ("%-020s"%"ignored",line,file=o)
# outputs relevant info
for n in ['branch','git','svn']:
d=getattr(self,n)
keys=list(d.keys())
keys.sort()
for key in keys: print ("%-020s %-20s %s"%(n,key,d[key]),file=o)
def norm(self): return self.filename+'.norm'
def parse(self):
with open(self.norm(),'w') as f:
self._parse(f)
print ("(Over)wrote",self.norm())
# basic usage for now
# $0 tagsfile1 tagsfile2
def main ():
parser=ArgumentParser(description="Create a normalized (.norm) file for each input, may run diff on them")
parser.add_argument('tagsnames',
metavar='tagsfile',
nargs='+',
help="tags file names")
parser.add_argument("-d","--diff",action="store_true",dest="run_diff",default=False,
help="runs diff on the normalized outputs - requires exactly 2 args")
apres=parser.parse_args()
for tagsname in apres.tagsnames:
TagsFile(tagsname).parse()
if apres.run_diff and len(apres.tagsnames)==2:
tf1=TagsFile(apres.tagsnames[0])
tf2=TagsFile(apres.tagsnames[1])
print ("%s <-- --> %s"%(tf1.norm(),tf2.norm()))
command = "diff %s %s"%(tf1.norm(),tf2.norm())
subprocess.Popen(command,shell=True)
if __name__ == '__main__':
main()