jenkins-bot has submitted this change and it was merged.
Change subject: View individual cache files
......................................................................
View individual cache files
Allow one or more cache entries to be viewed by supplying the cache key.
Allow cache commands to use the print function.
Catch and display exceptions if pickle cant load cache entry, such as
wrong version.
Change-Id: Ib9ae0c87a13f9bec04fc83f4d934b2a424779720
---
M scripts/maintenance/cache.py
M tox.ini
2 files changed, 36 insertions(+), 20 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index c97ce54..27c1671 100644
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -18,12 +18,11 @@
Customised output if the site code is 'ar':
- entry.site.code == "ar" and \
-pywikibot.output("%s" % entry._uniquedescriptionstr())
+ entry.site.code == "ar" and print("%s" %
entry._uniquedescriptionstr())
Or the state of the login
entry.site._loginstatus == LoginStatus.NOT_ATTEMPTED and \
-pywikibot.output("%s" % entry._uniquedescriptionstr())
+print("%s" % entry._uniquedescriptionstr())
These functions can be used as a command:
has_password(entry)
@@ -43,6 +42,7 @@
#
# Distributed under the terms of the MIT license.
#
+from __future__ import print_function
__version__ = '$Id$'
#
@@ -171,7 +171,7 @@
os.remove(self._cachefile_path())
-def process_entries(cache_dir, func):
+def process_entries(cache_path, func):
""" Check the contents of the cache. """
# This program tries to use file access times to determine
@@ -185,15 +185,28 @@
# - True = always use
use_accesstime = None
- if not cache_dir:
- cache_dir = os.path.join(pywikibot.config2.base_dir, 'apicache')
- for filename in os.listdir(cache_dir):
- filepath = os.path.join(cache_dir, filename)
+ if not cache_path:
+ cache_path = os.path.join(pywikibot.config2.base_dir, 'apicache')
+
+ if os.path.isdir(cache_path):
+ filenames = [os.path.join(cache_path, filename)
+ for filename in os.listdir(cache_path)]
+ else:
+ filenames = [cache_path]
+
+ for filepath in filenames:
+ filename = os.path.basename(filepath)
+ cache_dir = os.path.dirname(filepath)
if use_accesstime is not False:
stinfo = os.stat(filepath)
entry = CacheEntry(cache_dir, filename)
- entry._load_cache()
+ try:
+ entry._load_cache()
+ except ValueError as e:
+ print('Failed loading %s' % entry._cachefile_path())
+ pywikibot.exception(e, tb=True)
+ continue
if use_accesstime is None:
stinfo2 = os.stat(filepath)
@@ -214,10 +227,10 @@
try:
entry._rebuild()
- except Exception:
+ except Exception as e:
pywikibot.error(u'Problems loading %s with key %s, %r'
% (entry.filename, entry.key, entry._parsed_key))
- pywikibot.exception()
+ pywikibot.exception(e, tb=True)
continue
func(entry)
@@ -277,7 +290,7 @@
def main():
local_args = pywikibot.handleArgs()
- cache_dirs = None
+ cache_paths = None
delete = False
command = None
@@ -294,12 +307,15 @@
exit(1)
command = ''
else:
- cache_dir = [arg]
+ if not cache_paths:
+ cache_paths = [arg]
+ else:
+ cache_paths.append(arg)
func = None
- if not cache_dirs:
- cache_dirs = ['apicache', 'tests/apicache']
+ if not cache_paths:
+ cache_paths = ['apicache', 'tests/apicache']
# Also process the base directory, if it isnt the current directory
if os.path.abspath(os.getcwd()) != pywikibot.config2.base_dir:
@@ -328,11 +344,10 @@
else:
func = action_func
- for cache_dir in cache_dirs:
- if os.path.isdir(cache_dir):
- if len(cache_dirs) > 1:
- pywikibot.output(u'Processing %s' % cache_dir)
- process_entries(cache_dir, func)
+ for cache_path in cache_paths:
+ if len(cache_paths) > 1:
+ pywikibot.output(u'Processing %s' % cache_path)
+ process_entries(cache_path, func)
if __name__ == '__main__':
main()
diff --git a/tox.ini b/tox.ini
index 341cf42..fd26d1c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -58,6 +58,7 @@
./tests/aspects.py \
./tests/api_tests.py \
./tests/dry_api_tests.py \
+ ./scripts/maintenance/cache.py \
./tests/upload_tests.py
deps = flake8-docstrings
--
To view, visit
https://gerrit.wikimedia.org/r/161772
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib9ae0c87a13f9bec04fc83f4d934b2a424779720
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>