Initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Shared connection settings for the telnet drivers in this directory.
|
||||
|
||||
Resolved highest-priority-first from: the process environment, `../.env`,
|
||||
`../example.env`, then built-in defaults. Keeps addresses and credentials out
|
||||
of the scripts (and out of git) — see ../example.env.
|
||||
"""
|
||||
import os
|
||||
|
||||
KEYS = ('GPON_HOST', 'GPON_PORT', 'GPON_USER', 'GPON_PASS')
|
||||
_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
def _parse(path):
|
||||
vals = {}
|
||||
try:
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#') or '=' not in line:
|
||||
continue
|
||||
k, v = line.split('=', 1)
|
||||
vals[k.strip()] = v.strip().strip('"').strip("'")
|
||||
except OSError:
|
||||
pass
|
||||
return vals
|
||||
|
||||
|
||||
_cfg = _parse(os.path.join(_ROOT, 'example.env'))
|
||||
_cfg.update(_parse(os.path.join(_ROOT, '.env')))
|
||||
_cfg.update({k: v for k, v in os.environ.items() if k in KEYS})
|
||||
|
||||
HOST = _cfg.get('GPON_HOST') or '192.168.100.1'
|
||||
PORT = int(_cfg.get('GPON_PORT') or 23)
|
||||
USER = _cfg.get('GPON_USER') or 'root'
|
||||
PASS = _cfg.get('GPON_PASS') or 'admin'
|
||||
Reference in New Issue
Block a user