Passed
Push — master ( ffbe9f...5c3c8b )
by Konrad
01:19
created

db_sync_tool.__main__.get_arguments()   A

Complexity

Conditions 1

Size

Total Lines 37
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 37
rs 9.1359
c 0
b 0
f 0
cc 1
nop 1
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: utf-8 -*-
3
4
import argparse
5
from db_sync_tool import sync
6
from db_sync_tool.utility import helper
7
8
9
def main(args={}):
0 ignored issues
show
Bug Best Practice introduced by
The default value {} might cause unintended side-effects.

Objects as default values are only created once in Python and not on each invocation of the function. If the default object is modified, this modification is carried over to the next invocation of the method.

# Bad:
# If array_param is modified inside the function, the next invocation will
# receive the modified object.
def some_function(array_param=[]):
    # ...

# Better: Create an array on each invocation
def some_function(array_param=None):
    array_param = array_param or []
    # ...
Loading history...
10
    """
11
    Main entry point for the command line. Parse the arguments and call to the main process.
12
    :param args:
13
    :return:
14
    """
15
    args = get_arguments(args)
16
    sync.Sync(
17
        config_file=args.config_file,
18
        verbose=args.verbose,
19
        mute=args.mute,
20
        import_file=args.import_file,
21
        dump_name=args.dump_name,
22
        keep_dump=args.keep_dump,
23
        host_file=args.host_file
24
    )
25
26
27
def get_arguments(args):
28
    """
29
    Parses and returns script arguments
30
    :param args:
31
    :return:
32
    """
33
    parser = argparse.ArgumentParser()
34
    parser.add_argument('-f', '--config-file',
35
                        help='Path to configuration file',
36
                        required=False,
37
                        type=str)
38
    parser.add_argument('-v', '--verbose',
39
                        help='Enable extended console output',
40
                        required=False,
41
                        action='store_true')
42
    parser.add_argument('-m', '--mute',
43
                        help='Mute console output',
44
                        required=False,
45
                        action='store_true')
46
    parser.add_argument('-i', '--import-file',
47
                        help='Import database from a specific file dump',
48
                        required=False,
49
                        type=str)
50
    parser.add_argument('-dn', '--dump-name',
51
                        help='Set a specific dump file name (default is "_[dbname]_[date]")',
52
                        required=False,
53
                        type=str)
54
    parser.add_argument('-kd', '--keep-dump',
55
                        help='Skipping target import of the database dump and saving the available dump file in the given directory',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (133/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
56
                        required=False,
57
                        type=str)
58
    parser.add_argument('-o', '--host-file',
59
                        help='Using an additional hosts file for merging hosts information with the configuration file',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
60
                        required=False,
61
                        type=str)
62
63
    return parser.parse_args(helper.dict_to_args(args))
64
65
66
if __name__ == "__main__":
67
    main()
68