diff --git a/evolved5g/cli.py b/evolved5g/cli.py index 08b4080..96dc748 100644 --- a/evolved5g/cli.py +++ b/evolved5g/cli.py @@ -1,42 +1,67 @@ """Console script for evolved5g.""" import click from .utils import cookiecutter_generate -from evolved5g.cli_helper import CLI_helper +import os + + +@click.command() +def main(args=None): + """Console script for evolved5g.""" + click.echo( + "The console script for Evolved5G, this messages comes from evolved5g.cli.main") + click.echo("See click documentation at https://click.palletsprojects.com/") + return 0 + +# Creating Command group @click.group() @click.version_option() -@click.pass_context -def cli(ctx): +def cli(): """Console interface for EVOLVED-5G H2020 project""" - ctx.ensure_object(dict) - ctx.obj["helper"] = CLI_helper() + pass -@cli.command() +@click.command() @click.option('--no-input', type=bool, is_flag=True, help='Enables no prompt from the CLI during template generation', default=False) @click.option('-r', '--repo-name', type=str, help='Enter Repository name') @click.option('-p', '--package-name', type=str, help='Enter package name') @click.option('-t', '--template', type=str, help="Provide template location for custom package") -@click.pass_context -def generate(ctx,no_input, repo_name, package_name, template): +def generate(no_input, repo_name, package_name, template): """Generate EVOLVED-5G compliant NetApp from template""" - ctx.obj["helper"].generate(no_input, repo_name, package_name, template) - -@cli.command() -@click.option('--mode',type=click.Choice(['build', 'deploy','destroy'], case_sensitive=False)) -@click.option('--repo',type=str, help='Enter repo name') -@click.pass_context -def run_pipeline(ctx, mode, repo): - """ - """ - ctx.obj["helper"].run_pipeline(mode,repo) - -@cli.command() -@click.option('--id',type=int, help='Enter pipeline id') -@click.pass_context -def check_pipeline(ctx, id): - """ - """ - ctx.obj["helper"].check_pipeline(id) + # __location__ = os.path.realpath(os.path.join( + # os.getcwd(), os.path.dirname(__file__), "..")) + # location = (__location__ + '/cookiecutter_template/') + # click.echo(__location__) # -- for debug + extra = {} + if repo_name: + extra['repoName'] = repo_name + if package_name: + extra['packageName'] = package_name + if template: + cookiecutter_generate(template,no_input=no_input,extra_context=extra) + return + location = "gh:EVOLVED-5G/template" # location to github package + # Create project from the github package template + cookiecutter_generate(location, no_input=no_input, extra_context=extra) + + +# @click.command() +# def connect(): +# """Connect repository to CI/CD""" +# # Connect repository to CI/CD TODO +# click.echo("Connecting Repo to CI/CD") + +# @click.command() +# @click.option('-r', '--repeat', type=int, help='times to repeat', default=1) +# @click.option('-n', '--name', type=str, help='Name to greet', default='World') +# def test(repeat, name): +# """For Testing purposes, TODO Delete""" +# for i in range(repeat): +# click.echo(f'Hello {name}. This is a test') + +#cli.add_command(test) +# cli.add_command(connect) + +cli.add_command(generate) \ No newline at end of file diff --git a/evolved5g/cli_helper.py b/evolved5g/cli_helper.py deleted file mode 100644 index 569882f..0000000 --- a/evolved5g/cli_helper.py +++ /dev/null @@ -1,70 +0,0 @@ -from .utils import cookiecutter_generate -import requests -import json -import json.decoder -from click import echo - - - -class CLI_helper: - - def __init__(self): - - self.url_curl = "https://epg-api.tid.es/api/executions" - self.url_token = "https://epg-api.tid.es/api/auth" - self.username_token = "usu_Evolved5g" - self.password_token = "evolved5g" - self.branch = "nginx-unprivileged" - self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": None } - - def generate(self, no_input, repo_name, package_name, template): - """Generate EVOLVED-5G compliant NetApp from template""" - # extra = {} - # if repo_name: - # extra['repoName'] = repo_name - # if package_name: - # extra['packageName'] = package_name - # if template: - # cookiecutter_generate(template,no_input=no_input,extra_context=extra) - # return - location = "gh:EVOLVED-5G/template" - cookiecutter_generate(location, no_input=no_input) #extra_context=extra) - - def generate_token(self): - - self.header = { "content-Type":"application/json", "accept": None, "Authorization": None } - data = '{ "username": "usu_Evolved5g", "password": "evolved5g" }' - resp = requests.post(self.url_token, headers=self.header, data=data) - return(resp.json()["access_token"]) - - def run_pipeline(self, mode, repo): - """Run the build pipeline for the EVOLVED-5G NetApp""" - self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": self.generate_token() } - # repo = input("Please write down your repo:\n") - data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + self.branch + '"} }' - resp = requests.post(self.url_curl, headers=self.header, data=data) - echo(resp.json()["id"]) - - def check_pipeline(self, id): - - """Check the status of the pipeline for the EVOLVED-5G NetApp""" - self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": self.generate_token() } - # pipelineid = input("Please write down the pipeline ID you want to check:\n") - resp = requests.get(f"{self.url_curl}/{id}", headers=self.header) - result = resp.json() - - if result["status"] == "QUEUED": - echo(result) - else: - console = (json.dumps(result["console_log"]).split('\\n')) - - for element in console: - if "] { (" in element: - echo(element) - elif "[Pipeline]" not in element: - echo(element) - elif "] stage" in element: - echo(element) - - - diff --git a/evolved5g/utils.py b/evolved5g/utils.py index ada1215..8b391d3 100644 --- a/evolved5g/utils.py +++ b/evolved5g/utils.py @@ -4,5 +4,5 @@ def cookiecutter_generate(location, no_input=False, **kwargs): """ Create project from the cookiecutter template in location given with the appropriate arguments. """ - # extra_context = kwargs['extra_context'] - cookiecutter(location, no_input=no_input) #, extra_context=extra_context) + extra_context = kwargs['extra_context'] + cookiecutter(location, no_input=no_input, extra_context=extra_context) diff --git a/requirements.txt b/requirements.txt index bbe17ea..d3a05df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,8 +5,6 @@ coverage==4.5.4 Click==8.0.1 pytest==6.2.4 cookiecutter==1.7.3 -invoke==1.6.0 -requests==2.26.0 setuptools~=58.1.0 six~=1.16.0 certifi~=2021.10.8 diff --git a/requirements_dev.txt b/requirements_dev.txt index eef7463..626b503 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -12,5 +12,3 @@ twine Click==8.0.1 pytest==6.2.4 cookiecutter==1.7.3 -invoke==1.6.0 -requests==2.26.0 diff --git a/setup.py b/setup.py index 522506c..b165b26 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ """The setup script.""" from setuptools import setup, find_packages -from pathlib import Path with open('README.rst') as readme_file: readme = readme_file.read() @@ -11,8 +10,7 @@ with open('HISTORY.rst') as history_file: history = history_file.read() -with Path('requirements.txt').open() as file: - INSTALL_REQUIERES = file.readlines() +requirements = ['Click>=7.0', 'Cookiecutter', ] test_requirements = ['pytest>=3', ] @@ -33,10 +31,9 @@ entry_points={ 'console_scripts': [ 'evolved5g=evolved5g.cli:cli', - 'cli_helper= evolved5g.cli:cli_helper', ], }, - install_requires=INSTALL_REQUIERES, + install_requires=requirements, license="Apache Software License 2.0", long_description=readme + '\n\n' + history, include_package_data=True,