-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.py
More file actions
69 lines (58 loc) · 2.23 KB
/
Config.py
File metadata and controls
69 lines (58 loc) · 2.23 KB
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
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
class Config:
_instance = None
# Singleton class instance across 1 run setup
# Loads grouped dynamic variable initializers
def __new__(cls):
if cls._instance is None:
cls._instance = super(Config, cls).__new__(cls)
cls._instance._load_env_vars()
cls._instance._load_engine()
cls._instance._get_github_linguist()
return cls._instance
# Subprivate loading methods for configuration
def _load_env_vars(self):
self.ENV = os.environ.get('APP_ENV', 'development').lower()
self.GIT_TOKEN = os.environ.get('GIT_TOKEN')
self.AZURE_CONN = os.environ.get('AZURE_CONN')
self.STORAGE_ACCT_CONN = os.environ.get('STORAGE_ACCT_CONN')
self.STORAGE = Path(os.environ.get('STORAGE', 'resources'))
self.LOG_LEVEL = self.__get_log_level()
self.LOG_FILE = os.environ.get('LOG_FILE', 'app.log')
self.SLEEP = os.environ.get('SLEEP', 1)
self.__correct_paths()
return self
def _load_engine(self):
self.__get_db_name()
self.ENGINE_PATH = self.STORAGE / self.db_name
self.ENGINE_URI = f'sqlite:///{self.ENGINE_PATH}'
return self
def _get_github_linguist(self):
self.LINGUIST_URL = 'https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml'
self.LINGUIST_CACHE = self.STORAGE / 'linguist_cache.yaml'
# Private Methods for configuration
def __get_db_name(self):
if self.ENV == 'production':
self.db_name = 'gitwrap.sqlite'
else:
self.db_name = 'gitwrap_dev.sqlite'
return self
def __get_log_level(self):
return os.environ.get(
'LOG_LEVEL', 'DEBUG'
if os.environ.get('APP_ENV') == 'development'
else 'INFO'
)
def __correct_paths(self):
if self.ENV == 'production':
pass
else:
repo_root = Path(__file__).resolve().parent
self.STORAGE = repo_root / self.STORAGE
return self
# EOF
if __name__ == '__main__':
print('This module is intended to be imported, not run directly.')