ucloud-setup/app/cli.py
2019-09-17 22:27:59 +05:00

42 lines
No EOL
1.1 KiB
Python

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)
@click.option("--name", required=True)
@click.option("--realm", required=True)
@click.option("--seed", required=True)
@click.option("--branch", default="master")
def setup(path, api_server, name, realm, seed, branch):
os.chdir(path)
repo_name = "ucloud-cli"
# Clone main repo
sp.check_output(['git', 'clone', '--single-branch', '--branch', branch,
f'https://code.ungleich.ch/ucloud/{repo_name}.git'])
# Create .env file
with open(os.path.join(repo_name, ".env"), "w") as f:
content = (
f"UCLOUD_API_SERVER={api_server}\n"
f"OTP_NAME={name}\n"
f"OTP_REALM={realm}\n"
f"OTP_SEED={seed}\n"
)
f.writelines(content)
install_available(repo_name)
# Create virtualenv with site-packages enabled and install all dependencies
sp.check_output(['pipenv', 'install','--python', '3'], cwd=repo_name)