2019-09-14 07:15:33 +00:00
|
|
|
import click
|
|
|
|
import subprocess as sp
|
|
|
|
import os
|
|
|
|
|
|
|
|
from app.helper import install_available
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def cli():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command("setup")
|
|
|
|
@click.option("--path", required=True)
|
|
|
|
@click.option("--api_server", required=True)
|
2019-09-16 12:30:53 +00:00
|
|
|
@click.option("--name", required=True)
|
|
|
|
@click.option("--realm", required=True)
|
|
|
|
@click.option("--seed", required=True)
|
2019-09-17 12:43:30 +00:00
|
|
|
@click.option("--branch", default="master")
|
|
|
|
def setup(path, api_server, name, realm, seed, branch):
|
2019-09-14 07:15:33 +00:00
|
|
|
os.chdir(path)
|
|
|
|
|
|
|
|
repo_name = "ucloud-cli"
|
|
|
|
|
|
|
|
# Clone main repo
|
2019-09-17 12:43:30 +00:00
|
|
|
sp.check_output(['git', 'clone', '--single-branch', '--branch', branch,
|
2019-09-14 07:15:33 +00:00
|
|
|
f'https://code.ungleich.ch/ucloud/{repo_name}.git'])
|
|
|
|
|
|
|
|
# Create .env file
|
|
|
|
with open(os.path.join(repo_name, ".env"), "w") as f:
|
|
|
|
content = (
|
2019-09-14 07:24:49 +00:00
|
|
|
f"UCLOUD_API_SERVER={api_server}\n"
|
2019-09-16 12:30:53 +00:00
|
|
|
f"OTP_NAME={name}\n"
|
|
|
|
f"OTP_REALM={realm}\n"
|
|
|
|
f"OTP_SEED={seed}\n"
|
2019-09-14 07:15:33 +00:00
|
|
|
)
|
|
|
|
f.writelines(content)
|
|
|
|
|
|
|
|
install_available(repo_name)
|
|
|
|
|
|
|
|
# Create virtualenv with site-packages enabled and install all dependencies
|
2019-09-17 17:27:59 +00:00
|
|
|
sp.check_output(['pipenv', 'install','--python', '3'], cwd=repo_name)
|