cosmetic
[build.git] / module-tools.py
index 933f436..2cadc2b 100755 (executable)
@@ -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
@@ -143,7 +150,7 @@ class Module:
 
 
     # for parsing module spec name:branch
-    matcher_branch_spec=re.compile("\A(?P<name>[\w-]+):(?P<branch>[\w\.]+)\Z")
+    matcher_branch_spec=re.compile("\A(?P<name>[\w-]+):(?P<branch>[\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)
@@ -394,9 +399,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 +431,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 +446,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 +458,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
 
@@ -780,8 +783,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 +803,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
@@ -901,7 +903,7 @@ More help:
             parser.add_option("-c","--no-changelog", action="store_false", dest="changelog", default=True,
                               help="do not update changelog section in specfile when tagging")
         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 +953,10 @@ More help:
                 print '========================================',module.friendly_name()
             # call the method called do_<mode>
             method=Module.__dict__["do_%s"%mode]
-            method(module)
+            try:
+                method(module)
+            except Exception,e:
+                print 'Skipping failed %s - %r'%(modname,e)
 
 if __name__ == "__main__" :
     try: