+
+class Build(Module):
+
+ def __get_modules(self, tagfile):
+ self.init_module_dir()
+ modules = {}
+
+ tagfile = os.path.join(self.module_dir, tagfile)
+ for line in open(tagfile):
+ try:
+ name, url = line.split(':=')
+ name, git_or_svn_path = name.rsplit('-', 1)
+ name = svn_to_git_name(name.strip())
+ modules[name] = (git_or_svn_path.strip(), url.strip())
+ except:
+ pass
+ return modules
+
+ def get_modules(self, tagfile):
+ modules = self.__get_modules(tagfile)
+ for module in modules:
+ module_type = tag_or_branch = ""
+
+ path_type, url = modules[module]
+ if path_type == "GITPATH":
+ module_spec = os.path.split(url)[-1].replace(".git","")
+ name, tag_or_branch, module_type = self.parse_module_spec(module_spec)
+ else:
+ tag_or_branch = os.path.split(url)[-1].strip()
+ if url.find('/tags/') >= 0:
+ module_type = "tag"
+ elif url.find('/branches/') >= 0:
+ module_type = "branch"
+
+ modules[module] = {"module_type" : module_type,
+ "path_type": path_type,
+ "tag_or_branch": tag_or_branch,
+ "url":url}
+ return modules
+
+
+
+def modules_diff(first, second):
+ diff = {}
+
+ for module in first:
+ if module not in second:
+ print "=== module %s missing in right-hand side ==="%module
+ continue
+ if first[module]['tag_or_branch'] != second[module]['tag_or_branch']:
+ diff[module] = (first[module]['tag_or_branch'], second[module]['tag_or_branch'])
+
+ first_set = set(first.keys())
+ second_set = set(second.keys())
+
+ new_modules = list(second_set - first_set)
+ removed_modules = list(first_set - second_set)
+
+ return diff, new_modules, removed_modules
+
+def release_changelog(options, buildtag_old, buildtag_new):
+
+ # the command line expects new old, so we treat the tagfiles in the same order
+ nb_tags=len(options.distrotags)
+ if nb_tags==1:
+ tagfile_new=tagfile_old=options.distrotags[0]
+ elif nb_tags==2:
+ [tagfile_new,tagfile_old]=options.distrotags
+ else:
+ print "ERROR: provide one or two tagfile name (eg. onelab-k32-tags.mk)"
+ print "two tagfiles can be mentioned when a tagfile has been renamed"
+ return
+
+ if options.dry_run:
+ print "------------------------------ Computing Changelog from"
+ print "buildtag_old",buildtag_old,"tagfile_old",tagfile_old
+ print "buildtag_new",buildtag_new,"tagfile_new",tagfile_new
+ return
+
+ print '----'
+ print '----'
+ print '----'
+ print '= build tag %s to %s =' % (buildtag_old, buildtag_new)
+ print '== distro %s (%s to %s) ==' % (tagfile_new, buildtag_old, buildtag_new)
+
+ build = Build("build@%s" % buildtag_old, options)
+ build.init_module_dir()
+ first = build.get_modules(tagfile_old)
+
+ print ' * from', buildtag_old, build.repository.gitweb()
+
+ build = Build("build@%s" % buildtag_new, options)
+ build.init_module_dir()
+ second = build.get_modules(tagfile_new)
+
+ print ' * to', buildtag_new, build.repository.gitweb()
+
+ diff, new_modules, removed_modules = modules_diff(first, second)
+
+
+ def get_module(name, tag):
+ if not tag or tag == "trunk":
+ return Module("%s" % (module), options)
+ else:
+ return Module("%s@%s" % (module, tag), options)
+
+
+ for module in diff:
+ print '=== %s - %s to %s : package %s ===' % (tagfile_new, buildtag_old, buildtag_new, module)
+
+ first, second = diff[module]
+ m = get_module(module, first)
+ os.system('rm -rf %s' % m.module_dir) # cleanup module dir
+ m.init_module_dir()
+
+ if m.repository.type == "svn":
+ print ' * from', first, m.repository.url()
+ else:
+ print ' * from', first, m.repository.gitweb()
+
+ specfile = m.main_specname()
+ (tmpfd, tmpfile) = tempfile.mkstemp()
+ os.system("cp -f /%s %s" % (specfile, tmpfile))
+
+ m = get_module(module, second)
+ # patch for ipfw that, being managed in a separate repo, won't work for now
+ try:
+ m.init_module_dir()
+ except Exception,e:
+ print """Could not retrieve module %s - skipped
+{{{ %s }}}
+""" %( m.friendly_name(), e)
+ continue
+ specfile = m.main_specname()
+
+ if m.repository.type == "svn":
+ print ' * to', second, m.repository.url()
+ else:
+ print ' * to', second, m.repository.gitweb()
+
+ print '{{{'
+ os.system("diff -u %s %s | sed -e 's,%s,[[previous version]],'" % (tmpfile, specfile,tmpfile))
+ print '}}}'
+
+ os.unlink(tmpfile)
+
+ for module in new_modules:
+ print '=== %s : new package in build %s ===' % (tagfile_new, module)
+
+ for module in removed_modules:
+ print '=== %s : removed package from build %s ===' % (tagfile_new, module)
+
+
+def adopt_tag (options, args):
+ modules=[]
+ for module in options.modules:
+ modules += module.split()
+ for module in modules:
+ modobj=Module(module,options)
+ for tags_file in args:
+ if options.verbose:
+ print 'adopting tag %s for %s in %s'%(options.tag,module,tags_file)
+ modobj.patch_tags_file(tags_file,'_unused_',options.tag,fine_grain=False)
+ if options.verbose:
+ Command("git diff %s"%" ".join(args),options).run()
+