Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/263348

Change subject: update maintenance from master
......................................................................

update maintenance from master

- coding
- doc strings
- import oder
- verbose statement in compat2core.py
- IDENT constant and parameter order in make_i18n_dict.py

Change-Id: I87766e515ec53a155599f5426fabadc5a43b7ba7
---
M scripts/maintenance/__init__.py
M scripts/maintenance/cache.py
M scripts/maintenance/compat2core.py
M scripts/maintenance/make_i18n_dict.py
M scripts/maintenance/wikimedia_sites.py
5 files changed, 55 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/48/263348/1

diff --git a/scripts/maintenance/__init__.py b/scripts/maintenance/__init__.py
index ee430b4..fd43e14 100644
--- a/scripts/maintenance/__init__.py
+++ b/scripts/maintenance/__init__.py
@@ -1,2 +1,3 @@
+# -*- coding: utf-8  -*-
 # THIS DIRECTORY IS TO HOLD BOT SCRIPTS FOR THE NEW FRAMEWORK
 """Maintenance scripts."""
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index f05e9fd..15610f3 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -3,29 +3,35 @@
 r"""
 This script runs commands on each entry in the API caches.
 
-Syntax: cache.py [-password] [-delete] [-c '...'] [dir ...]
+Syntax:
+
+    python pwb.py cache [-password] [-delete] [-c "..."] [dir ...]
 
 If no directory are specified, it will detect the API caches.
 
 If no command is specified, it will print the filename of all entries.
 If only -delete is specified, it will delete all entries.
 
-The option '-c' must be followed by a command in python syntax.
+-delete           Delete each command filtered. If that option is set the
+                  default output will be nothing.
+
+-c                Filter command in python syntax. It must evaulate to True to
+                  output anything.
 
 Example commands:
   Print the filename of any entry with 'wikidata' in the key:
 
-    entry if "wikidata" in entry._uniquedescriptionstr() else None
+    -c entry if "wikidata" in entry._uniquedescriptionstr() else None
 
   Customised output if the site code is 'ar':
 
-    entry.site.code == "ar" and print("%s" % entry._uniquedescriptionstr())
+    -c entry.site.code == "ar" and print("%s" % entry._uniquedescriptionstr())
 
   Or the state of the login
-    entry.site._loginstatus == LoginStatus.NOT_ATTEMPTED and \
+    -c entry.site._loginstatus == LoginStatus.NOT_ATTEMPTED and \
 print("%s" % entry._uniquedescriptionstr())
 
-  These functions can be used as a command:
+Available filter commands:
     has_password(entry)
     is_logout(entry)
     empty_response(entry)
@@ -39,7 +45,7 @@
     newer_than(entry, interval)
 """
 #
-# (C) Pywikibot team, 2014
+# (C) Pywikibot team, 2014-2015
 #
 # Distributed under the terms of the MIT license.
 #
@@ -47,15 +53,17 @@
 __version__ = '$Id$'
 #
 
-import os
 import datetime
-import pickle
 import hashlib
+import os
+import pickle
+
 import pywikibot
+
 from pywikibot.data import api
 
-from pywikibot.site import APISite, DataSite, LoginStatus  # noqa
 from pywikibot.page import User  # noqa
+from pywikibot.site import APISite, DataSite, LoginStatus  # noqa
 
 
 class ParseError(Exception):
@@ -248,6 +256,8 @@
         func(entry)
 
 
+# Filter commands
+
 def has_password(entry):
     """Entry has a password in the entry."""
     if 'lgpassword' in entry._uniquedescriptionstr():
diff --git a/scripts/maintenance/compat2core.py 
b/scripts/maintenance/compat2core.py
index fb9ef6c..da3b33b 100755
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -17,13 +17,16 @@
 usage
 
 to convert a script and show warnings about deprecated methods:
-            pwb.py maintenance/compat2core <scriptname>
+
+    python  pwb.py maintenance/compat2core <scriptname>
 
 to show warnings about deprecated methods:
