1 #!/usr/bin/env python3.2
3 # perform comparison of tags contents between planet-lab and onelab tags
8 from argparse import ArgumentParser
13 def __init__ (self, filename):
14 self.filename=filename
16 m_comment = re.compile('^\s*#')
17 m_empty = re.compile('^\s*$')
18 m_gitpath = re.compile(\
19 '^\s*(?P<module>[\w\.\-]+)-GITPATH\s*'+
20 ':=\s*git://(?P<host>[\w\.\-]+)/'+
21 '(?P<repo>[\w\.\-]+)(?P<tag>[@\w/:_\.\-]+)?\s*$')
22 m_svnpath = re.compile(\
23 '^\s*(?P<module>[\w\-]+)-SVNPATH\s*'+
24 ':=\s*http://(?P<host>[\w\.\-]+)/'+
25 '(?P<svnpath>[\w/:_\.\-]+)\s*$')
26 m_branch = re.compile(\
27 '^\s*(?P<module>[\w\.\-]+)-BRANCH\s*:=\s*(?P<branch>[\w]+)\s*$')
33 with open(self.filename) as i:
34 for line in i.readlines():
36 match=TagsFile.m_empty.match(line)
38 match=TagsFile.m_comment.match(line)
40 match=TagsFile.m_gitpath.match(line)
42 (module,host,repo,tag)=match.groups()
43 if tag: tag=tag.replace('@','')
44 if module in self.git: print ('Warning: duplicate GITPATH for',module,file=o)
47 match=TagsFile.m_svnpath.match(line)
49 (module,host,svnpath)=match.groups()
50 tag=svnpath.split('/')[-1]
51 if module in self.svn: print ('Warning: duplicate SVNPATH for',module,file=o)
54 match=TagsFile.m_branch.match(line)
56 (module,branch)=match.groups()
57 if module in self.branch: print ('Warning: duplicate BRANCH for',module,file=o)
58 self.branch[module]=branch
60 print ("%-020s"%"ignored",line,file=o)
61 # outputs relevant info
62 for n in ['branch','git','svn']:
66 for key in keys: print ("%-020s %-20s %s"%(n,key,d[key]),file=o)
68 def norm(self): return self.filename+'.norm'
71 with open(self.norm(),'w') as f:
73 print ("(Over)wrote",self.norm())
76 # $0 tagsfile1 tagsfile2
78 parser=ArgumentParser(description="Create a normalized (.norm) file for each input, may run diff on them")
79 parser.add_argument('tagsnames',
82 help="tags file names")
83 parser.add_argument("-d","--diff",action="store_true",dest="run_diff",default=False,
84 help="runs diff on the normalized outputs - requires exactly 2 args")
86 apres=parser.parse_args()
87 for tagsname in apres.tagsnames:
88 TagsFile(tagsname).parse()
89 if apres.run_diff and len(apres.tagsnames)==2:
90 tf1=TagsFile(apres.tagsnames[0])
91 tf2=TagsFile(apres.tagsnames[1])
92 print ("%s <-- --> %s"%(tf1.norm(),tf2.norm()))
93 command = "diff %s %s"%(tf1.norm(),tf2.norm())
94 subprocess.Popen(command,shell=True)
96 if __name__ == '__main__':