diff --git a/onionr/config.py b/onionr/config.py index 960286f6..fe093b57 100755 --- a/onionr/config.py +++ b/onionr/config.py @@ -20,13 +20,11 @@ import os, json, logger -try: - dataDir = os.environ['ONIONR_HOME'] - if not dataDir.endswith('/'): - dataDir += '/' -except KeyError: - dataDir = 'data/' - +# set data dir +dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/')) +if not dataDir.endswith('/'): + dataDir += '/' + _configfile = os.path.abspath(dataDir + 'config.json') _config = {} diff --git a/onionr/core.py b/onionr/core.py index f178fefd..1cbce026 100755 --- a/onionr/core.py +++ b/onionr/core.py @@ -39,12 +39,10 @@ class Core: Initialize Core Onionr library ''' - 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 += '/' try: self.onionrInst = None diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index 2898256c..4f6281c9 100755 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -46,12 +46,10 @@ class NetController: ''' def __init__(self, hsPort, apiServerIP='127.0.0.1'): - 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 += '/' self.torConfigLocation = self.dataDir + 'torrc' self.readyState = False @@ -165,7 +163,7 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) except KeyboardInterrupt: logger.fatal('Got keyboard interrupt.', timestamp = False, level = logger.LEVEL_IMPORTANT) return False - + logger.debug('Finished starting Tor.', timestamp=True) self.readyState = True diff --git a/onionr/onionrplugins.py b/onionr/onionrplugins.py index a7560957..10e5e186 100755 --- a/onionr/onionrplugins.py +++ b/onionr/onionrplugins.py @@ -21,12 +21,10 @@ import os, re, importlib, config, logger import onionrevents as events -try: - dataDir = os.environ['ONIONR_HOME'] - if not dataDir.endswith('/'): - dataDir += '/' -except KeyError: - dataDir = 'data/' +# set data dir +dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/')) +if not dataDir.endswith('/'): + dataDir += '/' _pluginsfolder = dataDir + 'plugins/' _instances = dict()