jenkins-bot has submitted this change and it was merged. Change subject: De-decorate inside_git_dir ......................................................................
De-decorate inside_git_dir Moves inside_git_dir from fragile decorator to `ensure_git_dir` utility function. Saves an import, saves SLOC, saves brainpower. Change-Id: Ic85b0534869f656008db6279294634ae68150acc --- M scap/tasks.py M scap/utils.py 2 files changed, 11 insertions(+), 34 deletions(-) Approvals: Chad: Looks good to me, approved 20after4: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/scap/tasks.py b/scap/tasks.py index 1dddd11..122a48f 100644 --- a/scap/tasks.py +++ b/scap/tasks.py @@ -574,17 +574,17 @@ return restart.progress('restart_hhvm').run(batch_size=batch_size) -@utils.inside_git_dir def git_remote_exists(location, remote): """Check if remote exists in location""" + utils.ensure_git_dir(location) with utils.cd(location): cmd = '/usr/bin/git config --local --get remote.{}.url'.format(remote) return subprocess.call(cmd, shell=True) == 0 -@utils.inside_git_dir def git_remote_set(location, repo, remote='origin', user='mwdeploy'): """set the remote at location to repo""" + utils.ensure_git_dir(location) with utils.cd(location): if git_remote_exists(location, remote): cmd = '/usr/bin/git remote rm {}'.format(remote) @@ -607,10 +607,11 @@ utils.sudo_check_call(user, cmd) -@utils.inside_git_dir def git_checkout(location, rev, submodules=False, user="mwdeploy"): """Checkout a git repo sha at a location as a user """ + utils.ensure_git_dir(location) + logger = logging.getLogger('git_checkout') with utils.cd(location): logger.debug( @@ -638,13 +639,13 @@ subprocess.check_call(cmd, shell=True) -@utils.inside_git_dir def git_update_deploy_head(deploy_info, location): """updates .git/DEPLOY_HEAD file :param deploy_info: current deploy info to write to file as JSON :param (optional) location: git directory location (default cwd) """ + utils.ensure_git_dir(location) logger = logging.getLogger('git_deploy_file') with utils.cd(location): @@ -655,10 +656,10 @@ f.close() -@utils.inside_git_dir def git_tag_repo(deploy_info, location=os.getcwd()): """creates new tag in deploy repo""" + utils.ensure_git_dir(location) with utils.cd(location): cmd = """ /usr/bin/git tag -fa \\ diff --git a/scap/utils.py b/scap/utils.py index 77eccd2..b356406 100644 --- a/scap/utils.py +++ b/scap/utils.py @@ -9,7 +9,6 @@ import errno import fcntl import hashlib -import inspect import json import logging import os @@ -550,32 +549,9 @@ raise IOError(e.errno, e.strerror, path) -def inside_git_dir(func): - """Decorator to determine if the "location" argument is a git directory""" - def wrapper(*args, **kwargs): - argspec = inspect.getargspec(func) - try: - l = args[argspec.args.index('location')] - except IndexError: - l = None - - if l is None: - d = None - - if argspec.defaults is not None: - defaults = dict(zip( - argspec.args[-len(argspec.defaults):], - argspec.defaults - )) - d = defaults.get('location') - - l = kwargs.get('location', d) - - if l is None or not is_git_dir(l): - raise IOError(errno.ENOENT, 'Location is not a git repo', l) - - return func(*args, **kwargs) - return wrapper +def ensure_git_dir(location): + if location is None or not is_git_dir(location): + raise IOError(errno.ENOENT, 'Location is not a git repo', location) def is_git_dir(path): @@ -594,17 +570,17 @@ sudo_check_call(user, "mkdir -p '{}'".format(path), logger=logger) -@inside_git_dir def git_sha(location, rev): """Returns SHA1 for things like HEAD or HEAD~~""" + ensure_git_dir(location) with cd(location): cmd = '/usr/bin/git rev-parse --verify {}'.format(rev) return subprocess.check_output(cmd, shell=True).strip() -@inside_git_dir def git_next_deploy_tag(location, user=get_real_username()): """Calculates the scap/sync/{date}/{n} tag to use for this deployment""" + ensure_git_dir(location) with cd(location): timestamp = datetime.utcnow() date = timestamp.strftime('%F') -- To view, visit https://gerrit.wikimedia.org/r/240912 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic85b0534869f656008db6279294634ae68150acc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/tools/scap Gerrit-Branch: master Gerrit-Owner: Thcipriani <tcipri...@wikimedia.org> Gerrit-Reviewer: 20after4 <mmod...@wikimedia.org> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Dduvall <dduv...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits