-}
-
-def main():
-
- mode=None
- for function in functions.keys():
- if sys.argv[0].find(function) >= 0:
- mode = function
- break
- if not mode:
- print "Unsupported command",sys.argv[0]
- sys.exit(1)
-
- global usage
- usage += "\nmodule-%s : %s"%(mode,functions[mode])
- all_modules=os.path.dirname(sys.argv[0])+"/modules.list"
-
- parser=OptionParser(usage=usage,version=subversion_id)
- parser.add_option("-a","--all",action="store_true",dest="all_modules",default=False,
- help="run on all modules as found in %s"%all_modules)
- parser.add_option("-f","--fast-checks",action="store_true",dest="fast_checks",default=False,
- help="skip safety checks, such as svn updates -- use with care")
- if mode == "tag" or mode == 'branch':
- parser.add_option("-s","--set-version",action="store",dest="new_version",default=None,
- help="set new version and reset taglevel to 0")
- 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")
- if mode == "tag" or mode == "sync" :
- parser.add_option("-e","--editor", action="store", dest="editor", default="emacs",
- help="specify editor")
- if mode == "sync" :
- parser.add_option("-m","--message", action="store", dest="message", default=None,
- help="specify log message")
- if mode == "diff" :
- parser.add_option("-o","--only", action="store_true", dest="only", default=False,
- help="report diff only for modules that exhibit differences")
- if mode == "diff" :
- parser.add_option("-l","--list", action="store_true", dest="list", default=False,
- help="just list modules that exhibit differences")
- parser.add_option("-w","--workdir", action="store", dest="workdir",
- default="%s/%s"%(os.getenv("HOME"),"modules"),
- help="""name for dedicated working dir - defaults to ~/modules
+ 'changelog' : """extract changelog between build tags
+ expected arguments are a list of tags""",
+ 'adopt' : """locally adopt a specific tag""",
+ }
+
+ silent_modes = ['list']
+ # 'changelog' is for release-changelog
+ # 'adopt' is for 'adopt-tag'
+ regular_modes = set(modes.keys()).difference(set(['changelog','adopt']))
+
+ @staticmethod
+ def optparse_list(option, opt, value, parser):
+ try:
+ setattr(parser.values,option.dest,getattr(parser.values,option.dest)+value.split())
+ except:
+ setattr(parser.values,option.dest,value.split())
+
+ def run(self):
+
+ mode=None
+ # hack - need to check for adopt first as 'adopt-tag' contains tag..
+ for function in [ 'adopt' ] + list(Main.modes.keys()):
+ if sys.argv[0].find(function) >= 0:
+ mode = function
+ break
+ if not mode:
+ print("Unsupported command",sys.argv[0])
+ print("Supported commands:" + " ".join(list(Main.modes.keys())))
+ sys.exit(1)
+
+ usage='undefined usage, mode={}'.format(mode)
+ if mode in Main.regular_modes:
+ usage = Main.module_usage
+ usage += Main.common_usage
+ usage += "\nmodule-{} : {}".format(mode, Main.modes[mode])
+ elif mode == 'changelog':
+ usage = Main.release_usage
+ usage += Main.common_usage
+ elif mode == 'adopt':
+ usage = Main.adopt_usage
+ usage += Main.common_usage
+
+ parser=OptionParser(usage=usage)
+
+ # the 'adopt' mode is really special and doesn't share any option
+ if mode == 'adopt':
+ parser.add_option("-m","--module",action="append",dest="modules",default=[],
+ help="modules, can be used several times or with quotes")
+ parser.add_option("-t","--tag",action="store", dest="tag", default='master',
+ help="specify the tag to adopt, default is 'master'")
+ parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False,
+ help="run in verbose mode")
+ (options, args) = parser.parse_args()
+ options.workdir='unused'
+ options.dry_run=False
+ options.mode='adopt'
+ if len(args)==0 or len(options.modules)==0:
+ parser.print_help()
+ sys.exit(1)
+ adopt_tag(options,args)
+ return
+
+ # the other commands (module-* and release-changelog) share the same skeleton
+ if mode in [ 'tag', 'branch'] :
+ parser.add_option("-s","--set-version",action="store",dest="new_version",default=None,
+ help="set new version and reset taglevel to 0")
+ parser.add_option("-0","--bypass",action="store_true",dest="bypass",default=False,
+ help="skip checks on existence of the previous tag")
+ 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 in [ 'tag', 'sync' ] :
+ parser.add_option("-e","--editor", action="store", dest="editor", default=default_editor(),
+ help="specify editor")
+
+ if mode in ['diff','version'] :
+ parser.add_option("-W","--www", action="store", dest="www", default=False,
+ help="export diff in html format, e.g. -W trunk")
+
+ if mode == 'diff' :
+ parser.add_option("-l","--list", action="store_true", dest="list", default=False,
+ help="just list modules that exhibit differences")
+
+ default_modules_list=os.path.dirname(sys.argv[0])+"/modules.list"
+ parser.add_option("-a","--all",action="store_true",dest="all_modules",default=False,
+ help="run on all modules as found in {}".format(default_modules_list))
+ parser.add_option("-f","--file",action="store",dest="modules_list",default=None,
+ help="run on all modules found in specified file")
+ parser.add_option("-n","--dry-run",action="store_true",dest="dry_run",default=False,
+ help="dry run - shell commands are only displayed")
+ parser.add_option("-t","--distrotags",action="callback",callback=Main.optparse_list, dest="distrotags",
+ default=[], nargs=1,type="string",
+ help="""specify distro-tags files, e.g. onelab-tags-4.2.mk
+-- can be set multiple times, or use quotes""")
+
+ parser.add_option("-w","--workdir", action="store", dest="workdir",
+ default="{}/{}".format(os.getenv("HOME"),"modules"),
+ help="""name for dedicated working dir - defaults to ~/modules