Skip to content

Commit

Permalink
Merge pull request #380 from JrGoodle/refactor
Browse files Browse the repository at this point in the history
Various refactoring
  • Loading branch information
JrGoodle committed Nov 9, 2017
2 parents 9e80303 + 13b7174 commit 5e23bfc
Show file tree
Hide file tree
Showing 40 changed files with 371 additions and 231 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ engines:
enabled: true
shellcheck:
enabled: true
sonar-python:
enabled: true

ratings:
paths:
Expand Down
17 changes: 4 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,18 @@ matrix:

before_install: script/bootstrap "$PYVERSION"

install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install github-release; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then sudo -H pip3 install twine wheel; fi
- sudo pip install awscli
install: script/travis/install

before_script:
- script/setup "$PYVERSION"
- script/test
before_script: script/travis/before_script

script:
- if [ "$TARGET" = "cats" ]; then clowder-test -c cats all; fi
- if [ "$TARGET" = "cocos2d" ]; then clowder-test -c cocos2d all; fi
- if [ "$TARGET" = "llvm" ]; then clowder-test -c llvm all; fi
- if [ "$TARGET" = "parallel" ]; then clowder-test -c parallel; fi
- if [ "$TARGET" = "parallel" ]; then clowder-test parallel; fi
- if [ "$TARGET" = "swift" ]; then clowder-test -c swift all; fi

after_script:
- coverage combine examples/cats examples/cocos2d-objc examples/llvm-projects examples/swift-projects
- coverage xml
- ./cc-test-reporter format-coverage --output "coverage/codeclimate.$TRAVIS_JOB_NUMBER.json"
- aws s3 sync coverage/ "s3://clowder-coverage/coverage/$TRAVIS_BUILD_NUMBER"
after_script: script/travis/after_script

