Completed
Push — master ( 466c76...070dce )
by Charles
01:44
created

print_commit_table()   A

Complexity

Conditions 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 13
ccs 10
cts 10
cp 1
crap 3
rs 9.4285
1
# -*- coding: utf-8 -*-
2 1
'''
3
    Main module
4
'''
5 1
import os
6
7 1
import click
0 ignored issues
show
Configuration introduced by
The import click could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
8 1
from tabulate import tabulate
0 ignored issues
show
Configuration introduced by
The import tabulate could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
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):
1 ignored issue
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The argument param seems to be unused.
Loading history...
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(
0 ignored issues
show
best-practice introduced by
Too many arguments (7/5)
Loading history...
45
    exists=True, resolve_path=True, file_okay=False, readable=True),
46
    default=os.getcwd())
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation.
default=os.getcwd())
^ |
Loading history...
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):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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