WIP: change default data directories, subdirectories and config file
This commit is contained in:
parent
e8da744744
commit
bdddf58712
27 changed files with 263 additions and 121 deletions
|
@ -14,7 +14,7 @@ from util import helper
|
|||
class TrackerStorage(object):
|
||||
def __init__(self):
|
||||
self.log = logging.getLogger("TrackerStorage")
|
||||
self.file_path = "%s/trackers.json" % config.data_dir
|
||||
self.file_path = config.start_dir / 'trackers.json'
|
||||
self.load()
|
||||
self.time_discover = 0.0
|
||||
atexit.register(self.save)
|
||||
|
|
|
@ -9,7 +9,7 @@ from Config import config
|
|||
@pytest.mark.usefixtures("resetTempSettings")
|
||||
class TestAnnounceShare:
|
||||
def testAnnounceList(self, file_server):
|
||||
open("%s/trackers.json" % config.data_dir, "w").write("{}")
|
||||
(config.start_dir / 'trackers.json').open('w').write('{}')
|
||||
tracker_storage = AnnounceSharePlugin.tracker_storage
|
||||
tracker_storage.load()
|
||||
peer = Peer(file_server.ip, 1544, connection_server=file_server)
|
||||
|
|
|
@ -6,7 +6,7 @@ import time
|
|||
class ChartDb(Db):
|
||||
def __init__(self):
|
||||
self.version = 2
|
||||
super(ChartDb, self).__init__(self.getSchema(), "%s/chart.db" % config.data_dir)
|
||||
super(ChartDb, self).__init__(self.getSchema(), config.start_dir / 'chart.db')
|
||||
self.foreign_keys = True
|
||||
self.checkTables()
|
||||
self.sites = self.loadSites()
|
||||
|
|
|
@ -14,7 +14,7 @@ from util import helper
|
|||
class ContentFilterStorage(object):
|
||||
def __init__(self, site_manager):
|
||||
self.log = logging.getLogger("ContentFilterStorage")
|
||||
self.file_path = "%s/filters.json" % config.data_dir
|
||||
self.file_path = config.config_dir / 'filters.json'
|
||||
self.site_manager = site_manager
|
||||
self.file_content = self.load()
|
||||
|
||||
|
@ -36,12 +36,12 @@ class ContentFilterStorage(object):
|
|||
|
||||
def load(self):
|
||||
# Rename previously used mutes.json -> filters.json
|
||||
if os.path.isfile("%s/mutes.json" % config.data_dir):
|
||||
if (config.config_dir / 'mutes.json').is_file():
|
||||
self.log.info("Renaming mutes.json to filters.json...")
|
||||
os.rename("%s/mutes.json" % config.data_dir, self.file_path)
|
||||
if os.path.isfile(self.file_path):
|
||||
os.rename(config.config_dir / 'mutes.json', self.file_path)
|
||||
if self.file_path.is_file():
|
||||
try:
|
||||
return json.load(open(self.file_path))
|
||||
return json.load(self.file_path.open())
|
||||
except Exception as err:
|
||||
self.log.error("Error loading filters.json: %s" % err)
|
||||
return None
|
||||
|
|
|
@ -44,7 +44,7 @@ class UiRequestPlugin(object):
|
|||
if ".zip/" in path or ".tar.gz/" in path:
|
||||
file_obj = None
|
||||
path_parts = self.parsePath(path)
|
||||
file_path = "%s/%s/%s" % (config.data_dir, path_parts["address"], path_parts["inner_path"])
|
||||
file_path = config.data_dir / path_parts["address"] / path_parts["inner_path"]
|
||||
match = re.match(r"^(.*\.(?:tar.gz|zip))/(.*)", file_path)
|
||||
archive_path, path_within = match.groups()
|
||||
if archive_path not in archive_cache:
|
||||
|
|
|
@ -686,7 +686,7 @@ class UiWebsocketPlugin(object):
|
|||
if sys.platform == "linux":
|
||||
sys_db_paths += ['/usr/share/GeoIP/' + db_name]
|
||||
|
||||
data_dir_db_path = os.path.join(config.data_dir, db_name)
|
||||
data_dir_db_path = config.data_dir / db_name
|
||||
|
||||
db_paths = sys_db_paths + [data_dir_db_path]
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class BootstrapperDb(Db.Db):
|
|||
def __init__(self):
|
||||
self.version = 7
|
||||
self.hash_ids = {} # hash -> id cache
|
||||
super(BootstrapperDb, self).__init__({"db_name": "Bootstrapper"}, "%s/bootstrapper.db" % config.data_dir)
|
||||
super(BootstrapperDb, self).__init__({"db_name": "Bootstrapper"}, config.start_dir / 'bootstrapper.db')
|
||||
self.foreign_keys = True
|
||||
self.checkTables()
|
||||
self.updateHashCache()
|
||||
|
|
|
@ -16,7 +16,7 @@ def importPluginnedClasses():
|
|||
from User import UserManager
|
||||
|
||||
try:
|
||||
local_master_addresses = set(json.load(open("%s/users.json" % config.data_dir)).keys()) # Users in users.json
|
||||
local_master_addresses = set(json.load((config.private_dir / 'users.json').open()).keys()) # Users in users.json
|
||||
except Exception as err:
|
||||
local_master_addresses = set()
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ from User import UserManager
|
|||
class TestMultiuser:
|
||||
def testMemorySave(self, user):
|
||||
# It should not write users to disk
|
||||
users_before = open("%s/users.json" % config.data_dir).read()
|
||||
users_json = config.private_dir / 'users.json'
|
||||
users_before = users_json.open().read()
|
||||
user = UserManager.user_manager.create()
|
||||
user.save()
|
||||
assert open("%s/users.json" % config.data_dir).read() == users_before
|
||||
assert users_json.open().read() == users_before
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue