Make standarddir.Location private
This commit is contained in:
parent
ba03e9394a
commit
3a7206bda1
@ -35,9 +35,17 @@ from qutebrowser.utils import log, debug, message, utils
|
|||||||
_locations = {}
|
_locations = {}
|
||||||
|
|
||||||
|
|
||||||
Location = enum.Enum('Location', ['config', 'auto_config',
|
class _Location(enum.Enum):
|
||||||
'data', 'system_data',
|
|
||||||
'cache', 'download', 'runtime'])
|
"""A key for _locations."""
|
||||||
|
|
||||||
|
config = 1
|
||||||
|
auto_config = 2
|
||||||
|
data = 3
|
||||||
|
system_data = 4
|
||||||
|
cache = 5
|
||||||
|
download = 6
|
||||||
|
runtime = 7
|
||||||
|
|
||||||
|
|
||||||
APPNAME = 'qutebrowser'
|
APPNAME = 'qutebrowser'
|
||||||
@ -77,8 +85,8 @@ def _init_config(args):
|
|||||||
else:
|
else:
|
||||||
path = _writable_location(typ)
|
path = _writable_location(typ)
|
||||||
_create(path)
|
_create(path)
|
||||||
_locations[Location.config] = path
|
_locations[_Location.config] = path
|
||||||
_locations[Location.auto_config] = path
|
_locations[_Location.auto_config] = path
|
||||||
|
|
||||||
# Override the normal (non-auto) config on macOS
|
# Override the normal (non-auto) config on macOS
|
||||||
if utils.is_mac:
|
if utils.is_mac:
|
||||||
@ -86,7 +94,7 @@ def _init_config(args):
|
|||||||
if not overridden: # pragma: no branch
|
if not overridden: # pragma: no branch
|
||||||
path = os.path.expanduser('~/.' + APPNAME)
|
path = os.path.expanduser('~/.' + APPNAME)
|
||||||
_create(path)
|
_create(path)
|
||||||
_locations[Location.config] = path
|
_locations[_Location.config] = path
|
||||||
|
|
||||||
|
|
||||||
def config(auto=False):
|
def config(auto=False):
|
||||||
@ -96,8 +104,8 @@ def config(auto=False):
|
|||||||
which is different on macOS.
|
which is different on macOS.
|
||||||
"""
|
"""
|
||||||
if auto:
|
if auto:
|
||||||
return _locations[Location.auto_config]
|
return _locations[_Location.auto_config]
|
||||||
return _locations[Location.config]
|
return _locations[_Location.config]
|
||||||
|
|
||||||
|
|
||||||
def _init_data(args):
|
def _init_data(args):
|
||||||
@ -115,14 +123,14 @@ def _init_data(args):
|
|||||||
else:
|
else:
|
||||||
path = _writable_location(typ)
|
path = _writable_location(typ)
|
||||||
_create(path)
|
_create(path)
|
||||||
_locations[Location.data] = path
|
_locations[_Location.data] = path
|
||||||
|
|
||||||
# system_data
|
# system_data
|
||||||
_locations.pop(Location.system_data, None) # Remove old state
|
_locations.pop(_Location.system_data, None) # Remove old state
|
||||||
if utils.is_linux:
|
if utils.is_linux:
|
||||||
path = '/usr/share/' + APPNAME
|
path = '/usr/share/' + APPNAME
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
_locations[Location.system_data] = path
|
_locations[_Location.system_data] = path
|
||||||
|
|
||||||
|
|
||||||
def data(system=False):
|
def data(system=False):
|
||||||
@ -133,10 +141,10 @@ def data(system=False):
|
|||||||
"""
|
"""
|
||||||
if system:
|
if system:
|
||||||
try:
|
try:
|
||||||
return _locations[Location.system_data]
|
return _locations[_Location.system_data]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return _locations[Location.data]
|
return _locations[_Location.data]
|
||||||
|
|
||||||
|
|
||||||
def _init_cache(args):
|
def _init_cache(args):
|
||||||
@ -151,11 +159,11 @@ def _init_cache(args):
|
|||||||
else:
|
else:
|
||||||
path = _writable_location(typ)
|
path = _writable_location(typ)
|
||||||
_create(path)
|
_create(path)
|
||||||
_locations[Location.cache] = path
|
_locations[_Location.cache] = path
|
||||||
|
|
||||||
|
|
||||||
def cache():
|
def cache():
|
||||||
return _locations[Location.cache]
|
return _locations[_Location.cache]
|
||||||
|
|
||||||
|
|
||||||
def _init_download(args):
|
def _init_download(args):
|
||||||
@ -168,11 +176,11 @@ def _init_download(args):
|
|||||||
overridden, path = _from_args(typ, args)
|
overridden, path = _from_args(typ, args)
|
||||||
if not overridden:
|
if not overridden:
|
||||||
path = _writable_location(typ)
|
path = _writable_location(typ)
|
||||||
_locations[Location.download] = path
|
_locations[_Location.download] = path
|
||||||
|
|
||||||
|
|
||||||
def download():
|
def download():
|
||||||
return _locations[Location.download]
|
return _locations[_Location.download]
|
||||||
|
|
||||||
|
|
||||||
def _init_runtime(args):
|
def _init_runtime(args):
|
||||||
@ -205,11 +213,11 @@ def _init_runtime(args):
|
|||||||
# maximum length of 104 chars), so we don't add the username here...
|
# maximum length of 104 chars), so we don't add the username here...
|
||||||
|
|
||||||
_create(path)
|
_create(path)
|
||||||
_locations[Location.runtime] = path
|
_locations[_Location.runtime] = path
|
||||||
|
|
||||||
|
|
||||||
def runtime():
|
def runtime():
|
||||||
return _locations[Location.runtime]
|
return _locations[_Location.runtime]
|
||||||
|
|
||||||
|
|
||||||
def _writable_location(typ):
|
def _writable_location(typ):
|
||||||
|
Loading…
Reference in New Issue
Block a user