improve --clear-cache (#1230)
Allow for an optional argument to only delete cached entries from a specific module. delete all cache entries $ gallery-dl --clear-cache or $ gallery-dl --clear-cache all only delete entries for instagram $ gallery-dl --clear-cache instagram
This commit is contained in:
@@ -186,7 +186,7 @@ def main():
|
|||||||
elif args.clear_cache:
|
elif args.clear_cache:
|
||||||
from . import cache
|
from . import cache
|
||||||
log = logging.getLogger("cache")
|
log = logging.getLogger("cache")
|
||||||
cnt = cache.clear()
|
cnt = cache.clear(args.clear_cache)
|
||||||
|
|
||||||
if cnt is None:
|
if cnt is None:
|
||||||
log.error("Database file not available")
|
log.error("Database file not available")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2016-2020 Mike Fährmann
|
# Copyright 2016-2021 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -168,24 +168,33 @@ def cache(maxage=3600, keyarg=None):
|
|||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear(module="all"):
|
||||||
"""Delete all database entries"""
|
"""Delete database entries for 'module'"""
|
||||||
db = DatabaseCacheDecorator.db
|
db = DatabaseCacheDecorator.db
|
||||||
|
if not db:
|
||||||
|
return None
|
||||||
|
|
||||||
if db:
|
rowcount = 0
|
||||||
rowcount = 0
|
cursor = db.cursor()
|
||||||
cursor = db.cursor()
|
module = module.lower()
|
||||||
try:
|
|
||||||
|
try:
|
||||||
|
if module == "all":
|
||||||
cursor.execute("DELETE FROM data")
|
cursor.execute("DELETE FROM data")
|
||||||
except sqlite3.OperationalError:
|
|
||||||
pass # database is not initialized, can't be modified, etc.
|
|
||||||
else:
|
else:
|
||||||
rowcount = cursor.rowcount
|
cursor.execute(
|
||||||
db.commit()
|
"DELETE FROM data "
|
||||||
|
"WHERE key LIKE 'gallery_dl.extractor.' || ? || '.%'",
|
||||||
|
(module,)
|
||||||
|
)
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
pass # database is not initialized, can't be modified, etc.
|
||||||
|
else:
|
||||||
|
rowcount = cursor.rowcount
|
||||||
|
db.commit()
|
||||||
|
if rowcount:
|
||||||
cursor.execute("VACUUM")
|
cursor.execute("VACUUM")
|
||||||
return rowcount
|
return rowcount
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _path():
|
def _path():
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ def build_parser():
|
|||||||
)
|
)
|
||||||
general.add_argument(
|
general.add_argument(
|
||||||
"--clear-cache",
|
"--clear-cache",
|
||||||
dest="clear_cache", action="store_true",
|
dest="clear_cache", metavar="MODULE", nargs="?", const="all",
|
||||||
help="Delete all cached login sessions, cookies, etc.",
|
help="Delete all cached login sessions, cookies, etc.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user