|
1
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
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={}): |
|
|
|
|
|
|
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', |
|
|
|
|
|
|
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', |
|
|
|
|
|
|
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
|
|
|
|