mirror of
https://github.com/samschott/maestral.git
synced 2024-10-07 02:47:56 +03:00
use maestral modules for pre-update scripts
This commit is contained in:
parent
7dbfa3ed51
commit
10231136c2
74
setup.py
74
setup.py
@ -1,82 +1,10 @@
|
||||
import sys
|
||||
import os
|
||||
import os.path as osp
|
||||
import platform
|
||||
import tempfile
|
||||
import importlib.util
|
||||
from setuptools import setup, find_packages
|
||||
from maestral import __version__, __author__, __url__
|
||||
|
||||
|
||||
# check for running daemons before updating to prevent
|
||||
# incompatible versions of CLI / GUI and daemon
|
||||
|
||||
def get_home_dir():
|
||||
try:
|
||||
path = osp.expanduser('~')
|
||||
except Exception:
|
||||
path = ''
|
||||
|
||||
if osp.isdir(path):
|
||||
return path
|
||||
else:
|
||||
for env_var in ('HOME', 'USERPROFILE', 'TMP'):
|
||||
path = os.environ.get(env_var, '')
|
||||
if osp.isdir(path):
|
||||
return path
|
||||
else:
|
||||
path = ''
|
||||
|
||||
if not path:
|
||||
raise RuntimeError('Please set the environment variable HOME to '
|
||||
'your user/home directory.')
|
||||
|
||||
|
||||
_home_dir = get_home_dir()
|
||||
|
||||
|
||||
def _to_full_path(path, subfolder, filename, create):
|
||||
|
||||
if subfolder:
|
||||
path = osp.join(path, subfolder)
|
||||
|
||||
if create:
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
||||
if filename:
|
||||
path = osp.join(path, filename)
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def get_conf_path(subfolder=None, filename=None, create=True):
|
||||
if platform.system() == 'Darwin':
|
||||
conf_path = osp.join(get_home_dir(), 'Library', 'Application Support')
|
||||
else:
|
||||
fallback = osp.join(get_home_dir(), '.config')
|
||||
conf_path = os.environ.get('XDG_CONFIG_HOME', fallback)
|
||||
|
||||
return _to_full_path(conf_path, subfolder, filename, create)
|
||||
|
||||
|
||||
def get_runtime_path(subfolder=None, filename=None, create=True):
|
||||
if platform.system() == 'Darwin':
|
||||
runtime_path = get_conf_path(create=False)
|
||||
else:
|
||||
fallback = os.environ.get('XDG_CACHE_HOME', osp.join(_home_dir, '.cache'))
|
||||
runtime_path = os.environ.get('XDG_RUNTIME_DIR', fallback)
|
||||
|
||||
return _to_full_path(runtime_path, subfolder, filename, create)
|
||||
|
||||
|
||||
def get_old_runtime_path(subfolder=None, filename=None, create=True):
|
||||
if platform.system() == 'Darwin':
|
||||
runtime_path = tempfile.gettempdir()
|
||||
else:
|
||||
fallback = os.environ.get('XDG_CACHE_HOME', osp.join(_home_dir, '.cache'))
|
||||
runtime_path = os.environ.get('XDG_RUNTIME_DIR', fallback)
|
||||
|
||||
return _to_full_path(runtime_path, subfolder, filename, create)
|
||||
from maestral.utils.appdirs import get_conf_path, get_runtime_path, get_old_runtime_path
|
||||
|
||||
|
||||
def list_configs():
|
||||
|
Loading…
Reference in New Issue
Block a user