X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=module-tools.py;h=1a7ad8e2c5e8b6f9a7ee1d9196ae7aa8e81e96cb;hb=d042c265a1c2459918d5c5dd510ffa973c880c76;hp=933f436af66305a484d5b9ce4bc5f1aaa632f898;hpb=f3607d1e08b97e2b3cd0d4fced26b0e9df8989db;p=build.git diff --git a/module-tools.py b/module-tools.py index 933f436a..1a7ad8e2 100755 --- a/module-tools.py +++ b/module-tools.py @@ -48,6 +48,13 @@ def prompt (question,default=True,other_choices=[],allow_outside=False): except: raise +def default_editor(): + try: + editor = os.environ['EDITOR'] + except: + editor = "emacs" + return editor + class Command: def __init__ (self,command,options): self.command=command @@ -66,7 +73,7 @@ class Command: sys.stdout.flush() retcod=os.system(self.command + " &> " + self.tmp) if retcod != 0: - print "FAILED ! -- output quoted below " + print "FAILED ! -- out+err below (command was %s)"%self.command os.system("cat " + self.tmp) print "FAILED ! -- end of quoted output" elif self.options.verbose: @@ -143,7 +150,7 @@ class Module: # for parsing module spec name:branch - matcher_branch_spec=re.compile("\A(?P[\w-]+):(?P[\w\.]+)\Z") + matcher_branch_spec=re.compile("\A(?P[\w-]+):(?P[\w\.-]+)\Z") matcher_rpm_define=re.compile("%(define|global)\s+(\S+)\s+(\S*)\s*") def __init__ (self,module_spec,options): @@ -246,8 +253,7 @@ that for other purposes than tagging"""%topdir if not os.path.isdir (self.moddir): self.run_fatal("svn up -N %s"%self.moddir) if not os.path.isdir (self.moddir): - print 'Cannot find %s - check module name'%self.moddir - sys.exit(1) + raise Exception, 'Cannot find %s - check module name'%self.moddir def init_subdir (self,fullpath): if self.options.verbose: @@ -292,8 +298,7 @@ that for other purposes than tagging"""%topdir try: return glob("%s/*.spec"%self.edge_dir())[0] except: - print 'Cannot guess specfile for module %s'%self.name - sys.exit(1) + raise Exception, 'Cannot guess specfile for module %s'%self.name def all_specnames (self): return glob("%s/*.spec"%self.edge_dir()) @@ -366,8 +371,8 @@ that for other purposes than tagging"""%topdir for (key,was_changed) in changed.iteritems(): if not was_changed: if self.options.debug: - print 'rewriting missed %s as %s'%(key,patch_dict[key]) - new.write('%%define %s %s\n'%(key,patch_dict[key])) + print 'rewriting missing %s as %s'%(key,patch_dict[key]) + new.write('\n%%define %s %s\n'%(key,patch_dict[key])) spec.close() new.close() os.rename(newspecfile,specfile) @@ -375,11 +380,16 @@ that for other purposes than tagging"""%topdir def unignored_lines (self, logfile): result=[] exclude="Tagging module %s"%self.name + white_line_matcher = re.compile("\A\s*\Z") for logline in file(logfile).readlines(): if logline.strip() == Module.svn_magic_line: break - if logline.find(exclude) < 0: - result += [ logline ] + if logline.find(exclude) >= 0: + continue + elif white_line_matcher.match(logline): + continue + else: + result.append(logline.strip()+'\n') return result def insert_changelog (self, logfile, oldtag, newtag): @@ -394,9 +404,9 @@ that for other purposes than tagging"""%topdir if re.compile('%changelog').match(line): dateformat="* %a %b %d %Y" datepart=time.strftime(dateformat) - logpart="%s <%s> - %s %s"%(Module.config['username'], + logpart="%s <%s> - %s"%(Module.config['username'], Module.config['email'], - oldtag,newtag) + newtag) new.write(datepart+" "+logpart+"\n") for logline in self.unignored_lines(logfile): new.write("- " + logline) @@ -426,8 +436,7 @@ that for other purposes than tagging"""%topdir spec_dict[self.module_version_varname], spec_dict[self.module_taglevel_varname]) except KeyError,err: - print 'Something is wrong with module %s, cannot determine %s - exiting'%(self.name,err) - sys.exit(1) + raise Exception, 'Something is wrong with module %s, cannot determine %s - exiting'%(self.name,err) def tag_url (self, spec_dict): return "%s/tags/%s"%(self.mod_url(),self.tag_name(spec_dict)) @@ -442,8 +451,8 @@ that for other purposes than tagging"""%topdir if self.options.verbose: print 'exists - OK' else: if self.options.verbose: print 'KO' - print 'Could not find %s URL %s'%(message,url) - sys.exit(1) + raise Exception, 'Could not find %s URL %s'%(message,url) + def check_svnpath_not_exists (self, url, message): if self.options.fast_checks: return @@ -454,8 +463,7 @@ that for other purposes than tagging"""%topdir if self.options.verbose: print 'does not exist - OK' else: if self.options.verbose: print 'KO' - print '%s URL %s already exists - exiting'%(message,url) - sys.exit(1) + raise Exception, '%s URL %s already exists - exiting'%(message,url) # locate specfile, parse it, check it and show values @@ -695,6 +703,8 @@ Please write a changelog for this new tag in the section above buildname=Module.config['build'] except: buildname="build" + if self.options.build_branch: + buildname+=":"+self.options.build_branch build = Module(buildname,self.options) build.init_moddir() build.init_edge_dir() @@ -780,8 +790,7 @@ n: move to next file"""%locals() incremented = int(rightmost)+1 new_trunk_name="%s.%d"%(leftpart,incremented) except: - print 'Cannot figure next branch name from %s - exiting'%version - sys.exit(1) + raise Exception, 'Cannot figure next branch name from %s - exiting'%version # record starting point tagname latest_tag_name = self.tag_name(spec_dict) @@ -801,7 +810,7 @@ will be based on latest tag %s and *not* on the current trunk"""%(self.name,bran if answer is True: break elif answer is False: - sys.exit(1) + raise Exception,"User quit" elif answer == 'd': print '<<<< %s'%tag_url print '>>>> %s'%edge_url @@ -900,8 +909,10 @@ More help: if mode == "tag" : parser.add_option("-c","--no-changelog", action="store_false", dest="changelog", default=True, help="do not update changelog section in specfile when tagging") + parser.add_option("-b","--build-branch", action="store", dest="build_branch", default=None, + help="specify a build branch; used for locating the *tags*.mk files where adoption is to take place") if mode == "tag" or mode == "sync" : - parser.add_option("-e","--editor", action="store", dest="editor", default="emacs", + parser.add_option("-e","--editor", action="store", dest="editor", default=default_editor(), help="specify editor") if mode == "sync" : parser.add_option("-m","--message", action="store", dest="message", default=None, @@ -951,7 +962,10 @@ More help: print '========================================',module.friendly_name() # call the method called do_ method=Module.__dict__["do_%s"%mode] - method(module) + try: + method(module) + except Exception,e: + print 'Skipping failed %s: '%modname,e if __name__ == "__main__" : try: