Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ If you need to change default instance name, used for all future commands, use::

syncano default name_of_new_default_instance


If you do not have an Syncano account use `syncano init` command::

syncano init

And follow the steps. CLI will ask you about `email` and `password`, it will also create an Instance for you.
After `syncano init` you can start with getting the list of your Instances::

syncano instances list


To obtain a help, type::

syncano --help

To display a help for specific command, type::

syncano instances --help

And::

syncano instances list --help


Documentation
=============

Expand Down
4 changes: 2 additions & 2 deletions syncano_cli/account/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, config_path):
self.connection = syncano.connect()
self.config_path = config_path

def register(self, email, password, first_name, last_name, invitation_key):
def register(self, email, password, first_name=None, last_name=None, invitation_key=None):
api_key = self.connection.connection().register(
email=email,
password=password,
Expand All @@ -19,6 +19,6 @@ def register(self, email, password, first_name, last_name, invitation_key):
invitation_key=invitation_key
)

ACCOUNT_CONFIG.set('DEFAULT', 'api_key', api_key)
ACCOUNT_CONFIG.set('DEFAULT', 'key', api_key)
with open(self.config_path, 'wt') as fp:
ACCOUNT_CONFIG.write(fp)
4 changes: 1 addition & 3 deletions syncano_cli/account/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def top_account():
@click.pass_context
@click.option('--config', help=u'Account configuration file.')
def accounts(ctx, config):
"""
Handle Syncano account functionality;
"""
"""Handle Syncano account functionality."""
account_commands = AccountCommands(config_path=config or ACCOUNT_CONFIG_PATH)
ctx.obj['account_commands'] = account_commands

Expand Down
3 changes: 1 addition & 2 deletions syncano_cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def top_level():
@click.option('--instance-name', help=u'Default instance name.')
def login(context, config, instance_name):
"""
Log in to syncano using email and password and store ACCOUNT_KEY
in configuration file.
Log in to syncano using email and password.
"""
config = config or ACCOUNT_CONFIG_PATH
context.obj['config'] = config
Expand Down
4 changes: 4 additions & 0 deletions syncano_cli/config_commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def top_config():
@click.option('--config', help=u'Account configuration file.')
@click.option('--instance-name', help=u'Instance name.')
def config(ctx, config, instance_name):
"""Allow to manage global instance config."""
instance = get_instance(config, instance_name)
config_command = ConfigCommand(instance=instance)
ctx.obj['config_command'] = config_command
Expand All @@ -27,6 +28,7 @@ def config(ctx, config, instance_name):
@click.argument('name')
@click.argument('value')
def add(ctx, name, value):
"""Add config variable to global instance config."""
config_command = ctx.obj['config_command']
config_command.add(name, value)

Expand All @@ -36,6 +38,7 @@ def add(ctx, name, value):
@click.argument('name')
@click.argument('value')
def modify(ctx, name, value):
"""Modify config value in global instance config."""
config_command = ctx.obj['config_command']
config_command.modify(name, value)

Expand All @@ -44,5 +47,6 @@ def modify(ctx, name, value):
@click.pass_context
@click.argument('name')
def delete(ctx, name):
"""Removes config value from global instance config."""
config_command = ctx.obj['config_command']
config_command.delete(name)
19 changes: 12 additions & 7 deletions syncano_cli/hosting/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ def hosting(ctx, config, instance_name, domain):
@click.pass_context
@click.argument('directory')
def publish(ctx, directory,):

