forked from dramninjasUMD/marss.utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
71 lines (56 loc) · 1.96 KB
/
config.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
import os
import ConfigParser
config = None
def read_config(conf_file = None):
global config
if not conf_file:
# Set default conf file to be "./util.cfg"
curr_dir = os.path.dirname(os.path.realpath(__file__))
conf_file = "%s/util.cfg" % curr_dir
print("Reading config file %s" % conf_file)
if not os.path.exists(conf_file):
print("Unable to read '%s' configuration file." % conf_file)
exit(-1)
config = ConfigParser.SafeConfigParser()
config.read(conf_file)
# Store the config file path
config.add_section('util')
config.set('util', 'dir', os.path.dirname(conf_file))
return config
def check_config_param(config, section, param, is_path=False):
if config.has_option(section, param):
# If specified parameter is relative path then use config
# file path to get full path
if is_path and not os.path.isabs(config.get(section, param)):
full_path = "%s/%s" % (config.get('util', 'dir'),
config.get(section, param))
config.set(section, param, full_path)
if is_path and not os.path.exists(config.get(section, param)):
print("'%s' parameter in your config file is not valid." % param)
print("Error: Can't find file/directory: %s" % (
config.get(section, param)))
print("Please fix this error.")
exit(-1)
return True
print("Please specify '%s' in your configuration file." % param)
exit(-1)
def get_xoauth_filename():
if not config:
read_config()
check_config_param(config, 'email', 'xoauth', True)
return config.get('email', 'xoauth')
def get_marss_dir_path(filename):
if not config:
read_config()
check_config_param(config, 'DEFAULT', 'marss_dir', True)
return "%s/%s" % (config.get('DEFAULT', 'marss_dir'), filename)
def get_destination_email():
if not config:
read_config()
check_config_param(config, 'email', 'to')
dest_email = config.get('email', 'to')
if dest_email == "[email protected]":
print "Please change the default destination email before using this script"
exit()
else:
return dest_email