-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.py
54 lines (41 loc) · 2.05 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
import configparser
import os
import sys
from Helpers.CredsContainer import CredsContainer
class Config:
LOGGER_ID = "API SAMPLE TESTS"
CONFIG_DIR = 'ConfigFiles'
COMMON_CONFIG_SECTION = 'common'
ENV_CONFIG_SECTION = 'env-qa'
LOG_FILE_NAME = "testlog.log"
config_file_name = None
twitter_auth_creds = None
twitter_api_base_url = None
logging_level = None
logging_path = None
logger = None
# Warning! The code to set up logging requires this config class. Do not do any logging in __init__
def __init__(self, config_file_name):
try_path = os.path.join(self.current_dir, config_file_name)
if os.path.exists(try_path):
self.config_file_name = try_path
else:
self.config_file_name = os.path.join(self.current_dir, self.CONFIG_DIR, config_file_name)
if not os.path.exists(self.config_file_name):
print("\n\nFatal Error: Config file: {} not found.".format(self.config_file_name))
sys.exit()
# Warning! The code to set up logging requires this config class. Do not do any logging in read_config
def read_config(self):
config = configparser.ConfigParser()
config.read(self.config_file_name)
self.twitter_auth_creds = CredsContainer(config[self.COMMON_CONFIG_SECTION]['consumer_key'],
config[self.COMMON_CONFIG_SECTION]['consumer_secret'],
config[self.COMMON_CONFIG_SECTION]['access_token'],
config[self.COMMON_CONFIG_SECTION]['access_token_secret'])
self.logging_level = config[self.COMMON_CONFIG_SECTION]['logging_level']
self.logging_path = config[self.COMMON_CONFIG_SECTION]['logging_path']
self.twitter_api_base_url = config[self.ENV_CONFIG_SECTION]['twitter_api_base_url']
print("Twitter api base url = {}".format(self.twitter_api_base_url))
@property
def current_dir(self):
return os.path.dirname(os.path.abspath(__file__))