mirror of
https://github.com/chocolate-doom/statcheck.git
synced 2025-02-15 00:20:45 +00:00
Split config read function out to separate file.
This commit is contained in:
parent
3243cc4968
commit
4cdadc9b94
2 changed files with 19 additions and 15 deletions
17
common.py
Normal file
17
common.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
from os.path import dirname, join, exists
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
def read_config(path):
|
||||||
|
if path == '':
|
||||||
|
return {}
|
||||||
|
|
||||||
|
# Config deeper in the hierarchy can override config files from
|
||||||
|
# higher up in the hierarchy:
|
||||||
|
result = read_config(dirname(path))
|
||||||
|
config_file = join(path, ".democonfig")
|
||||||
|
if exists(config_file):
|
||||||
|
with open(config_file) as f:
|
||||||
|
result.update(yaml.safe_load(f))
|
||||||
|
|
||||||
|
return result
|
17
testrunner
17
testrunner
|
@ -1,24 +1,11 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from os.path import dirname, basename, join, exists
|
from os.path import join
|
||||||
import shlex
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
|
||||||
|
|
||||||
def read_config(path):
|
from common import *
|
||||||
if path == '':
|
|
||||||
return {}
|
|
||||||
|
|
||||||
# Config deeper in the hierarchy can override config files from
|
|
||||||
# higher up in the hierarchy:
|
|
||||||
result = read_config(dirname(path))
|
|
||||||
config_file = join(path, ".democonfig")
|
|
||||||
if exists(config_file):
|
|
||||||
with open(config_file) as f:
|
|
||||||
result.update(yaml.safe_load(f))
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
source_port = os.getenv("SOURCE_PORT")
|
source_port = os.getenv("SOURCE_PORT")
|
||||||
assert source_port != "", "SOURCE_PORT environment variable not set."
|
assert source_port != "", "SOURCE_PORT environment variable not set."
|
||||||
|
|
Loading…
Reference in a new issue