file_sync_tool.__main__.main()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: future_fstrings -*-
3
4
import argparse, sys, os
0 ignored issues
show
introduced by
Multiple imports on one line (argparse, sys, os)
Loading history...
5
from collections import defaultdict
0 ignored issues
show
Unused Code introduced by
Unused defaultdict imported from collections
Loading history...
6
# Workaround for ModuleNotFoundError
7
sys.path.append(os.getcwd())
8
from file_sync_tool import sync
0 ignored issues
show
introduced by
Import "from file_sync_tool import sync" should be placed at the top of the module
Loading history...
9
from file_sync_tool.utility import helper
0 ignored issues
show
introduced by
Import "from file_sync_tool.utility import helper" should be placed at the top of the module
Loading history...
10
11
12
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...
13
    """
14
    Main entry point for the command line. Parse the arguments and call to the main process.
15
    :param args:
16
    :return:
17
    """
18
    args = get_arguments(args)
19
    sync.Sync(
20
        config_file=args.config_file,
21
        verbose=args.verbose,
22
        mute=args.mute,
23
        host_file=args.host_file,
24
        args=args
25
    )
26
27
28
def get_arguments(args):
29
    """
30
    Parses and returns script arguments
31
    :param args:
32
    :return:
33
    """
34
    parser = argparse.ArgumentParser(prog='file_sync_tool', description='A tool for automatic file synchronization from and to host systems.')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (142/100).

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

Loading history...
35
    parser.add_argument('-f', '--config-file',
36
                        help='Path to configuration file',
37
                        required=False,
38
                        type=str)
39
    parser.add_argument('-v', '--verbose',
40
                        help='Enable extended console output',
41
                        required=False,
42
                        action='store_true')
43
    parser.add_argument('-m', '--mute',
44
                        help='Mute console output',
45
                        required=False,
46
                        action='store_true')
47
    parser.add_argument('-o', '--host-file',
48
                        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...
49
                        required=False,
50
                        type=str)
51
    parser.add_argument('-th', '--target-host',
52
                        help='SSH host to target system',
53
                        required=False,
54
                        type=str)
55
    parser.add_argument('-tu', '--target-user',
56
                        help='SSH user for target system',
57
                        required=False,
58
                        type=str)
59
    parser.add_argument('-tpw', '--target-password',
60
                        help='SSH password for target system',
61
                        required=False,
62
                        type=str)
63
    parser.add_argument('-tk', '--target-key',
64
                        help='File path to SSH key for target system',
65
                        required=False,
66
                        type=str)
67
    parser.add_argument('-tpo', '--target-port',
68
                        help='SSH port for target system',
69
                        required=False,
70
                        type=int)
71
    parser.add_argument('-oh', '--origin-host',
72
                        help='SSH host to origin system',
73
                        required=False,
74
                        type=str)
75
    parser.add_argument('-ou', '--origin-user',
76
                        help='SSH user for origin system',
77
                        required=False,
78
                        type=str)
79
    parser.add_argument('-opw', '--origin-password',
80
                        help='SSH password for origin system',
81
                        required=False,
82
                        type=str)
83
    parser.add_argument('-ok', '--origin-key',
84
                        help='File path to SSH key for origin system',
85
                        required=False,
86
                        type=str)
87
    parser.add_argument('-opo', '--origin-port',
88
                        help='SSH port for origin system',
89
                        required=False,
90
                        type=int)
91
    parser.add_argument('-fo', '--files-origin',
92
                        help='File path for origin source of file sync',
93
                        required=False,
94
                        type=str)
95
    parser.add_argument('-ft', '--files-target',
96
                        help='File path for target destination of file sync',
97
                        required=False,
98
                        type=str)
99
    parser.add_argument('-fe', '--files-exclude',
100
                        help='Excludes for file sync',
101
                        required=False,
102
                        type=str)
103
    parser.add_argument('-fop', '--files-option',
104
                        help='Additional rsync options',
105
                        required=False,
106
                        type=str)
107
108
    return parser.parse_args(helper.dict_to_args(args))
109
110
111
if __name__ == "__main__":
112
    main()
113