From 90481470b590ce58fc8f1600d9468302142c0ed6 Mon Sep 17 00:00:00 2001 From: Venu Vardhan Reddy Tekula Date: Mon, 26 Apr 2021 20:49:31 +0530 Subject: [PATCH] [gareth] Add the initial structure of the tool This commit adds the initial structure of the tool. The tool is built using click. The arguments are source, token, and the operation which can be create or update. Usage: ``` $ gareth --help ``` Signed-off-by: Venu Vardhan Reddy Tekula --- gareth/gareth.py | 109 ++++++++++++++++++ poetry.lock | 14 ++- pyproject.toml | 9 +- .../add-the-initial-structure-of-the-tool.yml | 14 +++ 4 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 gareth/gareth.py create mode 100644 releases/unreleased/add-the-initial-structure-of-the-tool.yml diff --git a/gareth/gareth.py b/gareth/gareth.py new file mode 100644 index 0000000..4c73404 --- /dev/null +++ b/gareth/gareth.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2021 Bitergia +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Authors: +# Venu Vardhan Reddy Tekula +# + + +""" +Tool to manage the developer installation of GrimoireLab. +""" + +import os + +import click + +REPOS = [ + "chaoss/grimoirelab-sirmordred", + "chaoss/grimoirelab-toolkit", + "chaoss/grimoirelab-perceval", + "chaoss/grimoirelab-perceval-mozilla", + "chaoss/grimoirelab-perceval-opnfv", + "chaoss/grimoirelab-perceval-puppet", + "chaoss/grimoirelab-perceval-weblate", + "Bitergia/grimoirelab-perceval-finos", + "chaoss/grimoirelab-graal", + "chaoss/grimoirelab-elk", + "chaoss/grimoirelab-sortinghat", + "chaoss/grimoirelab-sigils", + "chaoss/grimoirelab-kidash", + "chaoss/grimoirelab-cereslib", + "chaoss/grimoirelab-kingarthur", + "chaoss/grimoirelab-manuscripts" +] + + +def source_prompt(): + """Prompt source to read the folder name""" + + prompt_msg = ">> Please provide the source folder name" + return prompt_msg + + +def validate_source(ctx, param, value): + """Check source option""" + + click.echo() + + if os.path.exists(value): + return value + + click.echo("Error: {} directory does not exist".format(value)) + + if not click.confirm("Do you want to create it?"): + msg = "The deveoper setup needs a source directory.\n" + raise click.ClickException(msg) + + try: + os.mkdir(value) + click.echo("The '{}' directory is created.\n".format(value)) + except OSError as ex: + msg = "Unable to create directory.\n" + msg += str(ex) + raise click.ClickException(msg) + + return value + + +@click.command() +@click.option('-t', '--token', required=False, + help="GitHub API Token.") +@click.option('-s', '--source', + prompt=source_prompt(), + default="sources", show_default=True, + callback=validate_source, + help="The source folder of the dev env.") +@click.option('--create', 'operation', flag_value='create', + default=True, + help="Create the developer setup.") +@click.option('--update', 'operation', flag_value='update', + help="Update the developer setup.") +def main(token, source, operation): + """ + Tool to manage the developer installation of GrimoireLab. + """ + + if operation == 'create': + create_dev_setup(token, source) + elif operation == 'update': + update_dev_setup(source) + + +if __name__ == '__main__': + main() diff --git a/poetry.lock b/poetry.lock index f6de599..62c2d3e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,8 +1,18 @@ -package = [] +[[package]] +name = "click" +version = "7.1.2" +description = "Composable command line interface toolkit" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [metadata] lock-version = "1.1" python-versions = "^3.6" -content-hash = "ae1f216c71b9b712a5c479d19bf075b718c35d9248fd89cb1eb7624528ec5ad1" +content-hash = "50c9c4a188d010bdfd899535c0ecf6ede243940e15280da3e1b701b9d0eca190" [metadata.files] +click = [ + {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"}, + {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"}, +] diff --git a/pyproject.toml b/pyproject.toml index 3a6a6b5..00f2a03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,11 +21,18 @@ include = [ "NEWS" ] +[tool.poetry.scripts] +gareth = 'gareth.gareth:main' + [tool.poetry.dependencies] python = "^3.6" +click = "^7.1.2" + [tool.poetry.dev-dependencies] [build-system] -requires = ["poetry-core>=1.0.0"] +requires = [ + "poetry-core>=1.0.0" +] build-backend = "poetry.core.masonry.api" diff --git a/releases/unreleased/add-the-initial-structure-of-the-tool.yml b/releases/unreleased/add-the-initial-structure-of-the-tool.yml new file mode 100644 index 0000000..58dee00 --- /dev/null +++ b/releases/unreleased/add-the-initial-structure-of-the-tool.yml @@ -0,0 +1,14 @@ +--- +title: Add the initial structure of the tool +category: added +author: Venu Vardhan Reddy Tekula +issue: null +notes: > + The initial structure of the tool is added. The tool + is built using click. The arguments are source, token, + and the operation which can be create or update. + + Usage: + ``` + $ gareth --help + ```