-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
executable file
·81 lines (66 loc) · 3.11 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
########################################################################################################################
# Load configuration from specified file #
########################################################################################################################
# (C) Manuel Bernal Llinares <[email protected]>#
# Distributed under the Apache License 2.0 #
########################################################################################################################
import os
import json
import sys
import optparse
import uuid
import time
_config = None
def prepareConfig():
global _config
# print("Preparing config")
configFile = "./config.backup_daemon.json"
# Parse command line options
# Create the command line parser with its options
cmdl_version = '2015.03.05'
cmdl_parser = optparse.OptionParser(version=cmdl_version, conflict_handler='resolve')
cmdl_parser.add_option('-h', '--help', action='help', help='print this help text and exit')
cmdl_parser.add_option('-v', '--version', action='version', help='print program version and exit')
cmdl_parser.add_option('-c', '--config', dest='configFileName', metavar='PATH_TO_CONFIG_FILE',
help='specify a config file to use for the session')
(cmdl_options, cmdl_args) = cmdl_parser.parse_args()
if cmdl_options.configFileName:
configFile = cmdl_options.configFileName
# print("Reading config file " + configFile)
# Load config file
with open(configFile) as cf:
_config = json.load(cf)
_config['config'] = {}
_config['config']['file'] = configFile
# Setup logging settings
currentTime = time.localtime()
if "logger" not in _config:
_config['logger'] = {}
if "folder" not in _config['logger']:
_config['logger']['folder'] = './'
if "namespace" not in _config['logger']:
_config['logger']['namespace'] = 'mainSession'
if "filePath" not in _config['logger']:
_config['logger']['filePath'] = _config['logger']['folder'] \
+ "/" + "backup-" + str(currentTime.tm_year) \
+ format(currentTime.tm_mon, "02") \
+ format(currentTime.tm_mday, "02") \
+ "_" \
+ format(currentTime.tm_hour, "02") \
+ "." \
+ format(currentTime.tm_min, "02") \
+ "." \
+ format(currentTime.tm_sec, "02") \
+ ".log"
if "ouputAndErrorFilePath" not in _config['logger']:
_config['logger']['ouputAndErrorFilePath'] = _config['logger']['filePath'] + ".out"
def getConfig():
global _config
if not _config:
prepareConfig()
return _config
def main():
print("This module is not designed to be run alone")
if __name__ == "__main__":
main()