Skip to content

Commit

Permalink
Merge pull request #370 from JrGoodle/git-refactor
Browse files Browse the repository at this point in the history
Git refactor
  • Loading branch information
JrGoodle committed Nov 4, 2017
2 parents 3cac447 + 411c028 commit 5e7d8b1
Show file tree
Hide file tree
Showing 14 changed files with 1,214 additions and 1,018 deletions.
6 changes: 6 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ checks:
argument-count:
config:
threshold: 5
complex-logic:
config:
threshold: 7
file-lines:
config:
threshold: 1000
method-complexity:
config:
threshold: 7
method-count:
config:
threshold: 30
Expand Down
16 changes: 9 additions & 7 deletions clowder/clowder/cli/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def herd(clowder, group_names, **kwargs):
branch (str): Branch to attempt to herd
tag (str): Tag to attempt to herd
depth (int): Git clone depth. 0 indicates full clone, otherwise must be a positive integer
rebase (bool): Whether to use rebase instead of pulling latest changes. Defaults to False
rebase (bool): Whether to use rebase instead of pulling latest changes
project_names (list[str]) project_names: Project names to herd
skip (list[str]): Project names to skip
"""
Expand Down Expand Up @@ -200,7 +200,7 @@ def herd_parallel(clowder, group_names, **kwargs):
branch (str): Branch to attempt to herd
tag (str): Tag to attempt to herd
depth (int): Git clone depth. 0 indicates full clone, otherwise must be a positive integer
rebase (bool): Whether to use rebase instead of pulling latest changes. Defaults to False
rebase (bool): Whether to use rebase instead of pulling latest changes
project_names (list[str]): Project names to herd
skip (list[str]): Project names to skip
"""
Expand Down Expand Up @@ -282,12 +282,12 @@ def reset(clowder, group_names, **kwargs):
def sync(clowder, project_names, rebase=False, parallel=False):
"""Sync projects
.. py:function:: sync(clowder, project_names, rebase=False, parallel=False)
:param ClowderController clowder: ClowderController instance
:param list[str] project_names: Project names to sync
:param Optional[bool] rebase: Whether to use rebase instead of pulling latest changes.
Defaults to False
:param Optional[bool] parallel: Whether command is being run in parallel, affects output.
Defaults to False
:param Optional[bool] rebase: Whether to use rebase instead of pulling latest changes
:param Optional[bool] parallel: Whether command is being run in parallel, affects output
"""

projects = filter_projects_on_project_names(clowder.groups, project_names)
Expand Down Expand Up @@ -377,8 +377,10 @@ def _reset_parallel(clowder, group_names, **kwargs):
def _sync_parallel(projects, rebase=False):
"""Sync projects in parallel
.. py:function:: sync(projects, rebase=False)
:param list[Project] projects: Projects to sync
:param Optional[bool] rebase: Whether to use rebase instead of pulling latest changes. Defaults to False
:param Optional[bool] rebase: Whether to use rebase instead of pulling latest changes
"""

print(' - Sync forks in parallel\n')
Expand Down
10 changes: 6 additions & 4 deletions clowder/clowder/cli/start_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ def _start_tracking(self):
def _start_groups(clowder, group_names, skip, branch, tracking=False):
"""Start feature branch for groups
.. py:function:: _start_groups(clowder, group_names, skip, branch, tracking=False)
:param ClowderController clowder: ClowderController instance
:param list[str] group_names: Group names to create branches for
:param list[str] skip: Project names to skip
:param str branch: Local branch name to create
:param Optional[bool] tracking: Whether to create a remote branch with tracking relationship.
Defaults to False
:param Optional[bool] tracking: Whether to create a remote branch with tracking relationship
"""

groups = filter_groups(clowder.groups, group_names)
Expand All @@ -107,12 +108,13 @@ def _start_groups(clowder, group_names, skip, branch, tracking=False):
def _start_projects(clowder, project_names, skip, branch, tracking=False):
"""Start feature branch for projects
.. py:function:: _start_projects(clowder, project_names, skip, branch, tracking=False)
:param ClowderController clowder: ClowderController instance
:param list[str] project_names: Project names to creat branches for
:param list[str] skip: Project names to skip
:param str branch: Local branch name to create
:param Optional[bool] tracking: Whether to create a remote branch with tracking relationship.
Defaults to False
:param Optional[bool] tracking: Whether to create a remote branch with tracking relationship
"""

projects = filter_projects_on_project_names(clowder.groups, project_names)
Expand Down
30 changes: 2 additions & 28 deletions clowder/clowder/clowder_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,8 @@ def main():

print()
with ClowderApp() as app:
try:
app.run()
except CaughtSignal as err:
# determine what the signal is, and do something with it?
from signal import SIGINT, SIGABRT

if err.signum == SIGINT:
# do something... maybe change the exit code?
app.exit_code = 110
elif err.signum == SIGABRT:
# do something else...
app.exit_code = 111
except FrameworkError:
# do something when a framework error happens
# print("FrameworkError => %s" % e)

# and maybe set the exit code to something unique as well
# app.exit_code = 300

