Skip to content

Commit

Permalink
Merge pull request #5 from mrprompt/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mrprompt committed May 28, 2017
2 parents 46d1528 + 9843379 commit 6a9344d
Show file tree
Hide file tree
Showing 21 changed files with 399 additions and 283 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -13,7 +13,6 @@ before_script:
- pip install -Iv "codeclimate-test-reporter<4.4"

script:
- python setup.py test
- py.test --cov=deploybot test/

after_success:
Expand Down
2 changes: 1 addition & 1 deletion bitbucket-pipelines.yml
Expand Up @@ -5,4 +5,4 @@ pipelines:
- step:
script:
- pip install -r requirements.txt
- python setup.py test
- py.test --cov=deploybot test/
6 changes: 0 additions & 6 deletions cli.py

This file was deleted.

91 changes: 2 additions & 89 deletions cli/__init__.py
@@ -1,60 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from deploybot.client import Client
from deploybot.deploy import Deploy
from deploybot.user import User
from deploybot.repository import Repository
from deploybot.environment import Environment
from deploybot.server import Server
from .help import Help

import json
import tableprint
import copy
import os
import sys


def run(command):
account = os.environ.get('DEPLOYBOT_ACCOUNT')
token = os.environ.get('DEPLOYBOT_TOKEN')
client = Client(account, token)

if command == "repository":
client = Repository(client)
elif command == "user":
client = User(client)
elif command == "environment":
client = Environment(client)
elif command == "deploy":
client = Deploy(client)
elif command == "server":
client = Server(client)
elif command == "help":
client = Help()
else:
raise IndexError("Command not found")

return client


def headers(command):
if command == "repository":
headers = ('ID', 'Title', 'Name')
elif command == "user":
headers = ('ID', 'Name', 'Email', 'Admin')
elif command == "environment":
headers = ('ID', 'Repository ID', 'Environment Name', 'Branch', 'Automatic', 'Current')
elif command == "deploy":
headers = ('ID', 'Repository ID', 'Environment ID', 'State', 'Version')
elif command == "server":
headers = ('ID', 'Environment ID', 'Name', 'Protocol')
elif command == "help":
headers = ('Command', 'Description', 'Parameters')
else:
raise IndexError("Header not found")

return headers


def body(command, cmd, item):
Expand Down Expand Up @@ -149,7 +93,7 @@ def body(command, cmd, item):
else:
raise IndexError("Body not found")

return body
return list(map(lambda x: unicode(x), body))


def response(cmd, param, result):
Expand All @@ -166,35 +110,4 @@ def response(cmd, param, result):

data.append(body(cmd, param, item))

return data


def main(out=sys.stdout):
column_width = os.environ.get('COLUMN_WIDTH', 32)
style = os.environ.get('COLUMN_STYLE', 'fancy_grid')

try:
arg1 = sys.argv[1]
args = copy.copy(sys.argv)

args.pop(0)
args.pop(0)

if arg1 == 'help':
cmd = 'list'
else:
cmd = args.pop(0)

result = getattr(run(arg1), cmd)(*args)
header = headers(arg1)
data = response(arg1, cmd, result)
except Exception as e:
header = ('Error', 'Code')
data = [
(
str(e),
"try %s help" % sys.argv[0],
)
]

tableprint.table(data, headers=header, width=int(column_width), style=style, out=out)
return data
17 changes: 17 additions & 0 deletions cli/cli.py
@@ -0,0 +1,17 @@
import click
from .user import user
from .server import server
from .environment import environment
from .repository import repository
from .deploy import deploy


@click.group()
def cli():
pass

cli.add_command(user)
cli.add_command(server)
cli.add_command(environment)
cli.add_command(repository)
cli.add_command(deploy)
12 changes: 12 additions & 0 deletions cli/config.py
@@ -0,0 +1,12 @@
import os
from deploybot.client import Client


class Config(object):

def __init__(self):
self.account = os.environ.get('DEPLOYBOT_ACCOUNT')
self.token = os.environ.get('DEPLOYBOT_TOKEN')
self.width = os.environ.get('COLUMN_WIDTH', 32)
self.style = os.environ.get('COLUMN_STYLE', 'fancy_grid')
self.client = Client(self.account, self.token)
55 changes: 55 additions & 0 deletions cli/deploy.py
@@ -0,0 +1,55 @@
from deploybot.deploy import Deploy
from .config import Config
from . import response
from io import StringIO
import click
import tableprint

output = StringIO()
pass_config = click.make_pass_decorator(Config, ensure=True)
header = ('ID', 'Repository ID', 'Environment ID', 'State', 'Version')


@click.group('deploy', short_help='Deploy commands')
def deploy():
pass


@deploy.command('list')
@click.argument('repository', type=int)
@click.argument('environment', type=int)
@pass_config
def deploy_list(config, repository, environment):
"""List deploys"""
client = Deploy(config.client)
result = client.list(repository, environment)
data = response('deploy', 'list', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())


@deploy.command('get')
@click.argument('id', type=int)
@pass_config
def deploy_get(config, id):
"""Get info from deploy"""
client = Deploy(config.client)
result = client.get(id)
data = response('deploy', 'get', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())


@deploy.command('trigger')
@click.argument('id', type=int)
@pass_config
def deploy_get(config, id):
"""Trigger a specific deploy"""
client = Deploy(config.client)
result = client.get(id)
data = response('deploy', 'trigger', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())
41 changes: 41 additions & 0 deletions cli/environment.py
@@ -0,0 +1,41 @@
from deploybot.environment import Environment
from .config import Config
from . import response
from io import StringIO
import click
import tableprint

output = StringIO()
pass_config = click.make_pass_decorator(Config, ensure=True)
header = ('ID', 'Repository ID', 'Environment Name', 'Branch', 'Automatic', 'Current')


@click.group('environment', short_help='Environment commands')
def environment():
pass


@environment.command('list')
@click.argument('repository', type=int, required=False)
@pass_config
def environment_list(config, repository=None):
"""List environments"""
client = Environment(config.client)
result = client.list(repository)
data = response('environment', 'list', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())


@environment.command('get')
@click.argument('id', type=int)
@pass_config
def environment_get(config, id):
"""Get info from environment"""
client = Environment(config.client)
result = client.get(id)
data = response('environment', 'get', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())
80 changes: 0 additions & 80 deletions cli/help.py

This file was deleted.

40 changes: 40 additions & 0 deletions cli/repository.py
@@ -0,0 +1,40 @@
from deploybot.repository import Repository
from .config import Config
from . import response
from io import StringIO
import click
import tableprint

output = StringIO()
pass_config = click.make_pass_decorator(Config, ensure=True)
header = ('ID', 'Title', 'Name')


@click.group('repository', short_help='Repository commands')
def repository():
pass


@repository.command('list')
@pass_config
def repository_list(config):
"""List repositorys"""
client = Repository(config.client)
result = client.list()
data = response('repository', 'list', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())


@repository.command('get')
@click.argument('id', type=int)
@pass_config
def repository_get(config, id):
"""Get info from repository"""
client = Repository(config.client)
result = client.get(id)
data = response('repository', 'get', result)

tableprint.table(data, headers=header, width=int(config.width), style=config.style, out=output)
click.echo(output.getvalue())

0 comments on commit 6a9344d

Please sign in to comment.