-            pwb.py maintenance/compat2core <scriptname> -warnonly
+
+    python pwb.py maintenance/compat2core <scriptname> -warnonly
 """
 #
-# (C) xqt, 2014
+# (C) xqt, 2014-2015
+# (C) Pywikibot team, 2014-2015
 #
 # Distributed under the terms of the MIT license.
 #
@@ -32,9 +35,10 @@
 __version__ = '$Id$'
 #
 
+import codecs
 import os
 import re
-import codecs
+
 import pywikibot
 
 # be careful with replacement order!
@@ -76,8 +80,9 @@
     # other deprecated methods
     (r'(?<!site)\.encoding\s*\(\s*\)', '.site.encoding()'),
     (r'\.newimages\s*\(', '.newfiles('),
-    # new core methods
+    # new core methods and properties
     (r'\.get\s*\(\s*get_redirect\s*=\s*True\s*\)', '.text'),
+    (r'(?:pywikibot|wikipedia)\.verbose', 'config.verbose_output'),
     # stopme() is done by the framework itself
     (r'(\s*)try\:\s*\r?\n\s+main\(\)\s*\r?\n\s*finally\:\s*\r?\n'
      r'\s+pywikibot\.stopme\(\)',
@@ -110,6 +115,8 @@
     ('query.GetData(',
      'query.GetData() should be replaced by pywikibot.data.api.Request or\n'
      'by a direct site request'),
+    ('.verbose',
+     'verbose_output need "from pywikibot import config" first')
 )
 
 
diff --git a/scripts/maintenance/make_i18n_dict.py 
b/scripts/maintenance/make_i18n_dict.py
index bb6155f..0e4ecd1 100755
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -23,8 +23,8 @@
 >>> bot.to_json()
 """
 #
-# (C) xqt, 2013-2014
-# (C) Pywikibot team, 2013-2014
+# (C) xqt, 2013-2015
+# (C) Pywikibot team, 2013-2015
 #
 # Distributed under the terms of the MIT license.
 #
@@ -33,9 +33,9 @@
 __version__ = '$Id$'
 #
 
-import os
-import json
 import codecs
+import json
+import os
 
 from pywikibot import config
 
@@ -55,9 +55,10 @@
             if hasattr(self.script, msg):
                 self.messages.append(msg)
         self.messages.sort()
-        self.dict = dict()
+        self.dict = {}
 
     def print_all(self):
+        """Pretty print the dict as a file content to screen."""
         keys = list(self.dict.keys())
         keys.remove('qqq')
         keys.sort()
@@ -79,6 +80,7 @@
         print("};")
 
     def read(self, item):
+        """Read a single message from source script."""
         msg = getattr(self.script, item)
         keys = list(msg.keys())
         keys.append('qqq')
@@ -89,7 +91,7 @@
                     self.dict[code] = {}
                 self.dict[code][label] = (
                     u'Edit summary for message %s of %s report'
-                    % (self.scriptname, item))
+                    % (item, self.scriptname))
             elif code != 'commons':
                 if code not in self.dict:
                     self.dict[code] = {}
@@ -98,11 +100,19 @@
             print('WARNING: "en" key missing for message %s' % item)
 
     def run(self):
+        """
+        Run the bot, read the messages from source and print the dict.
+        """
         for msg in self.messages:
             self.read(msg)
         self.print_all()
 
     def to_json(self):
+        """
+        Run the bot and create json files.
+        """
+        IDENT = 4
+
         if not self.dict:
             self.run()
         json_dir = os.path.join(
@@ -119,8 +129,8 @@
             new_dict['@metadata'] = new_dict.get('@metadata', {'authors': []})
             with codecs.open(file_name, 'w', 'utf-8') as json_file:
                 new_dict.update(self.dict[lang])
-                json.dump(new_dict, json_file, ensure_ascii=False,
-                          sort_keys=True, indent=4, separators=(',', ': '))
+                json.dump(new_dict, json_file, ensure_ascii=False, 
sort_keys=True,
+                          indent=IDENT, separators=(',', ': '))
 
 if __name__ == '__main__':
     print(__doc__)
diff --git a/scripts/maintenance/wikimedia_sites.py 
b/scripts/maintenance/wikimedia_sites.py
index ccd2417..f582a01 100755
--- a/scripts/maintenance/wikimedia_sites.py
+++ b/scripts/maintenance/wikimedia_sites.py
@@ -12,12 +12,14 @@
 __version__ = '$Id$'
 #
 
-import re
 import codecs
-from xml.etree import cElementTree
+import re
 import sys
 
+from xml.etree import cElementTree
+
 import pywikibot
+
 from pywikibot.family import Family
 
 if sys.version_info[0] > 2:

-- 
To view, visit https://gerrit.wikimedia.org/r/263348
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I87766e515ec53a155599f5426fabadc5a43b7ba7
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to