diff --git a/onionr/config.py b/onionr/config.py index 63086a2c..bc26c1aa 100755 --- a/onionr/config.py +++ b/onionr/config.py @@ -19,12 +19,9 @@ ''' import os, json, logger -from utils import identifyhome +import filepaths -# set data dir -dataDir = identifyhome.identify_home() - -_configfile = os.path.abspath(dataDir + 'config.json') +_configfile = filepaths.config_file _config = {} def get(key, default = None, save = False): diff --git a/onionr/filepaths/__init__.py b/onionr/filepaths/__init__.py index 59e13255..ec58b4a0 100644 --- a/onionr/filepaths/__init__.py +++ b/onionr/filepaths/__init__.py @@ -14,6 +14,7 @@ cached_storage = home + 'cachedstorage.dat' announce_cache = home + 'announcecache.dat' export_location = home + 'block-export/' upload_list = home + 'upload-list.json' +config_file = home + 'config.json' tor_hs_address_file = home + 'hs/hostname' diff --git a/onionr/tests/test_storagecounter.py b/onionr/tests/test_storagecounter.py index 81645056..dbd2e75c 100644 --- a/onionr/tests/test_storagecounter.py +++ b/onionr/tests/test_storagecounter.py @@ -2,6 +2,9 @@ import sys, os sys.path.append(".") import unittest, uuid +TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' +os.environ["ONIONR_HOME"] = TEST_DIR +import config import logger from utils import createdirs import onionrsetup as setup @@ -13,24 +16,20 @@ import storagecounter import onionrstorage def _test_setup(): - import config TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR createdirs.create_dirs() setup.setup_config() - config.reload() class TestStorageCounter(unittest.TestCase): def test_basic_amount(self): - import config _test_setup() - print(config.get('allocations.disk')) + self.assertIsNotNone(config.get('allocations.disk')) self.assertGreaterEqual(config.get('allocations.disk'), 1000000) def test_insert_too_much(self): - import config _test_setup() config.set('allocations.disk', 1000) self.assertRaises(onionrexceptions.DiskAllocationReached, onionrblocks.insert, "test") diff --git a/onionr/utils/identifyhome.py b/onionr/utils/identifyhome.py index b62fdf22..a78969ac 100644 --- a/onionr/utils/identifyhome.py +++ b/onionr/utils/identifyhome.py @@ -22,6 +22,7 @@ import os, platform def identify_home(): path = os.environ.get('ONIONR_HOME', None) + if path is None: system = platform.system() if system == 'Linux': @@ -36,4 +37,5 @@ def identify_home(): path = os.path.abspath(path) if not path.endswith('/'): path += '/' + return path \ No newline at end of file