From c8e9b941ab3f6553e182aa7994fe9331f0592177 Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Tue, 23 Apr 2013 08:52:12 -0400 Subject: [PATCH] add --yes on tito release to keep from requiring input --- src/tito/cli.py | 8 ++++++-- src/tito/release.py | 42 +++++++++++++++++++++++------------------- tito.8.asciidoc | 5 +++++ 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/tito/cli.py b/src/tito/cli.py index af9da4a..2321f02 100644 --- a/src/tito/cli.py +++ b/src/tito/cli.py @@ -454,9 +454,12 @@ class ReleaseModule(BaseCliModule): self.parser.add_option("--all", action="store_true", help="Run all release targets configured.") - self.parser.add_option("--test", dest="test", action="store_true", + self.parser.add_option("--test", action="store_true", help="use current branch HEAD instead of latest package tag") + self.parser.add_option("-y", "--yes", dest="auto_accept", action="store_true", + help="Do not require input, just accept commits and builds") + self.parser.add_option("--all-starting-with", dest="all_starting_with", help="Run all release targets starting with the given string.") @@ -623,7 +626,8 @@ class ReleaseModule(BaseCliModule): target=target, releaser_config=releaser_config, no_cleanup=self.options.no_cleanup, - test=self.options.test) + test=self.options.test, + auto_accept=self.options.auto_accept) releaser.release(dry_run=self.options.dry_run, no_build=self.options.no_build, scratch=self.options.scratch) diff --git a/src/tito/release.py b/src/tito/release.py index 21b6825..ca4b5e1 100644 --- a/src/tito/release.py +++ b/src/tito/release.py @@ -50,7 +50,7 @@ class Releaser(object): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - target=None, releaser_config=None, no_cleanup=False, test=False): + target=None, releaser_config=None, no_cleanup=False, test=False, auto_accept=False): self.builder_args = self._parse_builder_args(releaser_config, target) if test: @@ -83,10 +83,18 @@ class Releaser(object): self.dry_run = False self.test = test # releaser must know to use builder designation rather than tag + self.auto_accept = auto_accept # don't ask for input, just go ahead self.no_cleanup = no_cleanup self._check_releaser_config() + def _ask_yes_no(self, prompt="Y/N? ", default_auto_answer=True): + if self.auto_accept: + return default_auto_answer + else: + answer = raw_input(prompt) + return answer.lower() in ['y', 'yes', 'ok', 'sure'] + def _check_releaser_config(self): """ Verify this release target has all the config options it needs. @@ -263,10 +271,10 @@ class RsyncReleaser(Releaser): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - target=None, releaser_config=None, no_cleanup=False, test=False, + target=None, releaser_config=None, no_cleanup=False, test=False, auto_accept=False, prefix="temp_dir="): Releaser.__init__(self, name, version, tag, build_dir, pkg_config, - global_config, user_config, target, releaser_config, no_cleanup, test) + global_config, user_config, target, releaser_config, no_cleanup, test, auto_accept) self.build_dir = build_dir self.prefix = prefix @@ -376,9 +384,9 @@ class YumRepoReleaser(RsyncReleaser): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - target=None, releaser_config=None, no_cleanup=False, test=False): + target=None, releaser_config=None, no_cleanup=False, test=False, auto_accept=False): RsyncReleaser.__init__(self, name, version, tag, build_dir, pkg_config, - global_config, user_config, target, releaser_config, no_cleanup, test, + global_config, user_config, target, releaser_config, no_cleanup, test, auto_accept, prefix="yumrepo-") def _read_rpm_header(self, ts, new_rpm_path): @@ -444,9 +452,9 @@ class FedoraGitReleaser(Releaser): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - target=None, releaser_config=None, no_cleanup=False, test=False): + target=None, releaser_config=None, no_cleanup=False, test=False, auto_accept=False): Releaser.__init__(self, name, version, tag, build_dir, pkg_config, - global_config, user_config, target, releaser_config, no_cleanup, test) + global_config, user_config, target, releaser_config, no_cleanup, test, auto_accept) self.git_branches = \ self.releaser_config.get(self.target, "branches").split(" ") @@ -513,8 +521,7 @@ class FedoraGitReleaser(Releaser): print("") print("###############################") print("") - answer = raw_input("Would you like to edit this commit message? [y/n] ") - if answer.lower() in ['y', 'yes', 'ok', 'sure']: + if self._ask_yes_no("Would you like to edit this commit message? [y/n] ", False): debug("Opening editor for user to edit commit message in: %s" % name) editor = 'vi' if "EDITOR" in os.environ: @@ -548,8 +555,7 @@ class FedoraGitReleaser(Releaser): print(diff_output) print("") print("##### Please review the above diff #####") - answer = raw_input("Do you wish to proceed with commit? [y/n] ") - if answer.lower() not in ['y', 'yes', 'ok', 'sure']: + if not self._ask_yes_no("Do you wish to proceed with commit? [y/n] "): print("Fine, you're on your own!") self.cleanup() sys.exit(1) @@ -712,9 +718,9 @@ class CvsReleaser(Releaser): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - target=None, releaser_config=None, no_cleanup=False, test=False): + target=None, releaser_config=None, no_cleanup=False, test=False, auto_accept=False): Releaser.__init__(self, name, version, tag, build_dir, pkg_config, - global_config, user_config, target, releaser_config, no_cleanup, test) + global_config, user_config, target, releaser_config, no_cleanup, test, auto_accept) self.package_workdir = os.path.join(self.working_dir, self.project_name) @@ -862,8 +868,7 @@ class CvsReleaser(Releaser): print("") print("##### Please review the above diff #####") - answer = raw_input("Do you wish to proceed with commit? [y/n] ") - if answer.lower() not in ['y', 'yes', 'ok', 'sure']: + if not self._ask_yes_no("Do you wish to proceed with commit? [y/n] "): print("Fine, you're on your own!") self.cleanup() sys.exit(1) @@ -893,8 +898,7 @@ class CvsReleaser(Releaser): print("") print("###############################") print("") - answer = raw_input("Would you like to edit this commit message? [y/n] ") - if answer.lower() in ['y', 'yes', 'ok', 'sure']: + if self._ask_yes_no("Would you like to edit this commit message? [y/n] ", False): debug("Opening editor for user to edit commit message in: %s" % name) editor = 'vi' if "EDITOR" in os.environ: @@ -958,9 +962,9 @@ class KojiReleaser(Releaser): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - target=None, releaser_config=None, no_cleanup=False, test=False): + target=None, releaser_config=None, no_cleanup=False, test=False, auto_accept=False): Releaser.__init__(self, name, version, tag, build_dir, pkg_config, - global_config, user_config, target, releaser_config, no_cleanup, test) + global_config, user_config, target, releaser_config, no_cleanup, test, auto_accept) self.only_tags = [] if 'ONLY_TAGS' in os.environ: diff --git a/tito.8.asciidoc b/tito.8.asciidoc index 9b997e5..3491637 100644 --- a/tito.8.asciidoc +++ b/tito.8.asciidoc @@ -17,6 +17,8 @@ tito build --test --rpm tito build [OPTIONS] +tito release [OPTIONS] TARGET + tito report @@ -211,6 +213,9 @@ if you have defined release targets yum-f15 and yum-f14 in releasers.conf, Perform a scratch build in Koji. Can be specified using environment variable SCRATCH set to 1 as well. +--yes:: +Do not ask to confirm release commits or edit their messages. + `tito report` ~~~~~~~~~~~~~