-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read http iface settings from $XDG_CONFIG_HOME/brotab/brotab.env
- Loading branch information
Showing
11 changed files
with
88 additions
and
179 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
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
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,36 @@ | ||
from os import environ | ||
from os.path import exists | ||
from os.path import expanduser | ||
|
||
from brotab.files import slurp_lines | ||
from brotab.mediator.const import DEFAULT_HTTP_IFACE | ||
from brotab.mediator.const import DEFAULT_MAX_HTTP_PORT | ||
from brotab.mediator.const import DEFAULT_MIN_HTTP_PORT | ||
from brotab.mediator.log import mediator_logger | ||
|
||
CONFIG = environ.get('XDG_CONFIG_HOME', expanduser('~/.config')) | ||
DEFAULT_FILENAME = '{0}/brotab/brotab.env'.format(CONFIG) | ||
|
||
|
||
def http_iface(): | ||
return environ.get('HTTP_IFACE', DEFAULT_HTTP_IFACE) | ||
|
||
|
||
def min_http_port(): | ||
return environ.get('MIN_HTTP_PORT', DEFAULT_MIN_HTTP_PORT) | ||
|
||
|
||
def max_http_port(): | ||
return environ.get('MAX_HTTP_PORT', DEFAULT_MAX_HTTP_PORT) | ||
|
||
|
||
def load_dotenv(filename=None): | ||
if filename is None: filename = DEFAULT_FILENAME | ||
mediator_logger.info('Loading .env file: %s', filename) | ||
if not exists(filename): | ||
mediator_logger.info('No .env file found: %s', filename) | ||
return | ||
for line in slurp_lines(filename): | ||
if not line or line.startswith('#'): continue | ||
key, value = line.split('=', 1) | ||
environ[key] = value |
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,22 @@ | ||
import os | ||
import tempfile | ||
|
||
|
||
def slurp(filename): | ||
with open(filename) as file_: | ||
return file_.read() | ||
|
||
|
||
def slurp_lines(filename): | ||
with open(filename) as file_: | ||
return [line.strip() for line in file_.readlines()] | ||
|
||
|
||
def spit(filename, contents): | ||
with open(filename, 'w', encoding='utf-8') as file_: | ||
file_.write(contents) | ||
|
||
|
||
def in_temp_dir(filename) -> str: | ||
temp_dir = tempfile.gettempdir() | ||
return os.path.join(temp_dir, filename) |
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.