diff options
Diffstat (limited to 'ganarchy/cli')
-rw-r--r-- | ganarchy/cli/__init__.py | 27 | ||||
-rw-r--r-- | ganarchy/cli/db.py | 71 | ||||
-rw-r--r-- | ganarchy/cli/debug.py | 112 | ||||
-rw-r--r-- | ganarchy/cli/merge_configs.py | 25 | ||||
-rw-r--r-- | ganarchy/cli/run_targets.py | 231 |
5 files changed, 0 insertions, 466 deletions
diff --git a/ganarchy/cli/__init__.py b/ganarchy/cli/__init__.py deleted file mode 100644 index 727c48d..0000000 --- a/ganarchy/cli/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# This file is part of GAnarchy - decentralized project hub -# Copyright (C) 2019 Soni L. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -"""The GAnarchy CLI. - -This module just defines the main command group. Submodules define -actual commands. -""" - -import click - -@click.group() -def main(): - pass diff --git a/ganarchy/cli/db.py b/ganarchy/cli/db.py deleted file mode 100644 index e754c34..0000000 --- a/ganarchy/cli/db.py +++ /dev/null @@ -1,71 +0,0 @@ -# This file is part of GAnarchy - decentralized project hub -# Copyright (C) 2020 Soni L. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -"""Database-related CLI commands. - -""" - -import os - -import click - -import ganarchy.cli -import ganarchy.data -import ganarchy.db -import ganarchy.dirs - -@ganarchy.cli.main.command() -def initdb(): - """Initializes the ganarchy database.""" - # TODO: makedirs in a separate command? - os.makedirs(ganarchy.dirs.DATA_HOME, exist_ok=True) - db = ganarchy.db.connect_database(ganarchy.data.ConfigManager.new_default()) - db.initialize() - db.close() - -@ganarchy.cli.main.group() -def migrations(): - """Modifies the DB to work with a newer/older version. - - WARNING: THIS COMMAND CAN BE EXTREMELY DESTRUCTIVE!""" - -@migrations.command() -@click.argument('migration') -def apply(migration): - """Applies the migration with the given name.""" - db = ganarchy.db.connect_database(ganarchy.data.ConfigManager.new_default()) - click.echo(ganarchy.db.MIGRATIONS[migration][0]) - db.apply_migration(migration) - db.close() - -@click.argument('migration') -@migrations.command() -def revert(migration): - """Reverts the migration with the given name.""" - db = ganarchy.db.connect_database(ganarchy.data.ConfigManager.new_default()) - click.echo(ganarchy.db.MIGRATIONS[migration][1]) - db.revert_migration(migration) - db.close() - -@click.argument('migration', required=False) -@migrations.command() -def info(migration): - """Shows information about the migration with the given name.""" - if not migration: - # TODO could be improved - click.echo(ganarchy.db.MIGRATIONS.keys()) - else: - click.echo(ganarchy.db.MIGRATIONS[migration][2]) diff --git a/ganarchy/cli/debug.py b/ganarchy/cli/debug.py deleted file mode 100644 index 95ad045..0000000 --- a/ganarchy/cli/debug.py +++ /dev/null @@ -1,112 +0,0 @@ -# This file is part of GAnarchy - decentralized project hub -# Copyright (C) 2019 Soni L. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -import click -import qtoml - -import ganarchy -import ganarchy.cli -import ganarchy.data - -@ganarchy.cli.main.group() -def debug(): - pass - -@debug.command() -def paths(): - click.echo('Config home: {}'.format(ganarchy.config_home)) - click.echo('Additional config search path: {}'.format(ganarchy.config_dirs)) - click.echo('Cache home: {}'.format(ganarchy.cache_home)) - click.echo('Data home: {}'.format(ganarchy.data_home)) - -def print_data_source(data_source): - if ganarchy.data.DataProperty.INSTANCE_TITLE in data_source.get_supported_properties(): - try: - title = data_source.get_property_value(ganarchy.data.DataProperty.INSTANCE_TITLE) - except LookupError: - title = None - click.echo("\tTitle: {}".format(title)) - - if ganarchy.data.DataProperty.INSTANCE_BASE_URL in data_source.get_supported_properties(): - try: - base_url = data_source.get_property_value(ganarchy.data.DataProperty.INSTANCE_BASE_URL) - except LookupError: - base_url = None - click.echo("\tBase URL: {}".format(base_url)) - - if ganarchy.data.DataProperty.REPO_LIST_SOURCES in data_source.get_supported_properties(): - click.echo("\tRepo list sources:") - try: - iterator = data_source.get_property_values(ganarchy.data.DataProperty.REPO_LIST_SOURCES) - except LookupError: - click.echo("\t\tNone") - else: - for i, rls in enumerate(iterator, 1): - click.echo("\t\t{}.".format(i)) - click.echo("\t\t\tURI: {}".format(rls.uri)) - click.echo("\t\t\tOptions: {}".format(rls.options)) - click.echo("\t\t\tActive: {}".format(rls.active)) - - if ganarchy.data.DataProperty.VCS_REPOS in data_source.get_supported_properties(): - click.echo("\tRepos:") - try: - iterator = data_source.get_property_values(ganarchy.data.DataProperty.VCS_REPOS) - except LookupError: - click.echo("\t\tNone") - else: - for i, pctp in enumerate(iterator, 1): - click.echo("\t\t{}.".format(i)) - click.echo("\t\t\tProject: {}".format(pctp.project_commit)) - click.echo("\t\t\tURI: {}".format(pctp.uri)) - click.echo("\t\t\tBranch: {}".format(pctp.branch)) - click.echo("\t\t\tOptions: {}".format(pctp.options)) - click.echo("\t\t\tActive: {}".format(pctp.active)) - -@debug.command() -def configs(): - confs = ganarchy.data.ConfigManager.new_default() - click.echo("Configs (raw): {}".format(confs.sources)) - click.echo("Breaking down the configs.") - update_excs = confs.update() - for conf, exc in zip(reversed(confs.sources), reversed(update_excs)): - click.echo("Config: {}".format(conf)) - if exc is not None: - click.echo("\tError(s): {}".format(exc)) - if conf.exists(): - print_data_source(conf) - click.echo("ConfigManager (raw):") - print_data_source(confs) - click.echo("ConfigManager (effective):") - print_data_source(ganarchy.data.EffectiveSource(confs)) - -@debug.command() -def repo_lists(): - confs = ganarchy.data.ConfigManager.new_default() - repo_lists = ganarchy.data.RepoListManager(confs) - update_excs = repo_lists.update() - click.echo("Repo lists (raw): {}".format(repo_lists.sources)) - click.echo("Breaking down the repo lists.") - for repo_list, exc in zip(reversed(repo_lists.sources), reversed(update_excs)): - click.echo("Repo list: {}".format(repo_list)) - if exc is not None: - click.echo("\tError(s): {}".format(exc)) - if repo_list.exists(): - print_data_source(repo_list) - click.echo("RepoListManager (raw):") - print_data_source(repo_lists) - click.echo("RepoListManager (effective):") - print_data_source(ganarchy.data.EffectiveSource(repo_lists)) - diff --git a/ganarchy/cli/merge_configs.py b/ganarchy/cli/merge_configs.py deleted file mode 100644 index d8e12e6..0000000 --- a/ganarchy/cli/merge_configs.py +++ /dev/null @@ -1,25 +0,0 @@ -import pathlib - -import click - -import ganarchy -import ganarchy.cli -import ganarchy.data - -@ganarchy.cli.main.command() -@click.option('--skip-errors/--no-skip-errors', default=False) -@click.argument('files', type=click.Path(exists=True, dir_okay=False, resolve_path=True), nargs=-1) -def merge_configs(skip_errors, files): - """Merges config files.""" - configs = [ganarchy.data.LocalDataSource(filename) for filename in files] - rlm = ganarchy.data.RepoListManager(ganarchy.data.ObjectDataSource({})) - rlm.sources += configs - res = [] - for src in rlm.sources: - res.append(src.update()) - effective = ganarchy.data.EffectiveSource(rlm) - if any(x is None for x in res): - click.echo("# This is DEPRECATED and will be REMOVED at some point!") - for pctp in effective.get_property_values(ganarchy.data.DataProperty.VCS_REPOS): - if pctp.active: - click.echo(f"""projects."{ganarchy.tomlescape(pctp.project_commit)}"."{ganarchy.tomlescape(pctp.uri)}"."{ganarchy.tomlescape(pctp.branch)}" = {{ active=true }}""") diff --git a/ganarchy/cli/run_targets.py b/ganarchy/cli/run_targets.py deleted file mode 100644 index 24497b9..0000000 --- a/ganarchy/cli/run_targets.py +++ /dev/null @@ -1,231 +0,0 @@ -# This file is part of GAnarchy - decentralized project hub -# Copyright (C) 2020 Soni L. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -"""This module contains the CLI Run Targets. -""" - -import os -import shutil - -import click - -from ganarchy import cli -from ganarchy import core -from ganarchy import data -from ganarchy import db -from ganarchy import dirs -from ganarchy.templating import environment - -@cli.main.command() -@click.option('--keep-stale-projects/--no-keep-stale-projects', default=True) -@click.argument('out', required=True, type=click.Path(file_okay=False, resolve_path=True)) -def run_once(out, keep_stale_projects): - """Runs GAnarchy once. - - Processes any necessary updates and updates the output directory to match. - """ -# """Runs ganarchy standalone. -# -# This will run ganarchy so it regularly updates the output directory given -# by OUT. Additionally, it'll also search for the following hooks in its -# config dirs: -# -# - post_object_update_hook - executed after an object is updated. -# -# - post_update_cycle_hook - executed after all objects in an update -# cycle are updated. -# """ - # create config objects - conf = data.ConfigManager.new_default() - effective_conf = data.EffectiveSource(conf) - repos = data.RepoListManager(effective_conf) - effective_repos = data.EffectiveSource(repos) - - # create dir if it doesn't exist - os.makedirs(out, exist_ok=True) - - # load template environment - env = environment.get_env() - - # make sure the cache dir exists - os.makedirs(dirs.CACHE_HOME, exist_ok=True) - - # make sure it is a git repo - core.GIT.create() - - if True: - # reload config and repo data - effective_repos.update() - database = db.connect_database(effective_conf) - database.load_repos(effective_repos) - - instance = core.GAnarchy(database, effective_conf) - - if not instance.base_url: - click.echo("No base URL specified", err=True) - return - - instance.load_projects() - - # update and render projects - if not keep_stale_projects: - shutil.rmtree(out + "/project") - - os.makedirs(out + "/project", exist_ok=True) - - template_project = env.get_template('project.html') - for p in instance.projects: - p.load_repos() - - generate_html = [] - results = p.update() - #if not p.exists: - # ... - for (repo, count) in results: - if count is not None: - generate_html.append( - (repo.url, repo.message, count, repo.branch) - ) - else: - click.echo(repo.errormsg, err=True) - html_entries = [] - for (url, msg, count, branch) in generate_html: - history = database.list_repobranch_activity(p.commit, url, branch) - # TODO process history into SVG - # TODO move this into a separate system - # (e.g. ``if project.startswith("svg-"):``) - html_entries.append((url, msg, "", branch)) - - os.makedirs(out + "/project/" + p.commit, exist_ok=True) - - with open(out + "/project/" + p.commit + "/index.html", "w") as f: - template_project.stream( - project_title = p.title, - project_desc = p.description, - project_body = p.commit_body, - project_commit = p.commit, - repos = html_entries, - base_url = instance.base_url, - # I don't think this thing supports deprecating the above? - project = p, - ganarchy = instance - ).dump(f) - - # render the config - template = env.get_template('index.toml') - with open(out + "/index.toml", "w") as f: - template.stream(database=database).dump(f) - - # render the index - # but reload projects first to pick up sorting order - # (new projects don't get sorted until their repos get fetched for the - # first time, because that's where the metadata is stored) - # FIXME .sort_projects()? - instance.load_projects() - template = env.get_template('index.html') - with open(out + "/index.html", "w") as f: - template.stream(ganarchy=instance).dump(f) - - -@cli.main.command() -@click.option('--dry-run/--no-dry-run', '--no-update/--update', default=False) -@click.argument('project', required=False) -def cron_target(dry_run, project): - """Runs ganarchy as a cron target. - - "Deprecated". Useful if you want full control over how GAnarchy - generates the pages. - """ - # create config objects - conf = data.ConfigManager.new_default() - effective_conf = data.EffectiveSource(conf) - repos = data.RepoListManager(effective_conf) - effective_repos = data.EffectiveSource(repos) - - # load config and repo data - effective_repos.update() - database = db.connect_database(effective_conf) - database.load_repos(effective_repos) - - # load template environment - env = environment.get_env() - - # handle config and project list - if project == "config": - # render the config - template = env.get_template('index.toml') - click.echo(template.render(database=database), nl=False) - return - if project == "project-list": - # could be done with a template but eh w/e, this is probably better - for project in database.list_projects(): - click.echo(project) - return - - # make sure the cache dir exists - os.makedirs(dirs.CACHE_HOME, exist_ok=True) - - # make sure it is a git repo - core.GIT.create() - - instance = core.GAnarchy(database, effective_conf) - - if not instance.base_url or not project: - click.echo("No base URL or project commit specified", err=True) - return - - if project == "index": - instance.load_projects() - # render the index - template = env.get_template('index.html') - click.echo(template.render(ganarchy=instance), nl=False) - return - - p = core.Project(database, project) - p.load_repos() - - generate_html = [] - results = p.update(dry_run=dry_run) - #if not p.exists: - # ... - for (repo, count) in results: - if count is not None: - generate_html.append((repo.url, repo.message, count, repo.branch)) - else: - click.echo(repo.errormsg, err=True) - html_entries = [] - for (url, msg, count, branch) in generate_html: - history = database.list_repobranch_activity(project, url, branch) - # TODO process history into SVG - # TODO move this into a separate system - # (e.g. ``if project.startswith("svg-"):``) - html_entries.append((url, msg, "", branch)) - - template = env.get_template('project.html') - click.echo( - template.render( - project_title = p.title, - project_desc = p.description, - project_body = p.commit_body, - project_commit = p.commit, - repos = html_entries, - base_url = instance.base_url, - # I don't think this thing supports deprecating the above? - project = p, - ganarchy = instance - ), - nl=False - ) |