validate_publish(directory)
domain = ctx.obj['domain']
domain = validate_domain(domain) # prepared for user defined domains;
hosting_commands = ctx.obj['hosting_commands']
hosting_commands.publish(domain=domain, base_dir=directory)
click.echo(
"INFO: Your site published. If default, go to: https://{instance_name}--{domain}.syncano.site. "
"Otherwise, go to: https://{instance_name}.syncano.site".format(
hosting_commands.instance.name,
domain=domain
if domain == 'default':
click.echo(
"INFO: Your site published. Go to: https://{instance_name}.syncano.site.".format(
instance_name=hosting_commands.instance.name,
)
)
else:
click.echo(
"INFO: Your site published. Go to: https://{instance_name}--{domain}.syncano.site.".format(
instance_name=hosting_commands.instance.name,
domain=domain
)
)
)


@hosting.group(invoke_without_command=True)
Expand Down
1 change: 1 addition & 0 deletions syncano_cli/init/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
46 changes: 46 additions & 0 deletions syncano_cli/init/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
import click
from syncano_cli.account.command import AccountCommands
from syncano_cli.base.connection import create_connection
from syncano_cli.config import ACCOUNT_CONFIG_PATH
from syncano_cli.init.helpers import random_instance_name
from syncano_cli.instance.command import InstanceCommands


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


@top_init.command()
@click.pass_context
@click.option('--config', help=u'Account configuration file.', default=ACCOUNT_CONFIG_PATH)
@click.option('--email', prompt=True)
@click.option('--password', prompt=True, hide_input=True, confirmation_prompt=True)
def init(ctx, config, email, password):
"""Register new user and create first instance."""
# register new account;
account_command = AccountCommands(config_path=config)
account_command.register(
email=email,
password=password,
)

# register sum up show;
click.echo()
click.echo('Account created for email: {}'.format(email))

# create instance;
connection = create_connection(config)
instance_commands = InstanceCommands(connection)
instance_name = random_instance_name()
instance_commands.create(instance_name=instance_name)
instance_commands.set_default(instance_name=instance_name, config_path=config)

# instace sum up show;
click.echo()
click.echo('Instance `{}` created.'.format(instance_name))

# show instructions;
click.echo()
click.echo(ctx.parent.get_help())
34 changes: 34 additions & 0 deletions syncano_cli/init/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import random

INSTANCE_NAME_ADJECTIVES = [
'autumn', 'hidden', 'bitter', 'misty', 'silent', 'empty', 'dry', 'dark',
'summer', 'icy', 'delicate', 'quiet', 'white', 'cool', 'spring', 'winter',
'patient', 'twilight', 'dawn', 'crimson', 'wispy', 'weathered', 'blue',
'billowing', 'broken', 'cold', 'damp', 'falling', 'frosty', 'green',
'long', 'late', 'lingering', 'bold', 'little', 'morning', 'muddy', 'old',
'red', 'rough', 'still', 'small', 'sparkling', 'throbbing', 'shy',
'wandering', 'withered', 'wild', 'black', 'young', 'holy', 'solitary',
'fragrant', 'aged', 'snowy', 'proud', 'floral', 'restless', 'divine',
'polished', 'ancient', 'purple', 'lively', 'nameless'
]

INSTANCE_NAME_NOUNS = [
'waterfall', 'river', 'breeze', 'moon', 'rain', 'wind', 'sea', 'morning',
'snow', 'lake', 'sunset', 'pine', 'shadow', 'leaf', 'dawn', 'glitter',
'forest', 'hill', 'cloud', 'meadow', 'sun', 'glade', 'bird', 'brook',
'butterfly', 'bush', 'dew', 'dust', 'field', 'fire', 'flower', 'firefly',
'feather', 'grass', 'haze', 'mountain', 'night', 'pond', 'darkness',
'snowflake', 'silence', 'sound', 'sky', 'shape', 'surf', 'thunder',
'violet', 'water', 'wildflower', 'wave', 'water', 'resonance', 'sun',
'wood', 'dream', 'cherry', 'tree', 'fog', 'frost', 'voice', 'paper',
'frog', 'smoke', 'star'
]


def random_instance_name():
return '{adj}-{noun}-{rnd}'.format(
adj=random.choice(INSTANCE_NAME_ADJECTIVES),
noun=random.choice(INSTANCE_NAME_NOUNS),
rnd=random.randint(1000, 9999),
)
6 changes: 3 additions & 3 deletions syncano_cli/instance/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def set_default(cls, instance_name, config_path):
with open(config_path, 'wt') as fp:
ACCOUNT_CONFIG.write(fp)

def create(self, instance_name, description):
def create(self, instance_name, description=None):
kwargs = {
'name': instance_name
}
Expand All @@ -52,7 +52,7 @@ def format_details(cls, instance):

@classmethod
def format_list(cls, instances, default_instance_name):
list_template = """Available instances:{}"""
list_template = """Available Instances:{}"""
lines = ''

def get_name_label(name, default_instance_name):
Expand All @@ -62,7 +62,7 @@ def get_name_label(name, default_instance_name):

for instance in instances:
lines += u"\n\t- {name}: {description}".format(
description=instance.description or u'N/A',
description=instance.description or u'no description',
name=get_name_label(instance.name, default_instance_name)
)

Expand Down
6 changes: 3 additions & 3 deletions syncano_cli/instance/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def top_instance():
@click.option('--instance-name', help=u'Instance name.')
def instances(ctx, config, instance_name):
"""
Mangage your Instances. Instance is an equivalent of a project or a set of data.
Manage your Instances. Instance is an equivalent of a project or a set of data.
It contains information about Sockets, Data Classes, Data Objects and more.
You can own and/or belong to multiple instances.
You can own and/or belong to multiple Instances.
"""
connection = create_connection(config, instance_name)
instance_commands = InstanceCommands(connection)
Expand Down Expand Up @@ -52,7 +52,7 @@ def details(ctx, instance_name):
def delete(ctx, instance_name):
instance_name = get_instance_name(ctx.obj['config'], instance_name) # default one if no provided;
confirmed_name = click.prompt('Are you sure that you want to delete '
'instance {}? Type instance name again'.format(instance_name))
'Instance {}? Type instance name again'.format(instance_name))
if confirmed_name == instance_name:
ctx.obj['instance_commands'].delete(instance_name)
else:
Expand Down
6 changes: 5 additions & 1 deletion syncano_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from syncano_cli.custom_sockets.commands import top_sockets
from syncano_cli.execute.commands import top_execute
from syncano_cli.hosting.commands import top_hosting
from syncano_cli.init.commands import top_init
from syncano_cli.instance.commands import top_instance
from syncano_cli.parse_to_syncano.commands import top_migrate
from syncano_cli.sync.commands import top_sync
Expand All @@ -21,12 +22,15 @@
top_config,
top_execute,
top_hosting,
top_init,
top_instance,
top_level,
top_migrate,
top_sync,
top_sockets,
])

],
)


def main():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_register(self):
self.runner.invoke(cli, args=['accounts', 'register', email], input='test1234\ntest1234', obj={})

# check if api key is written in the config file;
self.assert_config_variable_exists(ACCOUNT_CONFIG, 'DEFAULT', 'api_key')
self.assert_config_variable_exists(ACCOUNT_CONFIG, 'DEFAULT', 'key')

# restore old connection in Syncano LIB; To remove instance in tearDown;
self.connection.connection().api_key = old_key