From 9bd5efce1fbcd4d165041c6c811503b7ffec1e4f Mon Sep 17 00:00:00 2001 From: Arinerron Date: Thu, 28 Mar 2019 12:03:37 -0700 Subject: [PATCH] Make onionr use dirs from env --- install/onionr | 2 +- onionr/logger.py | 5 ++--- onionr/onionr.py | 13 +++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/install/onionr b/install/onionr index 81c071fa..31fd58cc 100755 --- a/install/onionr +++ b/install/onionr @@ -5,7 +5,7 @@ set -e [ "root" != "$USER" ] && exec sudo $0 "$@" export OUTPUT_DIR=${OUTPUT_DIR:=/usr/share/onionr} -export DATA_DIR=${DATA_DIR:=/etc/onionr} +export ONIONR_HOME=${ONIONR_HOME:=/etc/onionr} export LOG_DIR=${LOG_DIR:=/var/log/onionr} cd "$OUTPUT_DIR" diff --git a/onionr/logger.py b/onionr/logger.py index 18dfdf1d..34dc4d06 100755 --- a/onionr/logger.py +++ b/onionr/logger.py @@ -64,10 +64,9 @@ class colors: ''' Use the bitwise operators to merge these settings ''' +USE_ANSI = 0b100 if os.name == 'nt': USE_ANSI = 0b000 -else: - USE_ANSI = 0b100 OUTPUT_TO_CONSOLE = 0b010 OUTPUT_TO_FILE = 0b001 @@ -80,7 +79,7 @@ LEVEL_IMPORTANT = 6 _type = OUTPUT_TO_CONSOLE | USE_ANSI # the default settings for logging _level = LEVEL_DEBUG # the lowest level to log -_outputfile = './output.log' # the file to log to +_outputfile = 'data/onionr.log' # the file to log to def set_settings(type): ''' diff --git a/onionr/onionr.py b/onionr/onionr.py index 532fc4ee..532c87d5 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -62,12 +62,13 @@ class Onionr: except FileNotFoundError: pass - try: - self.dataDir = os.environ['ONIONR_HOME'] - if not self.dataDir.endswith('/'): - self.dataDir += '/' - except KeyError: - self.dataDir = 'data/' + # set data dir + self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/')) + if not self.dataDir.endswith('/'): + self.dataDir += '/' + + # set log file + logger.set_file(os.environ.get('LOG_DIR', 'data') + '/onionr.log') # Load global configuration data data_exists = Onionr.setupConfig(self.dataDir, self = self)