Skip to content

Commit

Permalink
Merge pull request #382 from JrGoodle/refactor
Browse files Browse the repository at this point in the history
More refactoring
  • Loading branch information
JrGoodle committed Nov 10, 2017
2 parents 06a21db + d111dc2 commit 71ddfc2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ checks:
threshold: 5
complex-logic:
config:
threshold: 7
threshold: 10
file-lines:
config:
threshold: 1000
method-complexity:
config:
threshold: 7
threshold: 10
method-count:
config:
threshold: 30
Expand Down
6 changes: 2 additions & 4 deletions clowder/clowder/git/project_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,8 @@ def start(self, remote, branch, depth, tracking):
except ClowderGitError:
self._exit()
else:
branch_output = fmt.ref_string(branch)
print(' - ' + branch_output + ' already exists')
correct_branch = self._is_branch_checked_out(branch)
if correct_branch:
print(' - ' + fmt.ref_string(branch) + ' already exists')
if self._is_branch_checked_out(branch):
print(' - On correct branch')
else:
try:
Expand Down
42 changes: 28 additions & 14 deletions clowder/clowder/model/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,13 @@ def reset(self, timestamp=None, parallel=False):
repo.reset()

def run(self, commands, ignore_errors, parallel=False):
"""Run command or script in project directory
"""Run commands or script in project directory
.. py:function:: run(commands, ignore_errors, parallel=False)
:param list[str] commands: Command to run
:param list[str] commands: Commands to run
:param bool ignore_errors: Whether to exit if command returns a non-zero exit code
:param Optional[bool] parallel: Whether command is being run in parallel, affects output
:raise ClowderExit:
:param Optional[bool] parallel: Whether commands are being run in parallel, affects output
"""

if not parallel and not existing_git_repository(self.full_path()):
Expand All @@ -396,16 +395,7 @@ def run(self, commands, ignore_errors, parallel=False):
forall_env['FORK_REMOTE'] = self.fork.remote_name

for cmd in commands:
self._print(fmt.command(cmd))
try:
execute_forall_command(cmd, self.full_path(), forall_env, self._print_output)
except ClowderError:
if not ignore_errors:
err = fmt.command_failed_error(cmd)
self._print(err)
if parallel:
raise ClowderError(err)
raise ClowderExit(1)
self._run_forall_command(cmd, forall_env, ignore_errors, parallel)

@project_repo_exists
def start(self, branch, tracking):
Expand Down Expand Up @@ -491,6 +481,30 @@ def _repo(path, remote, ref, recursive, **kwargs):
return ProjectRepoRecursive(path, remote, ref, **kwargs)
return ProjectRepo(path, remote, ref, **kwargs)

def _run_forall_command(self, command, env, ignore_errors, parallel):
"""Run command or script in project directory
:param str command: Command to run
:param dict env: Environment variables
:param bool ignore_errors: Whether to exit if command returns a non-zero exit code
:param bool parallel: Whether command is being run in parallel, affects output
Raises:
ClowderError
ClowderExit
"""

self._print(fmt.command(command))
try:
execute_forall_command(command, self.full_path(), env, self._print_output)
except ClowderError:
if not ignore_errors:
err = fmt.command_failed_error(command)
self._print(err)
if parallel:
raise ClowderError(err)
raise ClowderExit(1)

def _run_herd_command(self, command, repo, protocol, *args, **kwargs):
"""Run herd command
Expand Down

0 comments on commit 71ddfc2

Please sign in to comment.