after_success: if [ "$TRAVIS_OS_NAME" = "osx" ]; then script/deploy; fi

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# `clowder`
[![Build Status](https://travis-ci.org/JrGoodle/clowder.svg)](https://travis-ci.org/JrGoodle/clowder)
[![Coverage Status](https://coveralls.io/repos/github/JrGoodle/clowder/badge.svg?branch=master)](https://coveralls.io/github/JrGoodle/clowder?branch=master)
[![Maintainability](https://api.codeclimate.com/v1/badges/56c92799de08f9ef9258/maintainability)](https://codeclimate.com/github/JrGoodle/clowder/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/56c92799de08f9ef9258/test_coverage)](https://codeclimate.com/github/JrGoodle/clowder/test_coverage)
[![PyPI version](https://badge.fury.io/py/clowder-repo.svg)](https://badge.fury.io/py/clowder-repo)
Expand Down
9 changes: 6 additions & 3 deletions clowder/clowder/cli/init_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from __future__ import print_function

import os
import sys

from cement.ext.ext_argparse import ArgparseController, expose
from termcolor import colored, cprint

from clowder.clowder_repo import CLOWDER_REPO
from clowder.error.clowder_exit import ClowderExit
from clowder.util.connectivity import network_connection_required


Expand Down Expand Up @@ -42,11 +42,14 @@ def init(self):

@network_connection_required
def _init(self):
"""Clowder init command private implementation"""
"""Clowder init command private implementation
:raise ClowderExit:
"""

if os.path.isdir(CLOWDER_REPO.clowder_path):
cprint('Clowder already initialized in this directory\n', 'red')
sys.exit(1)
raise ClowderExit(1)

url_output = colored(self.app.pargs.url, 'green')
print('Create clowder repo from ' + url_output + '\n')
Expand Down
7 changes: 4 additions & 3 deletions clowder/clowder/cli/parallel_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import multiprocessing as mp
import os
import signal
import sys

import psutil
from termcolor import cprint

import clowder.util.formatting as fmt
from clowder.error.clowder_exit import ClowderExit
from clowder.util.progress import Progress
from clowder.util.clowder_utils import (
filter_groups,
Expand Down Expand Up @@ -397,6 +397,7 @@ def pool_handler(count):
"""Pool handler for finishing parallel jobs
:param int count: Total count of projects in progress bar
:raise ClowderExit:
"""

print()
Expand All @@ -410,13 +411,13 @@ def pool_handler(count):
__clowder_pool__.close()
__clowder_pool__.terminate()
cprint('\n - Command failed\n', 'red')
sys.exit(1)
raise ClowderExit(1)
except Exception as err:
__clowder_progress__.close()
__clowder_pool__.close()
__clowder_pool__.terminate()
cprint('\n' + str(err) + '\n', 'red')
sys.exit(1)
raise ClowderExit(1)
else:
__clowder_progress__.complete()
__clowder_progress__.close()
Expand Down
34 changes: 20 additions & 14 deletions clowder/clowder/cli/prune_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

from __future__ import print_function

import sys

from cement.ext.ext_argparse import ArgparseController, expose
from termcolor import cprint

from clowder.clowder_controller import CLOWDER_CONTROLLER
from clowder.clowder_repo import print_clowder_repo_status
from clowder.error.clowder_error import ClowderError
from clowder.util.connectivity import network_connection_required
from clowder.util.decorators import valid_clowder_yaml_required
from clowder.util.clowder_utils import (
Expand Down Expand Up @@ -158,11 +157,14 @@ def _prune_groups(groups, branch, **kwargs):
local_branch_exists = existing_branch_groups(groups, branch, is_remote=False)
remote_branch_exists = existing_branch_groups(groups, branch, is_remote=True)

_validate_branches(local, remote, local_branch_exists, remote_branch_exists)

for group in groups:
if group.existing_branch(branch, is_remote=remote):
run_group_command(group, skip, 'prune', branch, force=force, local=local, remote=remote)
try:
_validate_branches(local, remote, local_branch_exists, remote_branch_exists)
except ClowderError:
pass
else:
for group in groups:
if group.existing_branch(branch, is_remote=remote):
run_group_command(group, skip, 'prune', branch, force=force, local=local, remote=remote)


def _prune_projects(projects, branch, **kwargs):
Expand All @@ -188,10 +190,13 @@ def _prune_projects(projects, branch, **kwargs):
local_branch_exists = existing_branch_projects(projects, branch, is_remote=False)
remote_branch_exists = existing_branch_projects(projects, branch, is_remote=True)

_validate_branches(local, remote, local_branch_exists, remote_branch_exists)

for project in projects:
run_project_command(project, skip, 'prune', branch, force=force, local=local, remote=remote)
try:
_validate_branches(local, remote, local_branch_exists, remote_branch_exists)
except ClowderError:
pass
else:
for project in projects:
run_project_command(project, skip, 'prune', branch, force=force, local=local, remote=remote)


def _validate_branches(local, remote, local_branch_exists, remote_branch_exists):
Expand All @@ -203,24 +208,25 @@ def _validate_branches(local, remote, local_branch_exists, remote_branch_exists)
:param bool remote: Delete remote branch
:param bool local_branch_exists: Whether a local branch exists
:param bool remote_branch_exists: Whether a remote branch exists
:raise ClowderError:
"""

if local and remote:
branch_exists = local_branch_exists or remote_branch_exists
if not branch_exists:
cprint(' - No local or remote branches to prune\n', 'red')
sys.exit()
raise ClowderError
print(' - Prune local and remote branches\n')
return

if remote:
if not remote_branch_exists:
cprint(' - No remote branches to prune\n', 'red')
sys.exit()
raise ClowderError
print(' - Prune remote branches\n')
return

if not local_branch_exists:
print(' - No local branches to prune\n')
sys.exit()
raise ClowderError
print(' - Prune local branches\n')
11 changes: 7 additions & 4 deletions clowder/clowder/cli/save_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from __future__ import print_function

import os
import sys

from cement.ext.ext_argparse import ArgparseController, expose

import clowder.util.formatting as fmt
from clowder import ROOT_DIR
from clowder.clowder_controller import CLOWDER_CONTROLLER
from clowder.clowder_repo import CLOWDER_REPO
from clowder.error.clowder_exit import ClowderExit
from clowder.util.decorators import valid_clowder_yaml_required
from clowder.util.clowder_utils import (
validate_groups,
Expand Down Expand Up @@ -48,11 +48,14 @@ def save(self):

@valid_clowder_yaml_required
def _save(self):
"""Clowder save command private implementation"""
"""Clowder save command private implementation
:raise ClowderExit:
"""

if self.app.pargs.version.lower() == 'default':
print(fmt.save_default_error(self.app.pargs.version))
sys.exit(1)
raise ClowderExit(1)

CLOWDER_REPO.print_status()
validate_projects_exist(CLOWDER_CONTROLLER)
Expand All @@ -65,7 +68,7 @@ def _save(self):
yaml_file = os.path.join(version_dir, 'clowder.yaml')
if os.path.exists(yaml_file):
print(fmt.save_version_exists_error(version_name, yaml_file) + '\n')
sys.exit(1)
raise ClowderExit(1)

print(fmt.save_version(version_name, yaml_file))
save_yaml(CLOWDER_CONTROLLER.get_yaml(), yaml_file)
Expand Down
4 changes: 1 addition & 3 deletions clowder/clowder/cli/sync_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from __future__ import print_function

import sys

from cement.ext.ext_argparse import ArgparseController, expose
from termcolor import cprint

Expand Down Expand Up @@ -56,5 +54,5 @@ def _sync(self):
all_fork_projects = CLOWDER_CONTROLLER.get_all_fork_project_names()
if all_fork_projects == '':
cprint(' - No forks to sync\n', 'red')
sys.exit()
return
sync(CLOWDER_CONTROLLER, all_fork_projects, rebase=self.app.pargs.rebase, parallel=self.app.pargs.parallel)
3 changes: 0 additions & 3 deletions clowder/clowder/cli/yaml_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from __future__ import print_function

import sys

from cement.ext.ext_argparse import ArgparseController, expose

import clowder.util.formatting as fmt
Expand Down Expand Up @@ -49,4 +47,3 @@ def _yaml(self):
print(fmt.yaml_string(CLOWDER_CONTROLLER.get_yaml(resolved=True)))
else:
print_yaml()
sys.exit() # exit early to prevent printing extra newline
9 changes: 8 additions & 1 deletion clowder/clowder/clowder_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

from __future__ import print_function

import sys

import colorama
from cement.core.foundation import CementApp

import clowder.cli as cmd
from clowder.error.clowder_exit import ClowderExit


class ClowderApp(CementApp):
Expand Down Expand Up @@ -57,7 +60,11 @@ def main():

print()
with ClowderApp() as app:
app.run()
try:
app.run()
except ClowderExit:
sys.tracebacklimit = 0
raise
print()


Expand Down
15 changes: 9 additions & 6 deletions clowder/clowder/clowder_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

from __future__ import print_function

import sys

from termcolor import cprint

from clowder.error.clowder_exit import ClowderExit
from clowder.error.clowder_yaml_error import ClowderYAMLError
from clowder.model.defaults import Defaults
from clowder.model.group import Group
Expand All @@ -27,7 +26,10 @@ class ClowderController(object):
"""

def __init__(self):
"""ClowderController __init__"""
"""ClowderController __init__
:raise ClowderExit:
"""

self.defaults = None
self.groups = []
Expand All @@ -39,7 +41,7 @@ def __init__(self):
except (ClowderYAMLError, KeyError) as err:
self.error = err
except (KeyboardInterrupt, SystemExit):
sys.exit(1)
raise ClowderExit(1)

def get_all_fork_project_names(self):
"""Returns all project names containing forks
Expand Down Expand Up @@ -95,6 +97,7 @@ def get_timestamp(self, timestamp_project):
:param str timestamp_project: Project to get timestamp of current HEAD commit
:return: Commit timestamp string
:rtype: str
:raise ClowderExit:
"""

timestamp = None
Expand All @@ -105,7 +108,7 @@ def get_timestamp(self, timestamp_project):

if timestamp is None:
cprint(' - Failed to find timestamp\n', 'red')
sys.exit(1)
raise ClowderExit(1)

return timestamp

Expand Down Expand Up @@ -142,4 +145,4 @@ def _load_yaml(self):
self.groups = []


CLOWDER_CONTROLLER = ClowderController()
CLOWDER_CONTROLLER = ClowderController()

0 comments on commit 5e23bfc

Please sign in to comment.