-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: configuration loading and logging function
- Loading branch information
Annika
committed
May 22, 2020
1 parent
3ad30d7
commit c45a028
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
config.py | ||
config.json | ||
__pycache__/** | ||
__pycache__ | ||
backup/* | ||
logs/* | ||
data/* | ||
backup/**Ã | ||
backup/**� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"username": "", | ||
"password": "", | ||
"loglevel": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/python3 | ||
|
||
import json | ||
|
||
################## config.py ################### | ||
## loads configuration data from config.json ## | ||
## by Annika ## | ||
################################################ | ||
|
||
CONFIG_PATH = 'config.json' | ||
CONFIG_VARS = ['username', 'password', 'loglevel'] | ||
|
||
def loadConfig(): | ||
configData = json.load(open(CONFIG_PATH, 'r')) | ||
returnValue = [] | ||
# make sure we're not missing anything | ||
for configItem in CONFIG_VARS: | ||
if configItem not in configData: | ||
# We can't use core.log because config.loglevel doesn't exist yet | ||
print("E: {item} not found in config.json".format(item = configItem)) | ||
else: | ||
returnValue.append(configData[configItem]) | ||
return returnValue | ||
|
||
username, password, loglevel = loadConfig() | ||
# the order of these needs to be the same as in CONFIG_VARS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/python3 | ||
|
||
import config | ||
|
||
################## core.py ##################### | ||
## core functionality of Expecto Botronum ## | ||
## by Annika ## | ||
################################################ | ||
|
||
###################### | ||
## Helper Functions ## | ||
###################### | ||
|
||
def log(message): | ||
if config.loglevel > 2 or message[:2] == 'E:': | ||
# Errors are always logged and everything in debug mode is logged. | ||
print(message) | ||
elif message[:2] == 'W:' and config.loglevel >= 1: | ||
print(message) | ||
elif message[:2] == 'I:' and config.loglevel >= 2: | ||
print(message) |