mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
add 'util.expand_path()'
This commit is contained in:
parent
9a41002b77
commit
ea8ca4cfa4
@ -14,7 +14,7 @@ import time
|
||||
import tempfile
|
||||
import os.path
|
||||
import functools
|
||||
from . import config
|
||||
from . import config, util
|
||||
|
||||
|
||||
class CacheInvalidError(Exception):
|
||||
@ -111,7 +111,7 @@ class DatabaseCache(CacheModule):
|
||||
path = config.get(("cache", "file"), path_default)
|
||||
if path is None:
|
||||
raise RuntimeError()
|
||||
path = os.path.expanduser(os.path.expandvars(path))
|
||||
path = util.expand_path(path)
|
||||
self.db = sqlite3.connect(path, timeout=30, check_same_thread=False)
|
||||
self.db.execute(
|
||||
"CREATE TABLE IF NOT EXISTS data ("
|
||||
|
@ -55,7 +55,7 @@ def load(*files, format="json", strict=False):
|
||||
|
||||
for conf in configfiles:
|
||||
try:
|
||||
path = os.path.expanduser(os.path.expandvars(conf))
|
||||
path = util.expand_path(conf)
|
||||
with open(path) as file:
|
||||
confdict = parsefunc(file)
|
||||
if not _config:
|
||||
|
@ -104,6 +104,13 @@ def safe_int(value, default=0):
|
||||
return default
|
||||
|
||||
|
||||
def expand_path(path):
|
||||
"""Expand environment variables and tildes (~)"""
|
||||
if not path:
|
||||
return path
|
||||
return os.path.expandvars(os.path.expanduser(path))
|
||||
|
||||
|
||||
def code_to_language(code, default=None):
|
||||
"""Map an ISO 639-1 language code to its actual name"""
|
||||
return CODES.get((code or "").lower(), default)
|
||||
@ -325,7 +332,7 @@ class PathFormat():
|
||||
bdir = extractor.config("base-directory", (".", "gallery-dl"))
|
||||
if not isinstance(bdir, str):
|
||||
bdir = os.path.join(*bdir)
|
||||
self.basedirectory = os.path.expanduser(os.path.expandvars(bdir))
|
||||
self.basedirectory = expand_path(bdir)
|
||||
|
||||
skipmode = extractor.config("skip", True)
|
||||
if skipmode == "abort":
|
||||
|
Loading…
Reference in New Issue
Block a user