mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-14 01:41:25 -06:00
Merge pull request #126 from TheNetworkGuy/develop
Fixes bug in which config.py was not detected by the script
This commit is contained in:
commit
22982c3607
6
.github/workflows/publish-image.yml
vendored
6
.github/workflows/publish-image.yml
vendored
@ -5,10 +5,16 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test_quality:
|
test_quality:
|
||||||
uses: ./.github/workflows/quality.yml
|
uses: ./.github/workflows/quality.yml
|
||||||
|
test_code:
|
||||||
|
uses: ./.github/workflows/run_tests.yml
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
1
.github/workflows/run_tests.yml
vendored
1
.github/workflows/run_tests.yml
vendored
@ -4,6 +4,7 @@ name: Pytest code testing
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test_code:
|
test_code:
|
||||||
|
@ -3,7 +3,7 @@ Module for parsing configuration from the top level config.py file
|
|||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from importlib import util
|
from importlib import util
|
||||||
from os import environ
|
from os import environ, path
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
@ -104,18 +104,25 @@ def load_env_variable(config_environvar):
|
|||||||
|
|
||||||
def load_config_file(config_default, config_file="config.py"):
|
def load_config_file(config_default, config_file="config.py"):
|
||||||
"""Returns config from config.py file"""
|
"""Returns config from config.py file"""
|
||||||
# Check if config.py exists and load it
|
# Find the script path and config file next to it.
|
||||||
# If it does not exist, return the default config
|
script_dir = path.dirname(path.dirname(path.abspath(__file__)))
|
||||||
config_path = Path(config_file)
|
config_path = Path(path.join(script_dir, config_file))
|
||||||
if config_path.exists():
|
|
||||||
dconf = config_default.copy()
|
# If the script directory is not found, try the current working directory
|
||||||
# Dynamically import the config module
|
if not config_path.exists():
|
||||||
spec = util.spec_from_file_location("config", config_path)
|
config_path = Path(config_file)
|
||||||
config_module = util.module_from_spec(spec)
|
|
||||||
spec.loader.exec_module(config_module)
|
# If both checks fail then fallback to the default config
|
||||||
# Update DEFAULT_CONFIG with variables from the config module
|
if not config_path.exists():
|
||||||
for key in dconf:
|
return config_default
|
||||||
if hasattr(config_module, key):
|
|
||||||
dconf[key] = getattr(config_module, key)
|
dconf = config_default.copy()
|
||||||
return dconf
|
# Dynamically import the config module
|
||||||
return config_default
|
spec = util.spec_from_file_location("config", config_path)
|
||||||
|
config_module = util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(config_module)
|
||||||
|
# Update DEFAULT_CONFIG with variables from the config module
|
||||||
|
for key in dconf:
|
||||||
|
if hasattr(config_module, key):
|
||||||
|
dconf[key] = getattr(config_module, key)
|
||||||
|
return dconf
|
||||||
|
Loading…
Reference in New Issue
Block a user