- def patch_tags_file (self, tagsfile, oldname, newname,fine_grain=True):
- newtagsfile=tagsfile+".new"
- tags=open (tagsfile)
- new=open(newtagsfile,"w")
-
- matches=0
- # fine-grain : replace those lines that refer to oldname
- if fine_grain:
- if self.options.verbose:
- print 'Replacing %s into %s\n\tin %s .. '%(oldname,newname,tagsfile),
- matcher=re.compile("^(.*)%s(.*)"%oldname)
- for line in tags.readlines():
- if not matcher.match(line):
- new.write(line)
- else:
- (begin,end)=matcher.match(line).groups()
- new.write(begin+newname+end+"\n")
- matches += 1
- # brute-force : change uncommented lines that define <module>-SVNPATH
- else:
- if self.options.verbose:
- print 'Searching for -SVNPATH or -GITPATH lines referring to /%s/\n\tin %s .. '%(self.name,tagsfile),
- pattern="\A\s*%s-(SVNPATH|GITPATH)\s*(=|:=)\s*(?P<url_main>[^\s]+)/%s[^\s]+"\
- %(self.name,self.name)
- matcher_module=re.compile(pattern)
- for line in tags.readlines():
- attempt=matcher_module.match(line)
- if attempt:
- if line.find("-GITPATH") >= 0:
- modulepath = "%s-GITPATH"%self.name
- replacement = "%-32s:= %s/%s.git@%s\n"%(modulepath,attempt.group('url_main'),self.name,newname)
- else:
- modulepath = "%s-SVNPATH"%self.name
- replacement = "%-32s:= %s/%s/tags/%s\n"%(modulepath,attempt.group('url_main'),self.name,newname)
+ def patch_tags_file (self, tagsfile, oldname, newname, fine_grain=True):
+ newtagsfile = "{}.new".format(tagsfile)
+
+ with open(tagsfile) as tags:
+ with open(newtagsfile,"w") as new:
+ matches = 0
+ # fine-grain : replace those lines that refer to oldname
+ if fine_grain: