|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
1 |
|
''' |
|
3
|
|
|
Main module |
|
4
|
|
|
''' |
|
5
|
1 |
|
import os |
|
6
|
|
|
|
|
7
|
1 |
|
import click |
|
|
|
|
|
|
8
|
1 |
|
from tabulate import tabulate |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
1 |
|
import git_app_version.version |
|
11
|
1 |
|
from git_app_version.dumper import FileDumper |
|
12
|
1 |
|
from git_app_version.githandler import GitHandler |
|
13
|
|
|
|
|
14
|
1 |
|
__version__ = git_app_version.version.__version__ |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
1 |
|
def print_version(ctx, param, value): |
|
|
|
|
|
|
18
|
1 |
|
if not value or ctx.resilient_parsing: |
|
19
|
1 |
|
return |
|
20
|
1 |
|
click.echo('git-app-version ' + __version__) |
|
21
|
1 |
|
ctx.exit() |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
1 |
|
CONTEXT_SETTINGS = {'help_option_names': ['-h', '--help']} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
1 |
|
@click.command(context_settings=CONTEXT_SETTINGS) |
|
28
|
1 |
|
@click.option('--version', '-V', is_flag=True, callback=print_version, |
|
29
|
|
|
expose_value=False, is_eager=True) |
|
30
|
|
|
# @click.option('--verbose', '-v', count=True) |
|
31
|
1 |
|
@click.option('--quiet', '-q', is_flag=True, help='silent mode') |
|
32
|
1 |
|
@click.option('--output', '-o', default='version', |
|
33
|
|
|
help='output file path (without extension).' |
|
34
|
|
|
' Default is \'<repository-path>/version\'.') |
|
35
|
1 |
|
@click.option('--format', '-f', 'output_formats', |
|
36
|
|
|
type=click.Choice(['json', 'yml', 'xml', 'ini']), |
|
37
|
|
|
multiple=True, default=['json'], |
|
38
|
|
|
help='output file format and extension, Default is json.') |
|
39
|
1 |
|
@click.option('--namespace', '-n', default='', |
|
40
|
|
|
help='namespace like notation in version file, use dot separator' |
|
41
|
|
|
' to segment namespaces e.g.: \'foo.bar.git\'.' |
|
42
|
|
|
' Default is \'app_version\' for XML and INI' |
|
43
|
|
|
' and no namespace for JSON and YAML.') |
|
44
|
1 |
|
@click.argument('repository', type=click.Path( |
|
|
|
|
|
|
45
|
|
|
exists=True, resolve_path=True, file_okay=False, readable=True), |
|
46
|
|
|
default=os.getcwd()) |
|
|
|
|
|
|
47
|
1 |
|
@click.argument('commit', default='HEAD') |
|
48
|
1 |
|
@click.pass_context |
|
49
|
|
|
def dump(ctx, repository, commit, output, output_formats, namespace, quiet): |
|
50
|
|
|
''' |
|
51
|
|
|
Get Git commit informations and store them in a INI/XML/YAML/JSON file |
|
52
|
|
|
|
|
53
|
|
|
\b |
|
54
|
|
|
REPOSITORY git repository path, Default is the current directory. |
|
55
|
|
|
COMMIT git commit to check, Default is HEAD. |
|
56
|
|
|
''' |
|
57
|
|
|
|
|
58
|
1 |
|
try: |
|
59
|
1 |
|
vcs = GitHandler(repository) |
|
60
|
|
|
|
|
61
|
1 |
|
data = vcs.get_infos(commit=commit) |
|
62
|
|
|
|
|
63
|
1 |
|
if not quiet: |
|
64
|
1 |
|
print_commit_table(data) |
|
65
|
|
|
|
|
66
|
1 |
|
dumper = FileDumper() |
|
67
|
1 |
|
if not quiet and len(output_formats): |
|
68
|
1 |
|
click.echo("written to :") |
|
69
|
|
|
|
|
70
|
1 |
|
for output_format in output_formats: |
|
71
|
1 |
|
dest = dumper.dump( |
|
72
|
|
|
data=data, |
|
73
|
|
|
fileformat=output_format, |
|
74
|
|
|
target=output, |
|
75
|
|
|
cwd=repository, |
|
76
|
|
|
namespace=namespace) |
|
77
|
1 |
|
if not quiet: |
|
78
|
1 |
|
click.echo(dest) |
|
79
|
|
|
|
|
80
|
1 |
|
ctx.exit(0) |
|
81
|
|
|
|
|
82
|
1 |
|
except (RuntimeError, ValueError, TypeError) as exc: |
|
83
|
1 |
|
click.echo("Error Writing version config file : " + str(exc)) |
|
84
|
1 |
|
ctx.exit(1) |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
1 |
|
def print_commit_table(data): |
|
|
|
|
|
|
88
|
1 |
|
click.echo('Git commit :') |
|
89
|
1 |
|
keys = sorted(data.keys()) |
|
90
|
1 |
|
table = [] |
|
91
|
1 |
|
for key in keys: |
|
92
|
1 |
|
if isinstance(data[key], list): |
|
93
|
1 |
|
item = ' '.join(data[key]) |
|
94
|
|
|
else: |
|
95
|
1 |
|
item = data[key] |
|
96
|
|
|
|
|
97
|
1 |
|
table.append([key, item]) |
|
98
|
|
|
|
|
99
|
|
|
click.echo(tabulate(table, tablefmt='simple')) |
|
100
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.