release-changelog should support the build trunk as well
[build.git] / module-tools.py
index c35cd13..da4c012 100755 (executable)
@@ -330,7 +330,7 @@ that for other purposes than tagging"""%topdir
             Module.prompt_config()
             print "Checking ...",
             Command("svn co -N %s %s"%(Module.config['svnpath'],topdir),options).run_fatal()
-            Command("svn co -N %s/%s %s/%s"%(Module.config['svnpath'],
+            Command("svn co %s/%s %s/%s"%(Module.config['svnpath'],
                                              Module.config['build'],
                                              topdir,
                                              Module.config['build']),options).run_fatal()
@@ -364,11 +364,13 @@ that for other purposes than tagging"""%topdir
         if not os.path.isdir (self.module_dir):
             raise Exception, 'Cannot find %s - check module name'%self.module_dir
 
-    def init_subdir (self,fullpath):
+    def init_subdir (self,fullpath, deep=False):
         if self.options.verbose:
             print 'Checking for',fullpath
+        opt=""
+        if not deep: opt="-N"
         if not os.path.isdir (fullpath):
-            self.run_fatal("svn update -N %s"%fullpath)
+            self.run_fatal("svn update %s %s"%(opt,fullpath))
 
     def revert_subdir (self,fullpath):
         if self.options.fast_checks:
@@ -385,15 +387,15 @@ that for other purposes than tagging"""%topdir
             return
         if self.options.verbose:
             print 'Updating',fullpath
-        self.run_fatal("svn update -N %s"%fullpath)
+        self.run_fatal("svn update %s"%fullpath)
 
     def init_edge_dir (self):
         # if branch, edge_dir is two steps down
         if hasattr(self,'branch'):
-            self.init_subdir("%s/branches"%self.module_dir)
+            self.init_subdir("%s/branches"%self.module_dir,deep=False)
         elif hasattr(self,'tagname'):
-            self.init_subdir("%s/tags"%self.module_dir)
-        self.init_subdir(self.edge_dir())
+            self.init_subdir("%s/tags"%self.module_dir,deep=False)
+        self.init_subdir(self.edge_dir(),deep=True)
 
     def revert_edge_dir (self):
         self.revert_subdir(self.edge_dir())
@@ -405,15 +407,21 @@ that for other purposes than tagging"""%topdir
         attempt="%s/%s.spec"%(self.edge_dir(),self.name)
         if os.path.isfile (attempt):
             return attempt
-        else:
-            pattern="%s/*.spec"%self.edge_dir()
-            try:
-                return glob(pattern)[0]
-            except:
-                raise Exception, 'Cannot guess specfile for module %s -- pattern was %s'%(self.name,pattern)
+        pattern1="%s/*.spec"%self.edge_dir()
+        level1=glob(pattern1)
+        if level1:
+            return level1[0]
+        pattern2="%s/*/*.spec"%self.edge_dir()
+        level2=glob(pattern2)
+        if level2:
+            return level2[0]
+        raise Exception, 'Cannot guess specfile for module %s -- patterns were %s or %s'%(self.name,pattern1,pattern2)
 
     def all_specnames (self):
-        return glob("%s/*.spec"%self.edge_dir())
+        level1=glob("%s/*.spec"%self.edge_dir())
+        if level1: return level1
+        level2=glob("%s/*/*.spec"%self.edge_dir())
+        return level2
 
     def parse_spec (self, specfile, varnames):
         if self.options.verbose:
@@ -855,8 +863,10 @@ Please write a changelog for this new tag in the section above
         tagsfiles=glob(build.edge_dir()+"/*-tags*.mk")
         tagsdict=dict( [ (x,'todo') for x in tagsfiles ] )
         default_answer = 'y'
+        tagsfiles.sort()
         while True:
-            for (tagsfile,status) in tagsdict.iteritems():
+            for tagsfile in tagsfiles:
+                status=tagsdict[tagsfile]
                 basename=os.path.basename(tagsfile)
                 print ".................... Dealing with %s"%basename
                 while tagsdict[tagsfile] == 'todo' :
