summary refs log tree commit diff stats
path: root/ganarchy/cli/debug.py
blob: 5bff0541001027b8c472de74d4edea5d954f50ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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.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))