#!/usr/bin/python -u
-subversion_id = "$Id$"
-
import sys, os
import re
import time
os.chdir(cwd)
return ret
- def __run_command_in_repo(self, command):
+ def __run_command_in_repo(self, command, ignore_errors=False):
c = Command(command, self.options)
- return self.__run_in_repo(c.run_fatal)
+ if ignore_errors:
+ return self.__run_in_repo(c.output_of)
+ else:
+ return self.__run_in_repo(c.run_fatal)
def update(self, subdir=None, recursive=None):
return self.__run_command_in_repo("git pull")
return self.__run_command_in_repo("git checkout %s" % tag)
def tag(self, tagname, logfile):
- return self.__run_command_in_repo("git tag %s -F %s" % (tagname, logfile))
+ self.__run_command_in_repo("git tag %s -F %s" % (tagname, logfile))
+ self.commit(logfile)
def diff(self):
c = Command("git diff", self.options)
return self.__run_in_repo(c.output_of, with_stderr=True)
def commit(self, logfile):
- self.__run_command_in_repo("git add -A")
- self.__run_command_in_repo("git commit -F %s" % logfile)
+ self.__run_command_in_repo("git add -A", ignore_errors=True)
+ self.__run_command_in_repo("git commit -F %s" % logfile, ignore_errors=True)
+ self.__run_command_in_repo("git push")
self.__run_command_in_repo("git push --tags")
def revert(self):
configKeys=[ ('svnpath',"Enter your toplevel svnpath",
"svn+ssh://%s@svn.planet-lab.org/svn/"%commands.getoutput("id -un")),
('gitserver', "Enter your git server's hostname", "git.onelab.eu"),
+ ('gituser', "Enter your user name (login name) on git server", os.getlogin()),
("build", "Enter the name of your build module","build"),
('username',"Enter your firstname and lastname for changelogs",""),
("email","Enter your email address for changelogs",""),
]
+ @classmethod
+ def prompt_config_option(cls, key, message, default):
+ cls.config[key]=raw_input("%s [%s] : "%(message,default)).strip() or default
+
@classmethod
def prompt_config (cls):
for (key,message,default) in cls.configKeys:
cls.config[key]=""
while not cls.config[key]:
- cls.config[key]=raw_input("%s [%s] : "%(message,default)).strip() or default
+ cls.prompt_config_option(key, message, default)
# for parsing module spec name:branch
@classmethod
def git_remote_dir (cls, name):
- return "%s:/git/%s.git" % (cls.config['gitserver'], name)
+ return "%s@%s:/git/%s.git" % (cls.config['gituser'], cls.config['gitserver'], name)
@classmethod
def svn_remote_dir (cls, name):
module-* commands need a fresh working dir. Make sure that you do not use
that for other purposes than tagging""" % options.workdir
sys.exit(1)
- if not os.path.isdir (options.workdir):
- print "Cannot find",options.workdir,"let's create it"
- cls.prompt_config()
- print "Checking ...",
+
+ def checkout_build():
+ print "Checking out build module..."
remote = cls.git_remote_dir(cls.config['build'])
local = os.path.join(options.workdir, cls.config['build'])
- build = GitRepository.checkout(remote, local, options, depth=1)
- if not build.is_clean():
- build.revert()
+ GitRepository.checkout(remote, local, options, depth=1)
print "OK"
-
- # store config
+
+ def store_config():
f=file(storage,"w")
for (key,message,default) in Module.configKeys:
f.write("%s=%s\n"%(key,Module.config[key]))
if options.debug:
print 'Stored',storage
Command("cat %s"%storage,options).run()
- else:
+
+ def read_config():
# read config
f=open(storage)
for line in f.readlines():
Module.config[key]=value
f.close()
+ if not os.path.isdir (options.workdir):
+ print "Cannot find",options.workdir,"let's create it"
+ Command("mkdir -p %s" % options.workdir, options).run_silent()
+ cls.prompt_config()
+ checkout_build()
+ store_config()
+ else:
+ read_config()
+ # check missing config options
+ old_layout = False
+ for (key,message,default) in cls.configKeys:
+ if not Module.config.has_key(key):
+ print "Configuration changed for module-tools"
+ cls.prompt_config_option(key, message, default)
+ old_layout = True
+
+ if old_layout:
+ Command("rm -rf %s" % options.workdir, options).run_silent()
+ Command("mkdir -p %s" % options.workdir, options).run_silent()
+ checkout_build()
+ store_config()
+
build_dir = os.path.join(options.workdir, cls.config['build'])
build = Repository(build_dir, options)
if not build.is_clean():
print "build module needs a revert"
build.revert()
print "OK"
+ build.update()
if options.verbose and options.mode not in Main.silent_modes:
print '******** Using config'
usage = Main.release_usage
usage += Main.common_usage
- parser=OptionParser(usage=usage,version=subversion_id)
+ parser=OptionParser(usage=usage)
if mode == "tag" or mode == 'branch':
parser.add_option("-s","--set-version",action="store",dest="new_version",default=None,