From: Frederic Massart Date: Thu, 9 Aug 2012 01:48:46 +0000 (+0800) Subject: Moodle rebase has a better arguments logic X-Git-Tag: v0.1~59 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=60e113ec68330ebe60ec5c3890d67da4983e5cfa;p=mdk.git Moodle rebase has a better arguments logic --- diff --git a/moodle-rebase.py b/moodle-rebase.py index 44be35a..c699c02 100755 --- a/moodle-rebase.py +++ b/moodle-rebase.py @@ -11,31 +11,36 @@ C = config.Conf().get Wp = workplace.Workplace() # Arguments -parser = argparse.ArgumentParser(description="Backports a branch") +parser = argparse.ArgumentParser(description="Rebases branches") parser.add_argument('-i', '--issues', metavar='issues', required=True, nargs='+', help='issues to be rebased') parser.add_argument('-s', '--suffix', metavar='suffix', help='the suffix of the branch of those issues') -parser.add_argument('-v', '--versions', metavar='version', nargs='+', choices=[ str(x) for x in range(13, C('masterBranch')) ] + ['master'], help='versions to rebase the issues on. Ignored if name is set.') +parser.add_argument('-v', '--versions', metavar='version', nargs='+', choices=[ str(x) for x in range(13, C('masterBranch')) ] + ['master'], help='versions to rebase the issues on. Ignored if names is set.') parser.add_argument('-p', '--push', action='store_true', help='push the branch after successful rebase') parser.add_argument('-r', '--remote', metavar='remote', help='the remote to push the branch to. Default is %s.' % C('mineRepo')) parser.add_argument('-f', '--force-push', action='store_true', help='Force the push', dest='forcepush') -parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance to work on') +parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances to rebase') args = parser.parse_args() -instances = [] -if args.versions == None: - M = Wp.resolve(args.name) - if not M: - debug('This is not a Moodle instance') - sys.exit(1) - instances.append(M) -else: - for v in args.versions: - name = Wp.generateInstanceName(v) - if Wp.isMoodle(name): - instances.append(Wp.get(name)) +names = args.names +issues = args.issues +versions = args.versions + +# If we don't have a version, we need an instance +if not names and not versions: + debug('This is not a Moodle instance') + sys.exit(1) + +# We don't have any names but some versions are set +if not names: + names = [] + for v in versions: + names.append(Wp.generateInstanceName(v)) + +# Getting instances +Mlist = Wp.resolveMultiple(names) # Loops over instances to rebase -for M in instances: +for M in Mlist: debug('Working on %s' % (M.get('identifier'))) M.git().fetch('origin') @@ -49,7 +54,7 @@ for M in instances: debug('Stashed your local changes') # Looping over each issue to rebase - for issue in args.issues: + for issue in issues: branch = M.generateBranchName(issue, suffix=args.suffix) if not M.git().hasBranch(branch): debug('Could not find branch %s' % (branch)) @@ -79,8 +84,9 @@ for M in instances: # Stash pop if not stash[1].startswith('No local changes'): pop = M.git().stash(command='pop') - if pop =! 0: + if pop[0] != 0: debug('An error ocured while unstashing your changes') + debug(result[2]) else: debug('Popped the stash')