@@ -887,7 +897,7 @@ c: cat the current tag file
 n: move to next file"""%locals()
 
             if prompt("Want to review changes on tags files",False):
-                tagsdict = dict ( [ (x, 'todo') for tagsfile in tagsfiles ] )
+                tagsdict = dict ( [ (x, 'todo') for x in tagsfiles ] )
                 default_answer='d'
             else:
                 break
@@ -979,17 +989,24 @@ will be based on latest tag %s and *not* on the current trunk"""%(self.name,bran
         f.write("Branch %s for module %s created (as new trunk) from tag %s\n"%(new_trunk_name,self.name,latest_tag_name))
         f.close()
 
-        # we're done, let's commit the stuff
+        # review the renumbering changes in trunk
         command="svn diff %s"%self.edge_dir()
-        self.run_prompt("Review changes in trunk",command)
-        command="svn copy --file %s %s %s"%(tmp,self.edge_url(),branch_url)
+        self.run_prompt("Review (renumbering) changes in trunk",command)
+        # create branch
+        command="svn copy --file %s %s %s"%(tmp,tag_url,branch_url)
         self.run_prompt("Create branch",command)
+        # commit trunk
         command="svn commit --file %s %s"%(tmp,self.edge_dir())
         self.run_prompt("Commit trunk",command)
+        # create initial tag for the new trunk
         new_tag_url=self.tag_url(spec_dict)
-        command="svn copy --file %s %s %s"%(tmp,self.edge_url(),new_tag_url)
+        command="svn copy --file %s %s %s"%(tmp,tag_url,new_tag_url)
         self.run_prompt("Create initial tag in trunk",command)
         os.unlink(tmp)
+        # print message about SVNBRANCH
+        print """You might now wish to review your tags files
+Please make sure you mention as appropriate 
+%s-SVNBRANCH := %s""" %(self.name,branch_name)
 
 ##############################
 class Package:
@@ -997,9 +1014,14 @@ class Package:
     def __init__(self, package, module, svnpath, spec):
         self.package=package
         self.module=module
-        self.svnpath=svnpath
+        self.svnrev = None
+        self.svnpath=svnpath    
+        if svnpath.rfind('@') > 0:
+            self.svnpath, self.svnrev = svnpath.split('@')
         self.spec=spec
-        self.specpath="%s/%s"%(svnpath,spec)
+        self.specpath="%s/%s"%(self.svnpath,self.spec)
+        if self.svnrev:
+            self.specpath += "@%s" % self.svnrev
         self.basename=os.path.basename(svnpath)
 
     # returns a http URL to the trac path where full diff can be viewed (between self and pkg)
@@ -1024,10 +1046,14 @@ class Build (Module):
     
     # we cannot get build's svnpath as for other packages as we'd get something in svn+ssh
     # xxx quick & dirty
-    def __init__ (self, buildtag,options):
+    def __init__ (self, buildtag, options):
         self.buildtag=buildtag
+        if buildtag == "trunk":
+            module_name="build"
+            self.display="trunk"
+            self.svnpath="http://svn.planet-lab.org/svn/build/trunk"
         # if the buildtag start with a : (to use a branch rather than a tag)
-        if buildtag.find(':') == 0 : 
+        elif buildtag.find(':') == 0 : 
             module_name="build%(buildtag)s"%locals()
             self.display=buildtag[1:]
             self.svnpath="http://svn.planet-lab.org/svn/build/branches/%s"%self.display
@@ -1035,6 +1061,9 @@ class Build (Module):
             module_name="build@%(buildtag)s"%locals()
             self.display=buildtag
             self.svnpath="http://svn.planet-lab.org/svn/build/tags/%s"%self.buildtag
+        print 'module_name',module_name
+        print 'display',self.display
+        print 'svnpath',self.svnpath
         Module.__init__(self,module_name,options)
 
     @staticmethod
@@ -1151,7 +1180,10 @@ class Release:
             pnames = list(pnames_new.intersection(pnames_old))
             pnames.sort()
 
-            if options.verbose: print "Found new/deprecated/preserved pnames",pnames_new,pnames_deprecated,pnames
+            if options.verbose: 
+                print "Found new pnames",pnames_new
+                print "Found deprecated pnames",pnames_deprecated
+                print "Found preserved pnames",pnames
 
             # display created and deprecated 
             for name in pnames_created:
@@ -1205,6 +1237,8 @@ class Release:
 class Main:
 
     module_usage="""Usage: %prog [options] module_desc [ .. module_desc ]
+Revision: $Revision$
+
 module-tools : a set of tools to manage subversion tags and specfile
   requires the specfile to either
   * define *version* and *taglevel*
@@ -1223,6 +1257,8 @@ Branches:
       release-changelog 4.2-rc25 4.2-rc24 4.2-rc23 4.2-rc22
   You can refer to a (build) branch by prepending a colon, like in
       release-changelog :4.2 4.2-rc25
+  You can refer to the build trunk by just mentioning 'trunk', e.g.
+      release-changelog -t coblitz-tags.mk coblitz-2.01-rc6 trunk
 """
     common_usage="""More help:
   see http://svn.planet-lab.org/wiki/ModuleTools"""
@@ -1330,7 +1366,7 @@ Branches:
                           help="skip safety checks, such as svn updates -- use with care")
 
         # default verbosity depending on function - temp
-        verbose_modes= ['tag','sync']
+        verbose_modes= ['tag', 'sync', 'branch']
         
         if mode not in verbose_modes:
             parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
@@ -1357,6 +1393,8 @@ Branches:
             Module.init_homedir(options)
             for n in range(len(args)-1):
                 [t_new,t_old]=args[n:n+2]
+                print '----------------------------------------'
+                print 'PAIR',t_new,t_old
                 Release.do_changelog (t_new,t_old,options)
         else:
             ########## module-*