app.args.print_help()
sys.exit(1)
finally:
# Maybe we want to see a full-stack trace for the above
# exceptions, but only if --debug was passed?
if app.debug:
import traceback
traceback.print_exc()
print()
app.run()
print()


if __name__ == '__main__':
Expand Down
47 changes: 28 additions & 19 deletions clowder/clowder/clowder_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
import clowder.util.formatting as fmt
from clowder.error.clowder_error import ClowderError
from clowder.git.project_repo import ProjectRepo
from clowder.git.util import (
existing_git_repository,
format_project_ref_string,
format_project_string,
print_validation
)
from clowder.util.connectivity import is_offline
from clowder.util.execute import execute_command
from clowder.util.file_system import (
Expand Down Expand Up @@ -44,6 +50,7 @@ def __init__(self, root_directory):
self.default_ref = 'refs/heads/master'
self.remote = 'origin'
self.clowder_path = os.path.join(self.root_directory, '.clowder')
self.repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)

# Create clowder.yaml symlink if .clowder dir and yaml file exist
clowder_symlink = os.path.join(self.root_directory, 'clowder.yaml')
Expand All @@ -69,25 +76,24 @@ def add(self, files):
:param str files: Files to git add
"""

ProjectRepo(self.clowder_path, self.remote, self.default_ref).add(files)
self.repo.add(files)

def branches(self):
"""Print current local branches"""

ProjectRepo(self.clowder_path, self.remote, self.default_ref).print_branches(local=True, remote=True)
self.repo.print_branches(local=True, remote=True)

def checkout(self, ref):
"""Checkout ref in clowder repo
:param str ref: Ref to git checkout
"""

repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
if self.is_dirty():
print(' - Dirty repo. Please stash, commit, or discard your changes')
repo.status_verbose()
self.repo.status_verbose()
return
repo.checkout(ref)
self.repo.checkout(ref)

def clean(self):
"""Discard changes in clowder repo
Expand All @@ -97,7 +103,7 @@ def clean(self):

if self.is_dirty():
print(' - Discard current changes')
ProjectRepo(self.clowder_path, self.remote, self.default_ref).clean(args='fdx')
self.repo.clean(args='fdx')
return

print(' - No changes to discard')
Expand All @@ -108,15 +114,15 @@ def commit(self, message):
:param str message: Git commit message
"""

ProjectRepo(self.clowder_path, self.remote, self.default_ref).commit(message)
self.repo.commit(message)

def git_status(self):
"""Print clowder repo git status
Equivalent to: ``git status -vv``
"""

ProjectRepo(self.clowder_path, self.remote, self.default_ref).status_verbose()
self.repo.status_verbose()

def init(self, url, branch):
"""Clone clowder repo from url
Expand All @@ -128,7 +134,7 @@ def init(self, url, branch):
# Register exit handler to remove files if cloning repo fails
atexit.register(self.init_exit_handler)

ProjectRepo(self.clowder_path, self.remote, self.default_ref).create_clowder_repo(url, branch)
self.repo.create_clowder_repo(url, branch)
self.link()

def init_exit_handler(self):
Expand All @@ -147,12 +153,14 @@ def is_dirty(self):
:rtype: bool
"""

return ProjectRepo(self.clowder_path, self.remote, self.default_ref).is_dirty()
return self.repo.is_dirty()

def link(self, version=None):
"""Create symlink pointing to clowder.yaml file
:param Optional[str] version: Version name of clowder.yaml to link. Defaults to None for default clowder.yaml
.. py:function:: link(version=None)
:param Optional[str] version: Version name of clowder.yaml to link
"""

if version is None:
Expand All @@ -174,22 +182,23 @@ def link(self, version=None):
def print_status(self, fetch=False):
"""Print clowder repo status
:param Optional[str] fetch: Fetch before printing status. Defaults to False
.. py:function:: print_status(fetch=False)
:param Optional[str] fetch: Fetch before printing status
"""

repo_path = os.path.join(self.root_directory, '.clowder')
if not ProjectRepo.existing_git_repository(repo_path):
if not existing_git_repository(repo_path):
output = colored('.clowder', 'green')
print(output)
return

if not is_offline() and fetch:
print(' - Fetch upstream changes for clowder repo')
repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
repo.fetch(self.remote)
self.repo.fetch(self.remote)

project_output = ProjectRepo.format_project_string(repo_path, '.clowder')
current_ref_output = ProjectRepo.format_project_ref_string(repo_path)
project_output = format_project_string(self.repo, '.clowder')
current_ref_output = format_project_ref_string(self.repo)

clowder_symlink = os.path.join(self.root_directory, 'clowder.yaml')
if not os.path.islink(clowder_symlink):
Expand Down Expand Up @@ -228,8 +237,8 @@ def run_command(self, command):
def _validate_groups(self):
"""Validate status of clowder repo"""

if not ProjectRepo(self.clowder_path, self.remote, self.default_ref).validate_repo():
ProjectRepo.print_validation(self.clowder_path)
if not self.repo.validate_repo():
print_validation(self.repo)
print()
sys.exit(1)

Expand Down

0 comments on commit 5e7d8b1

Please sign in to comment.