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