fix env home regression and made identifyhome lint compliant

master
Kevin Froman 2019-12-20 15:50:56 -06:00
parent c469c5d871
commit f71f2f6246
1 changed files with 17 additions and 11 deletions

View File

@ -1,9 +1,10 @@
''' """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
Identify a data directory for Onionr Identify a data directory for Onionr
''' """
''' import os
import platform
"""
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -16,14 +17,18 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' """
import os, platform
def identify_home():
def identify_home() -> str:
"""Return path of home directory.
Take env into account with sane OS defaults
"""
path = os.environ.get('ONIONR_HOME', None) path = os.environ.get('ONIONR_HOME', None)
if not os.getcwd().endswith('src') and path is not None: if path is not None and not os.getcwd().endswith('src') \
and 'test' not in path:
path = 'src/' + path path = 'src/' + path
if path is None: if path is None:
@ -33,7 +38,8 @@ def identify_home():
elif system == 'Windows': elif system == 'Windows':
path = os.path.expanduser('~') + '\\AppData\\Local\\onionr\\' path = os.path.expanduser('~') + '\\AppData\\Local\\onionr\\'
elif system == 'Darwin': elif system == 'Darwin':
path = os.path.expanduser('~' + '/Library/Application Support/onionr/') path = os.path.expanduser('~' +
'/Library/Application Support/onionr/')
else: else:
path = 'data/' path = 'data/'
else: else:
@ -41,4 +47,4 @@ def identify_home():
if not path.endswith('/'): if not path.endswith('/'):
path += '/' path += '/'
return path return path