use proper data folders
This commit is contained in:
parent
650d5077ed
commit
837286a970
@ -19,11 +19,9 @@
|
||||
'''
|
||||
|
||||
import os, json, logger
|
||||
|
||||
from utils import identifyhome
|
||||
# set data dir
|
||||
dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
|
||||
if not dataDir.endswith('/'):
|
||||
dataDir += '/'
|
||||
dataDir = identifyhome.identify_home()
|
||||
|
||||
_configfile = os.path.abspath(dataDir + 'config.json')
|
||||
_config = {}
|
||||
|
@ -30,6 +30,7 @@ import dbcreator, onionrstorage, serializeddata, subprocesspow
|
||||
from etc import onionrvalues, powchoice
|
||||
from onionrutils import localcommand, stringvalidators, bytesconverter, epoch
|
||||
from onionrutils import blockmetadata
|
||||
from utils import identifyhome
|
||||
import storagecounter
|
||||
|
||||
class Core:
|
||||
@ -38,9 +39,7 @@ class Core:
|
||||
Initialize Core Onionr library
|
||||
'''
|
||||
# set data dir
|
||||
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
|
||||
if not self.dataDir.endswith('/'):
|
||||
self.dataDir += '/'
|
||||
self.dataDir = identifyhome.identify_home()
|
||||
|
||||
try:
|
||||
self.usageFile = self.dataDir + 'disk-usage.txt'
|
||||
|
@ -29,7 +29,7 @@ def readline(message = ''):
|
||||
color = colors.fg.green + colors.bold
|
||||
output = colors.reset + str(color) + '... ' + colors.reset + str(message) + colors.reset
|
||||
|
||||
if not settings.get_settings() & USE_ANSI:
|
||||
if not settings.get_settings() & settings.USE_ANSI:
|
||||
output = colors.filter(output)
|
||||
|
||||
sys.stdout.write(output)
|
||||
|
@ -18,7 +18,9 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import os
|
||||
data_home = os.environ.get('DATA_DIR', os.environ.get('DATA_DIR', 'data'))
|
||||
from utils import identifyhome
|
||||
|
||||
data_home = os.environ.get('ONIONR_LOG_DIR', identifyhome.identify_home())
|
||||
# Use the bitwise operators to merge these settings
|
||||
USE_ANSI = 0b100
|
||||
if os.name == 'nt':
|
||||
|
@ -20,6 +20,7 @@
|
||||
import os, sys, base64, subprocess, signal
|
||||
import config, logger
|
||||
from . import getopenport
|
||||
from utils import identifyhome
|
||||
config.reload()
|
||||
class NetController:
|
||||
'''
|
||||
@ -28,9 +29,7 @@ class NetController:
|
||||
|
||||
def __init__(self, hsPort, apiServerIP='127.0.0.1'):
|
||||
# set data dir
|
||||
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
|
||||
if not self.dataDir.endswith('/'):
|
||||
self.dataDir += '/'
|
||||
self.dataDir = identifyhome.identify_home()
|
||||
|
||||
self.torConfigLocation = self.dataDir + 'torrc'
|
||||
self.readyState = False
|
||||
|
@ -43,11 +43,12 @@ from netcontroller import NetController
|
||||
from onionrblockapi import Block
|
||||
import onionrproofs, onionrexceptions, communicator, setupconfig
|
||||
import onionrcommands as commands # Many command definitions are here
|
||||
from utils import identifyhome
|
||||
|
||||
try:
|
||||
from urllib3.contrib.socks import SOCKSProxyManager
|
||||
except ImportError:
|
||||
raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)")
|
||||
raise ImportError("You need the PySocks module (for use with socks5 proxy to use Tor)")
|
||||
|
||||
class Onionr:
|
||||
def __init__(self):
|
||||
@ -67,7 +68,7 @@ class Onionr:
|
||||
pass
|
||||
|
||||
# set data dir
|
||||
self.dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
|
||||
self.dataDir = identifyhome.identify_home()
|
||||
if not self.dataDir.endswith('/'):
|
||||
self.dataDir += '/'
|
||||
|
||||
@ -97,7 +98,8 @@ class Onionr:
|
||||
if not os.path.exists(plugins.get_plugin_data_folder(name)):
|
||||
try:
|
||||
os.mkdir(plugins.get_plugin_data_folder(name))
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.warn('Error enabling plugin: ' + str(e))
|
||||
plugins.disable(name, onionr = self, stop_event = False)
|
||||
|
||||
self.communicatorInst = None
|
||||
@ -139,7 +141,8 @@ class Onionr:
|
||||
command = ''
|
||||
finally:
|
||||
self.execute(command)
|
||||
|
||||
|
||||
os.chdir(self.userRunDir)
|
||||
return
|
||||
|
||||
def exitSigterm(self, signum, frame):
|
||||
@ -175,7 +178,7 @@ class Onionr:
|
||||
|
||||
def get_hostname(self):
|
||||
try:
|
||||
with open('./' + self.dataDir + 'hs/hostname', 'r') as hostname:
|
||||
with open(self.dataDir + 'hs/hostname', 'r') as hostname:
|
||||
return hostname.read().strip()
|
||||
except FileNotFoundError:
|
||||
return "Not Generated"
|
||||
|
@ -19,11 +19,9 @@
|
||||
'''
|
||||
import os, re, importlib
|
||||
import onionrevents as events, config, logger
|
||||
|
||||
from utils import identifyhome
|
||||
# set data dir
|
||||
dataDir = os.environ.get('ONIONR_HOME', os.environ.get('DATA_DIR', 'data/'))
|
||||
if not dataDir.endswith('/'):
|
||||
dataDir += '/'
|
||||
dataDir = identifyhome.identify_home()
|
||||
|
||||
_pluginsfolder = dataDir + 'plugins/'
|
||||
_instances = dict()
|
||||
@ -75,15 +73,15 @@ def enable(name, onionr = None, start_event = True):
|
||||
return False
|
||||
else:
|
||||
enabled_plugins.append(name)
|
||||
config.set('plugins.enabled', enabled_plugins, True)
|
||||
|
||||
config.set('plugins.enabled', enabled_plugins, savefile=True)
|
||||
|
||||
if start_event is True:
|
||||
start(name)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
logger.error('Failed to enable plugin \"%s\", disabling plugin.' % name)
|
||||
logger.error('Failed to enable plugin \"%s\", disabling plugin.' % name, terminal=True)
|
||||
disable(name)
|
||||
|
||||
return False
|
||||
@ -245,7 +243,7 @@ def get_plugin_data_folder(name, absolute = True):
|
||||
Returns the location of a plugin's data folder
|
||||
'''
|
||||
|
||||
return get_plugins_folder(name, absolute) + dataDir
|
||||
return get_plugins_folder(name, absolute)
|
||||
|
||||
def check():
|
||||
'''
|
||||
|
39
onionr/utils/identifyhome.py
Normal file
39
onionr/utils/identifyhome.py
Normal file
@ -0,0 +1,39 @@
|
||||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
Identify a data directory for Onionr
|
||||
'''
|
||||
'''
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import os, platform
|
||||
|
||||
def identify_home():
|
||||
|
||||
path = os.environ.get('ONIONR_HOME', None)
|
||||
if path is None:
|
||||
system = platform.system()
|
||||
if system == 'Linux':
|
||||
path = os.path.expanduser('~') + '/.local/share/onionr/'
|
||||
elif system == 'Windows':
|
||||
path = os.path.expanduser('~') + '\\AppData\\Local\\onionr\\'
|
||||
elif system == 'Darwin':
|
||||
path = os.path.expanduser('~' + '/Library/Application Support/onionr/')
|
||||
else:
|
||||
path = 'data/'
|
||||
else:
|
||||
path = os.path.abspath(path)
|
||||
if not path.endswith('/'):
|
||||
path += '/'
|
||||
return path
|
Loading…
Reference in New Issue
Block a user