mirror of
https://github.com/mikf/gallery-dl.git
synced 2025-01-31 19:51:34 +01:00
implement '--clear-cache'
Effectively clears all cached values from the cache database by executing "DELETE FROM data" without any further user input.
This commit is contained in:
parent
0318c610dc
commit
bc26fc2439
@ -181,6 +181,18 @@ def main():
|
||||
if test:
|
||||
print("Example :", test[0])
|
||||
print()
|
||||
elif args.clear_cache:
|
||||
from . import cache
|
||||
log = logging.getLogger("cache")
|
||||
cnt = cache.clear()
|
||||
|
||||
if cnt is None:
|
||||
log.error("Database file not available")
|
||||
else:
|
||||
log.info(
|
||||
"Deleted %d %s from '%s'",
|
||||
cnt, "entry" if cnt == 1 else "entries", cache._path(),
|
||||
)
|
||||
else:
|
||||
if not args.urls and not args.inputfile:
|
||||
parser.error(
|
||||
|
@ -166,19 +166,39 @@ def cache(maxage=3600, keyarg=None):
|
||||
return wrap
|
||||
|
||||
|
||||
try:
|
||||
path = config.get(("cache", "file"), "")
|
||||
if path is None:
|
||||
raise RuntimeError()
|
||||
elif not path:
|
||||
def clear():
|
||||
"""Delete all database entries"""
|
||||
db = DatabaseCacheDecorator.db
|
||||
|
||||
if db:
|
||||
rowcount = 0
|
||||
cursor = db.cursor()
|
||||
try:
|
||||
cursor.execute("DELETE FROM data")
|
||||
except sqlite3.OperationalError:
|
||||
pass # database is not initialized, can't be modified, etc.
|
||||
else:
|
||||
rowcount = cursor.rowcount
|
||||
db.commit()
|
||||
cursor.execute("VACUUM")
|
||||
return rowcount
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def _path():
|
||||
path = config.get(("cache", "file"), -1)
|
||||
|
||||
if path == -1:
|
||||
import tempfile
|
||||
import os.path
|
||||
path = os.path.join(tempfile.gettempdir(), ".gallery-dl.cache")
|
||||
else:
|
||||
path = util.expand_path(path)
|
||||
return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache")
|
||||
|
||||
return util.expand_path(path)
|
||||
|
||||
|
||||
try:
|
||||
DatabaseCacheDecorator.db = sqlite3.connect(
|
||||
path, timeout=30, check_same_thread=False)
|
||||
|
||||
except (RuntimeError, sqlite3.OperationalError):
|
||||
_path(), timeout=30, check_same_thread=False)
|
||||
except (TypeError, sqlite3.OperationalError):
|
||||
cache = memcache # noqa: F811
|
||||
|
@ -93,6 +93,11 @@ def build_parser():
|
||||
metavar="URL", action=ConfigAction, dest="proxy",
|
||||
help="Use the specified proxy",
|
||||
)
|
||||
general.add_argument(
|
||||
"--clear-cache",
|
||||
dest="clear_cache", action="store_true",
|
||||
help="Delete all cached login sessions, cookies, etc.",
|
||||
)
|
||||
|
||||
output = parser.add_argument_group("Output Options")
|
||||
output.add_argument(
|
||||
|
Loading…
x
Reference in New Issue
Block a user