jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/423237 )

Change subject: [bugfix] Use python specific api cache paths in cache 
maintenance script
......................................................................

[bugfix] Use python specific api cache paths in cache maintenance script

- use python version specific api cache paths
- use os.path.join to concat paths
- don't restore the api cache entry if deletion is wanted only
- skip cache path if version does not match
- use pywikibot.handle_args instead of the deprecated variant

Bug: T183911
Change-Id: Idf7bcf8b8ecefc5fc3979bb2aa4c7cf4b67d63fc
---
M scripts/maintenance/cache.py
1 file changed, 28 insertions(+), 6 deletions(-)

Approvals:
  Framawiki: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index 445a277..8215d2c 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -78,6 +78,8 @@
 from pywikibot.page import User
 from pywikibot.site import APISite, DataSite, LoginStatus

+from pywikibot.tools import PYTHON_VERSION
+
 __all__ = (
     'User', 'APISite', 'DataSite', 'LoginStatus',
     'ParseError', 'CacheEntry', 'process_entries', 'main',
@@ -232,7 +234,8 @@
          - True  = always use
     """
     if not cache_path:
-        cache_path = os.path.join(pywikibot.config2.base_dir, 'apicache')
+        cache_path = os.path.join(pywikibot.config2.base_dir,
+                                  'apicache-py{0:d}'.format(PYTHON_VERSION[0]))

     if not os.path.exists(cache_path):
         pywikibot.error('%s: no such file or directory' % cache_path)
@@ -251,6 +254,21 @@
             stinfo = os.stat(filepath)

         entry = CacheEntry(cache_dir, filename)
+
+        # Deletion is choosen only, abbreviate this request
+        if func is None and output_func is None \
+           and action_func == CacheEntry._delete:
+            action_func(entry)
+            continue
+
+        # Skip foreign python specific directory
+        _, _, version = cache_path.partition('-')
+        if version and version[-1] != str(PYTHON_VERSION[0]):
+            pywikibot.error(
+                "Skipping {0} directory, can't read content with python {1[0]}"
+                .format(cache_path, PYTHON_VERSION))
+            continue
+
         try:
             entry._load_cache()
         except ValueError as e:
@@ -387,7 +405,7 @@

 def main():
     """Process command line arguments and invoke bot."""
-    local_args = pywikibot.handleArgs()
+    local_args = pywikibot.handle_args()
     cache_paths = None
     delete = False
     command = None
@@ -419,17 +437,21 @@
                 cache_paths.append(arg)

     if not cache_paths:
-        cache_paths = ['apicache', 'tests/apicache']
+        folders = ('apicache', 'apicache-py2', 'apicache-py3')
+        cache_paths = list(folders)
+        # Add tests folders
+        cache_paths += [os.path.join('tests', f) for f in folders]

         # Also process the base directory, if it isnt the current directory
         if os.path.abspath(os.getcwd()) != pywikibot.config2.base_dir:
             cache_paths += [
-                os.path.join(pywikibot.config2.base_dir, 'apicache')]
+                os.path.join(pywikibot.config2.base_dir, f) for f in folders]

         # Also process the user home cache, if it isnt the config directory
-        if os.path.expanduser('~/.pywikibot') != pywikibot.config2.base_dir:
+        userpath = os.path.expanduser(os.path.join('~', '.pywikibot'))
+        if userpath != pywikibot.config2.base_dir:
             cache_paths += [
-                os.path.join(os.path.expanduser('~/.pywikibot'), 'apicache')]
+                os.path.join(userpath, f) for f in folders]

     if delete:
         action_func = CacheEntry._delete

--
To view, visit https://gerrit.wikimedia.org/r/423237
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Idf7bcf8b8ecefc5fc3979bb2aa4c7cf4b67d63fc
Gerrit-Change-Number: 423237
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: Zoranzoki21 <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to