1
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
2
|
|
|
# -*- coding: future_fstrings -*- |
3
|
|
|
|
4
|
|
|
import argparse, sys, os |
|
|
|
|
5
|
|
|
from collections import defaultdict |
|
|
|
|
6
|
|
|
# Workaround for ModuleNotFoundError |
7
|
|
|
sys.path.append(os.getcwd()) |
8
|
|
|
from file_sync_tool import sync |
|
|
|
|
9
|
|
|
from file_sync_tool.utility import helper |
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
def main(args={}): |
|
|
|
|
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.') |
|
|
|
|
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', |
|
|
|
|
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
|
|
|
|