Commit fee46803 authored by Nikos Skalkotos's avatar Nikos Skalkotos Committed by Filippos Giannakos
Browse files

Fix pep8 errors

parent 5d95a60e
...@@ -58,7 +58,7 @@ BRANCH_TYPES = { ...@@ -58,7 +58,7 @@ BRANCH_TYPES = {
"master": branch_type(True, True, False, "master": branch_type(True, True, False,
"^%s$" % VERSION_RE, "debian"), "^%s$" % VERSION_RE, "debian"),
"hotfix": branch_type(True, True, True, "hotfix": branch_type(True, True, True,
"^(?P<bverstr>^%s\.[1-9][0-9]*)(%s)*$" %\ "^(?P<bverstr>^%s\.[1-9][0-9]*)(%s)*$" %
(VERSION_RE, RC_RE), (VERSION_RE, RC_RE),
"debian")} "debian")}
BASE_VERSION_FILE = "version" BASE_VERSION_FILE = "version"
...@@ -3,7 +3,7 @@ import re ...@@ -3,7 +3,7 @@ import re
import logging import logging
logging.basicConfig() logging.basicConfig()
#from optparse import OptionParser
from argparse import ArgumentParser from argparse import ArgumentParser
os.environ["GIT_PYTHON_TRACE"] = "full" os.environ["GIT_PYTHON_TRACE"] = "full"
...@@ -47,7 +47,7 @@ def conflicts(): ...@@ -47,7 +47,7 @@ def conflicts():
except GitCommandError as e: except GitCommandError as e:
if e.status != 128: if e.status != 128:
print "An error occured. Resolve it and type 'exit 0'" print "An error occured. Resolve it and type 'exit 0'"
tmpbashrc=create_temp_file("bashrc") tmpbashrc = create_temp_file("bashrc")
f = open(tmpbashrc, 'w') f = open(tmpbashrc, 'w')
f.write("source $HOME/.bashrc ; export PS1=(Conflict)\"$PS1\"") f.write("source $HOME/.bashrc ; export PS1=(Conflict)\"$PS1\"")
f.close() f.close()
...@@ -56,22 +56,25 @@ def conflicts(): ...@@ -56,22 +56,25 @@ def conflicts():
else: else:
raise raise
def get_release_version(develop_version): def get_release_version(develop_version):
version = develop_version.rstrip('next') version = develop_version.rstrip('next')
parts = version.split('.') parts = version.split('.')
major_version = int(parts[0]) major_version = int(parts[0])
minor_version = int(parts[1]) minor_version = int(parts[1])
#return str(major_version) + '.' + str(minor_version+1) + 'rc1' # return str(major_version) + '.' + str(minor_version+1) + 'rc1'
return str(major_version) + '.' + str(minor_version+1) return str(major_version) + '.' + str(minor_version+1)
def get_develop_version_from_release(release_version): def get_develop_version_from_release(release_version):
#version = re.sub('rc[0-9]+$', '', release_version) # version = re.sub('rc[0-9]+$', '', release_version)
version = release_version version = release_version
parts = version.split('.') parts = version.split('.')
major_version = int(parts[0]) major_version = int(parts[0])
minor_version = int(parts[1]) minor_version = int(parts[1])
return str(major_version) + '.' + str(minor_version+1) + 'next' return str(major_version) + '.' + str(minor_version+1) + 'next'
def get_hotfix_version(version): def get_hotfix_version(version):
parts = version.split('.') parts = version.split('.')
major_version = int(parts[0]) major_version = int(parts[0])
...@@ -81,8 +84,9 @@ def get_hotfix_version(version): ...@@ -81,8 +84,9 @@ def get_hotfix_version(version):
else: else:
hotfix_version = 0 hotfix_version = 0
return str(major_version) + '.' + str(minor_version) + '.'\ return str(major_version) + '.' + str(minor_version) + '.' \
+ str(hotfix_version+1) + str(hotfix_version+1)
class GitManager(object): class GitManager(object):
def __init__(self): def __init__(self):
...@@ -94,7 +98,7 @@ class GitManager(object): ...@@ -94,7 +98,7 @@ class GitManager(object):
self.log.info("Repository: %s. HEAD: %s", self.repo, self.start_hex) self.log.info("Repository: %s. HEAD: %s", self.repo, self.start_hex)
self.new_branches = [] self.new_branches = []
self.new_tags = [] self.new_tags = []
#self.repo.git.pull("origin") # self.repo.git.pull("origin")
def get_branch(self, mode, version): def get_branch(self, mode, version):
if mode not in ["release", "hotfix"]: if mode not in ["release", "hotfix"]:
...@@ -106,10 +110,10 @@ class GitManager(object): ...@@ -106,10 +110,10 @@ class GitManager(object):
raise ValueError("Unknown mode: %s" % mode) raise ValueError("Unknown mode: %s" % mode)
return "debian-%s-%s" % (mode, version) return "debian-%s-%s" % (mode, version)
def doit(self, action_yes=None, action_no=None, question="Do it", args=None, def doit(self, action_yes=None, action_no=None, question="Do it",
default=False): args=None, default=False):
if not args.defaults: if not args.defaults:
ret = query_yes_no(question, default = "yes" if default else "no") ret = query_yes_no(question, default="yes" if default else "no")
else: else:
ret = default ret = default
...@@ -123,7 +127,6 @@ class GitManager(object): ...@@ -123,7 +127,6 @@ class GitManager(object):
for b in branches: for b in branches:
print "git branch -D %s" % b print "git branch -D %s" % b
def __cleanup_branches(self, branches): def __cleanup_branches(self, branches):
repo = self.repo repo = self.repo
for b in branches: for b in branches:
...@@ -137,13 +140,12 @@ class GitManager(object): ...@@ -137,13 +140,12 @@ class GitManager(object):
self.__print_cleanup(branches) self.__print_cleanup(branches)
return return
question="Remove branches %s" % branches question = "Remove branches %s" % branches
action_yes = partial(self.__cleanup_branches, branches) action_yes = partial(self.__cleanup_branches, branches)
action_no = partial(self.__print_cleanup, branches) action_no = partial(self.__print_cleanup, branches)
self.doit(action_yes=action_yes, action_no=action_no, self.doit(action_yes=action_yes, action_no=action_no,
question=question, args=args, default=default) question=question, args=args, default=default)
def check_edit_changelog(self, edit_action, args, default=True): def check_edit_changelog(self, edit_action, args, default=True):
if args.edit_changelog is not None: if args.edit_changelog is not None:
if args.edit_changelog: if args.edit_changelog:
...@@ -169,9 +171,9 @@ class GitManager(object): ...@@ -169,9 +171,9 @@ class GitManager(object):
def edit_changelog(self, branch, base_branch=None): def edit_changelog(self, branch, base_branch=None):
repo = self.repo repo = self.repo
if not branch in repo.branches: if branch not in repo.branches:
raise ValueError("Branch %s does not exist." % branch) raise ValueError("Branch %s does not exist." % branch)
if base_branch and not base_branch in repo.branches: if base_branch and base_branch not in repo.branches:
raise ValueError("Branch %s does not exist." % base_branch) raise ValueError("Branch %s does not exist." % base_branch)
repo.git.checkout(branch) repo.git.checkout(branch)
...@@ -181,7 +183,8 @@ class GitManager(object): ...@@ -181,7 +183,8 @@ class GitManager(object):
lines = [] lines = []
lines.append("#Changelog for %s\n" % branch) lines.append("#Changelog for %s\n" % branch)
if base_branch: if base_branch:
commits = repo.git.rev_list("%s..%s" % (base_branch, branch)).split("\n") commits = repo.git.rev_list(
"%s..%s" % (base_branch, branch)).split("\n")
for c in commits: for c in commits:
commit = repo.commit(c) commit = repo.commit(c)
lines.append("* " + commit.message.split("\n")[0]) lines.append("* " + commit.message.split("\n")[0])
...@@ -216,7 +219,7 @@ class GitManager(object): ...@@ -216,7 +219,7 @@ class GitManager(object):
if not args.defaults: if not args.defaults:
version = query_user("Release version", default=version) version = query_user("Release version", default=version)
else: else:
#validate version? # validate version?
pass pass
rc_version = "%src1" % version rc_version = "%src1" % version
new_develop_version = "%snext" % version new_develop_version = "%snext" % version
...@@ -224,13 +227,13 @@ class GitManager(object): ...@@ -224,13 +227,13 @@ class GitManager(object):
upstream_branch = self.get_branch("release", version) upstream_branch = self.get_branch("release", version)
debian_branch = self.get_debian_branch("release", version) debian_branch = self.get_debian_branch("release", version)
#create release branch # create release branch
repo.git.branch(upstream_branch, upstream) repo.git.branch(upstream_branch, upstream)
self.new_branches.append(upstream_branch) self.new_branches.append(upstream_branch)
repo.git.checkout(upstream_branch) repo.git.checkout(upstream_branch)
versioning.bump_version(rc_version) versioning.bump_version(rc_version)
#create debian release branch # create debian release branch
repo.git.checkout(debian) repo.git.checkout(debian)
repo.git.branch(debian_branch, debian) repo.git.branch(debian_branch, debian)
self.new_branches.append(debian_branch) self.new_branches.append(debian_branch)
...@@ -238,21 +241,20 @@ class GitManager(object): ...@@ -238,21 +241,20 @@ class GitManager(object):
repo.git.checkout(upstream_branch) repo.git.checkout(upstream_branch)
repo.git.checkout(debian) repo.git.checkout(debian)
#bump develop version # bump develop version
repo.git.checkout(upstream) repo.git.checkout(upstream)
versioning.bump_version(new_develop_version) versioning.bump_version(new_develop_version)
repo.git.checkout(upstream_branch) repo.git.checkout(upstream_branch)
@cleanup @cleanup
def start_hotfix(self, args): def start_hotfix(self, args):
repo = self.repo repo = self.repo
upstream = "master" upstream = "master"
debian = "debian" debian = "debian"
repo.git.checkout(upstream) repo.git.checkout(upstream)
#maybe provide major.minor version, find the latest release/hotfix and # maybe provide major.minor version, find the latest release/hotfix and
#branch from there ? # branch from there ?
vcs = utils.get_vcs_info() vcs = utils.get_vcs_info()
version = versioning.get_base_version(vcs) version = versioning.get_base_version(vcs)
...@@ -261,7 +263,7 @@ class GitManager(object): ...@@ -261,7 +263,7 @@ class GitManager(object):
if not args.defaults: if not args.defaults:
version = query_user("Hotfix version", default=version) version = query_user("Hotfix version", default=version)
else: else:
#validate version? # validate version?
pass pass
rc_version = "%src1" % version rc_version = "%src1" % version
...@@ -270,13 +272,13 @@ class GitManager(object): ...@@ -270,13 +272,13 @@ class GitManager(object):
upstream_branch = self.get_branch("hotfix", version) upstream_branch = self.get_branch("hotfix", version)
debian_branch = self.get_debian_branch("hotfix", version) debian_branch = self.get_debian_branch("hotfix", version)
#create hotfix branch # create hotfix branch
repo.git.branch(upstream_branch, upstream) repo.git.branch(upstream_branch, upstream)
self.new_branches.append(upstream_branch) self.new_branches.append(upstream_branch)
repo.git.checkout(upstream_branch) repo.git.checkout(upstream_branch)
versioning.bump_version(rc_version) versioning.bump_version(rc_version)
#create debian hotfix branch # create debian hotfix branch
repo.git.checkout(debian) repo.git.checkout(debian)
repo.git.branch(debian_branch, debian) repo.git.branch(debian_branch, debian)
self.new_branches.append(debian_branch) self.new_branches.append(debian_branch)
...@@ -284,10 +286,10 @@ class GitManager(object): ...@@ -284,10 +286,10 @@ class GitManager(object):
repo.git.checkout(upstream_branch) repo.git.checkout(upstream_branch)
repo.git.checkout(debian) repo.git.checkout(debian)
#bump develop version. Ask first or verify we have the same # bump develop version. Ask first or verify we have the same
#major.minornext? # major.minornext?
#repo.git.checkout(upstream) # repo.git.checkout(upstream)
#versioning.bump_version(new_develop_version) # versioning.bump_version(new_develop_version)
repo.git.checkout(upstream_branch) repo.git.checkout(upstream_branch)
...@@ -313,17 +315,17 @@ class GitManager(object): ...@@ -313,17 +315,17 @@ class GitManager(object):
new_version = re.sub(RC_RE, '', release_version) new_version = re.sub(RC_RE, '', release_version)
versioning._bump_version(new_version, vcs) versioning._bump_version(new_version, vcs)
#merge to master # merge to master
self._merge_branches(master, upstream_branch) self._merge_branches(master, upstream_branch)
self._merge_branches(debian_master, debian_branch) self._merge_branches(debian_master, debian_branch)
#create tags # create tags
repo.git.checkout(master) repo.git.checkout(master)
repo.git.tag("%s" % tag) repo.git.tag("%s" % tag)
repo.git.checkout(debian) repo.git.checkout(debian)
repo.git.tag("%s" % debian_tag) repo.git.tag("%s" % debian_tag)
#merge release changes to upstream # merge release changes to upstream
self.merge_branches(upstream, upstream_branch, args, default=True) self.merge_branches(upstream, upstream_branch, args, default=True)
self.merge_branches(debian, debian_branch, args, default=True) self.merge_branches(debian, debian_branch, args, default=True)
...@@ -342,7 +344,7 @@ class GitManager(object): ...@@ -342,7 +344,7 @@ class GitManager(object):
upstream_branch = self.get_branch("hotfix", version) upstream_branch = self.get_branch("hotfix", version)
debian_branch = self.get_debian_branch("hotfix", version) debian_branch = self.get_debian_branch("hotfix", version)
#create tags? # create tags?
self._merge_branches(upstream, upstream_branch) self._merge_branches(upstream, upstream_branch)
self._merge_branches(debian, debian_branch) self._merge_branches(debian, debian_branch)
...@@ -368,14 +370,14 @@ class GitManager(object): ...@@ -368,14 +370,14 @@ class GitManager(object):
feature_name = args.feature_name feature_name = args.feature_name
repo = self.repo repo = self.repo
feature_upstream = "feature-%s" % feature_name feature_upstream = "feature-%s" % feature_name
if not feature_upstream in repo.branches: if feature_upstream not in repo.branches:
raise ValueError("Branch %s does not exist." % feature_upstream) raise ValueError("Branch %s does not exist." % feature_upstream)
feature_debian = "debian-%s" % feature_upstream feature_debian = "debian-%s" % feature_upstream
edit_action = partial(self.edit_changelog, feature_upstream, "develop") edit_action = partial(self.edit_changelog, feature_upstream, "develop")
self.check_edit_changelog(edit_action, args, default=True) self.check_edit_changelog(edit_action, args, default=True)
#merge to develop # merge to develop
self._merge_branches("develop", feature_upstream) self._merge_branches("develop", feature_upstream)
if feature_debian in repo.branches: if feature_debian in repo.branches:
self._merge_branches("debian-develop", feature_debian) self._merge_branches("debian-develop", feature_debian)
...@@ -394,93 +396,89 @@ def refhead(repo): ...@@ -394,93 +396,89 @@ def refhead(repo):
def main(): def main():
parser = ArgumentParser(description="Devflow tool") parser = ArgumentParser(description="Devflow tool")
parser.add_argument('-V', '--version', action='version', parser.add_argument('-V', '--version', action='version',
version='devflow-flow %s' % __version__) version='devflow-flow %s' % __version__)
parser.add_argument('-d', '--defaults', action='store_true', default=False, parser.add_argument(
help="Assume default on every choice, unless a value is provided") '-d', '--defaults', action='store_true', default=False,
help="Assume default on every choice, unless a value is provided")
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
init_parser = subparsers.add_parser('init', init_parser = subparsers.add_parser('init',
help="Initialize a new devflow repo") help="Initialize a new devflow repo")
init_parser.add_argument('-m', '--master', type=str, nargs='?', init_parser.add_argument('-m', '--master', type=str, nargs='?',
help="Master branch") help="Master branch")
init_parser.add_argument('-d', '--develop', type=str, nargs='?', init_parser.add_argument('-d', '--develop', type=str, nargs='?',
help="Develop branch") help="Develop branch")
init_parser.set_defaults(func='init_repo') init_parser.set_defaults(func='init_repo')
feature_parser = subparsers.add_parser('feature', help="Feature options") feature_parser = subparsers.add_parser('feature', help="Feature options")
feature_subparsers = feature_parser.add_subparsers() feature_subparsers = feature_parser.add_subparsers()
feature_start_parser = feature_subparsers.add_parser('start', feature_start_parser = feature_subparsers.add_parser(
help="Start a new feature") 'start', help="Start a new feature")
feature_start_parser.set_defaults(func='start_feature') feature_start_parser.set_defaults(func='start_feature')
feature_start_parser.add_argument('feature_name', type=str, feature_start_parser.add_argument('feature_name', type=str,
help="Name of the feature") help="Name of the feature")
feature_finish_parser = feature_subparsers.add_parser('finish', feature_finish_parser = feature_subparsers.add_parser(
help="Finish a feature") 'finish', help="Finish a feature")
feature_finish_parser.set_defaults(func='end_feature') feature_finish_parser.set_defaults(func='end_feature')
feature_finish_parser.add_argument('feature_name', type=str, feature_finish_parser.add_argument('feature_name', type=str,
help="Name of the feature") help="Name of the feature")
feature_finish_parser.add_argument('--no-edit-changelog', feature_finish_parser.add_argument(
action='store_const', const=False, dest='edit_changelog', '--no-edit-changelog', action='store_const', const=False,
help="Do not edit the changelog") dest='edit_changelog', help="Do not edit the changelog")
feature_finish_parser.add_argument('--no-cleanup', action='store_const', feature_finish_parser.add_argument(
const=True, dest='cleanup', help="Do not cleanup branches") '--no-cleanup', action='store_const', const=True, dest='cleanup',
help="Do not cleanup branches")
release_parser = subparsers.add_parser('release', help="release options") release_parser = subparsers.add_parser('release', help="release options")
release_subparsers = release_parser.add_subparsers() release_subparsers = release_parser.add_subparsers()
release_start_parser = release_subparsers.add_parser(
release_start_parser = release_subparsers.add_parser('start', 'start', help="Start a new release")
help="Start a new release") release_start_parser.add_argument(
release_start_parser.add_argument('--version', type=str, '--version', type=str, help="Version of the release")
help="Version of the release") release_start_parser.add_argument(
release_start_parser.add_argument('--develop-version', type=str, '--develop-version', type=str, help="New develop version")
help="New develop version")
release_start_parser.set_defaults(func='start_release') release_start_parser.set_defaults(func='start_release')
release_finish_parser = release_subparsers.add_parser(
release_finish_parser = release_subparsers.add_parser('finish', 'finish', help="Finish a release")
help="Finish a release") release_finish_parser.add_argument(
release_finish_parser.add_argument('version', type=str, 'version', type=str, help="Version of the release")
help="Version of the release") release_finish_parser.add_argument(
release_finish_parser.add_argument('--no-edit-changelog', '--no-edit-changelog', action='store_const', const=False,
action='store_const', const=False, dest='edit_changelog', dest='edit_changelog', help="Do not edit the changelog")
help="Do not edit the changelog") release_finish_parser.add_argument(
release_finish_parser.add_argument('--no-cleanup', action='store_const', '--no-cleanup', action='store_const', const=True, dest='cleanup',
const=True, dest='cleanup', help="Do not cleanup branches") help="Do not cleanup branches")
release_finish_parser.set_defaults(func='end_release') release_finish_parser.set_defaults(func='end_release')
hotfix_parser = subparsers.add_parser('hotfix', help="hotfix options") hotfix_parser = subparsers.add_parser('hotfix', help="hotfix options")
hotfix_subparsers = hotfix_parser.add_subparsers() hotfix_subparsers = hotfix_parser.add_subparsers()
hotfix_start_parser = hotfix_subparsers.add_parser(
hotfix_start_parser = hotfix_subparsers.add_parser('start', 'start', help="Start a new hotfix")
help="Start a new hotfix") hotfix_start_parser.add_argument(
hotfix_start_parser.add_argument('--version', type=str, '--version', type=str, help="Version of the hotfix")
help="Version of the hotfix") hotfix_start_parser.add_argument(
hotfix_start_parser.add_argument('--develop-version', type=str, '--develop-version', type=str, help="New develop version")
help="New develop version")
hotfix_start_parser.set_defaults(func='start_hotfix') hotfix_start_parser.set_defaults(func='start_hotfix')
hotfix_finish_parser = hotfix_subparsers.add_parser(
hotfix_finish_parser = hotfix_subparsers.add_parser('finish', 'finish', help="Finish a hotfix")
help="Finish a hotfix") hotfix_finish_parser.add_argument(
hotfix_finish_parser.add_argument('version', type=str, 'version', type=str, help="Version of the hotfix")
help="Version of the hotfix") hotfix_finish_parser.add_argument(
hotfix_finish_parser.add_argument('--no-edit-changelog', '--no-edit-changelog', action='store_const', const=False,
action='store_const', const=False, dest='edit_changelog', dest='edit_changelog', help="Do not edit the changelog")
help="Do not edit the changelog") hotfix_finish_parser.add_argument(
hotfix_finish_parser.add_argument('--no-cleanup', action='store_const', '--no-cleanup', action='store_const', const=True, dest='cleanup',
const=True, dest='cleanup', help="Do not cleanup branches") help="Do not cleanup branches")
hotfix_finish_parser.set_defaults(func='end_hotfix') hotfix_finish_parser.set_defaults(func='end_hotfix')
args = parser.parse_args() args = parser.parse_args()
gm = GitManager() gm = GitManager()
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
import sys import sys
#http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
# http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
def query_yes_no(question, default="yes"): def query_yes_no(question, default="yes"):
"""Ask a yes/no question via raw_input() and return their answer. """Ask a yes/no question via raw_input() and return their answer.
...@@ -13,9 +14,9 @@ def query_yes_no(question, default="yes"): ...@@ -13,9 +14,9 @@ def query_yes_no(question, default="yes"):
The "answer" return value is one of "yes" or "no". The "answer" return value is one of "yes" or "no".
""" """
valid = {"yes":True, "y":True, "ye":True, valid = {"yes": True, "y": True, "ye": True,
"no":False, "n":False} "no": False, "n": False}
if default == None: if default is None:
prompt = " [y/n] " prompt = " [y/n] "
elif default == "yes": elif default == "yes":
prompt = " [Y/n] " prompt = " [Y/n] "
...@@ -32,14 +33,16 @@ def query_yes_no(question, default="yes"): ...@@ -32,14 +33,16 @@ def query_yes_no(question, default="yes"):
elif choice in valid: elif choice in valid:
return valid[choice] return valid[choice]
else: else:
sys.stdout.write("Please respond with 'yes' or 'no' "\ sys.stdout.write("Please respond with 'yes' or 'no' "
"(or 'y' or 'n').\n") "(or 'y' or 'n').\n")