changeset 7666:4473f1094d3d

scripts: clean up and run the old scripts/logformat.py script
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 05 Jan 2019 14:57:49 +0100
parents 8fbcdfe364d4
children ed9fea79a321
files kallithea/lib/auth.py kallithea/lib/page.py scripts/logformat.py
diffstat 3 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/auth.py	Thu Jan 03 01:03:14 2019 +0100
+++ b/kallithea/lib/auth.py	Sat Jan 05 14:57:49 2019 +0100
@@ -933,8 +933,8 @@
         global_permissions = request.authuser.permissions['global'] # usually very short
         ok = any(p in global_permissions for p in self.required_perms)
 
-        log.debug('Check %s for global %s (%s): %s' %
-            (request.authuser.username, self.required_perms, purpose, ok))
+        log.debug('Check %s for global %s (%s): %s',
+            request.authuser.username, self.required_perms, purpose, ok)
         return ok
 
 
@@ -983,7 +983,7 @@
         except KeyError:
             ok = False
 
-        log.debug('Middleware check %s for %s for repo %s (%s): %s' % (user.username, self.required_perms, repo_name, purpose, ok))
+        log.debug('Middleware check %s for %s for repo %s (%s): %s', user.username, self.required_perms, repo_name, purpose, ok)
         return ok
 
 
--- a/kallithea/lib/page.py	Thu Jan 03 01:03:14 2019 +0100
+++ b/kallithea/lib/page.py	Sat Jan 05 14:57:49 2019 +0100
@@ -190,7 +190,7 @@
         try:
             self.page = int(page)  # make it int() if we get it as a string
         except (ValueError, TypeError):
-            log.error("Invalid page value: %r" % page)
+            log.error("Invalid page value: %r", page)
             self.page = 1
 
         self.items_per_page = items_per_page
--- a/scripts/logformat.py	Thu Jan 03 01:03:14 2019 +0100
+++ b/scripts/logformat.py	Sat Jan 05 14:57:49 2019 +0100
@@ -3,13 +3,6 @@
 import re
 import sys
 
-if len(sys.argv) < 2:
-    print 'Cleanup of superfluous % formatting of log statements.'
-    print 'Usage:'
-    print '''  hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff'''
-    raise SystemExit(1)
-
-
 logre = r'''
 (log\.(?:error|info|warning|debug)
 [(][ \n]*
@@ -19,6 +12,8 @@
 [ \n]*[)]
 )
 '''
+
+
 res = [
     # handle % () - keeping spaces around the old %
     (re.compile(logre % r'''("[^"]*"|'[^']*')   ([\n ]*) %  ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
@@ -32,8 +27,20 @@
     (re.compile(logre % r'''("[^"]*"|'[^']*') ,       () (   [\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
     ]
 
-for f in sys.argv[1:]:
+
+def rewrite(f):
     s = open(f).read()
     for r, t in res:
         s = r.sub(t, s)
     open(f, 'w').write(s)
+
+
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        print 'Cleanup of superfluous % formatting of log statements.'
+        print 'Usage:'
+        print '''  hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff'''
+        raise SystemExit(1)
+
+    for f in sys.argv[1:]:
+        rewrite(f)