changeset 8771:f8971422795e

scripts: introduce source_format.py to fix up the module name in file headers
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 07 Nov 2020 02:29:41 +0100
parents 0a84ef075575
children 52816813cbec
files kallithea/bin/vcs_hooks.py kallithea/config/middleware/https_fixup.py kallithea/config/middleware/permanent_repo_url.py kallithea/config/middleware/pygrack.py kallithea/config/middleware/simplegit.py kallithea/config/middleware/simplehg.py kallithea/config/middleware/wrapper.py kallithea/lib/conf.py kallithea/lib/webutils.py kallithea/model/userlog.py scripts/run-all-cleanup scripts/source_format.py
diffstat 12 files changed, 42 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/bin/vcs_hooks.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/bin/vcs_hooks.py	Sat Nov 07 02:29:41 2020 +0100
@@ -13,7 +13,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 kallithea.bin.vcs_hooks
-~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~
 
 Entry points for Kallithea hooking into Mercurial and Git.
 
--- a/kallithea/config/middleware/https_fixup.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/config/middleware/https_fixup.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.middleware.https_fixup
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+kallithea.config.middleware.https_fixup
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 middleware to handle https correctly
 
--- a/kallithea/config/middleware/permanent_repo_url.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/config/middleware/permanent_repo_url.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.middleware.permanent_repo_url
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+kallithea.config.middleware.permanent_repo_url
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 middleware to handle permanent repo URLs, replacing PATH_INFO '/_123/yada' with
 '/name/of/repo/yada' after looking 123 up in the database.
--- a/kallithea/config/middleware/pygrack.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/config/middleware/pygrack.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.middleware.pygrack
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+kallithea.config.middleware.pygrack
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Python implementation of git-http-backend's Smart HTTP protocol
 
--- a/kallithea/config/middleware/simplegit.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/config/middleware/simplegit.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.middleware.simplegit
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+kallithea.config.middleware.simplegit
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 SimpleGit middleware for handling Git protocol requests (push/clone etc.)
 It's implemented with basic auth function
--- a/kallithea/config/middleware/simplehg.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/config/middleware/simplehg.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.middleware.simplehg
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+kallithea.config.middleware.simplehg
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 SimpleHg middleware for handling Mercurial protocol requests (push/clone etc.).
 It's implemented with basic auth function
--- a/kallithea/config/middleware/wrapper.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/config/middleware/wrapper.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.middleware.wrapper
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+kallithea.config.middleware.wrapper
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Wrap app to measure request and response time ... all the way to the response
 WSGI iterator has been closed.
--- a/kallithea/lib/conf.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/lib/conf.py	Sat Nov 07 02:29:41 2020 +0100
@@ -13,7 +13,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 kallithea.lib.conf
-~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~
 
 Various config settings for Kallithea
 
--- a/kallithea/lib/webutils.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/lib/webutils.py	Sat Nov 07 02:29:41 2020 +0100
@@ -13,7 +13,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 kallithea.lib.webutils
-~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~
 
 Helper functions that may rely on the current WSGI request, exposed in the TG2
 thread-local "global" variables. It should have few dependencies so it can be
--- a/kallithea/model/userlog.py	Sun Oct 11 10:13:25 2020 +0200
+++ b/kallithea/model/userlog.py	Sat Nov 07 02:29:41 2020 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.model.db
-~~~~~~~~~~~~~~~~~~
+kallithea.model.userlog
+~~~~~~~~~~~~~~~~~~~~~~~
 
 Database Models for Kallithea
 
--- a/scripts/run-all-cleanup	Sun Oct 11 10:13:25 2020 +0200
+++ b/scripts/run-all-cleanup	Sat Nov 07 02:29:41 2020 +0100
@@ -8,6 +8,7 @@
 scripts/docs-headings.py
 scripts/generate-ini.py
 scripts/whitespacecleanup.sh
+hg files 'set:!binary()&grep("^#!.*python")' 'set:**.py' | xargs scripts/source_format.py
 
 hg files 'set:!binary()&grep("^#!.*python")' 'set:**.py' | xargs scripts/pyflakes
 echo "no blocking problems found by $0"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/source_format.py	Sat Nov 07 02:29:41 2020 +0100
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+# hg files 'set:!binary()&grep("^#!.*python")' 'set:**.py' | xargs scripts/source_format.py
+
+import re
+import sys
+
+
+filenames = sys.argv[1:]
+
+for fn in filenames:
+    with open(fn) as f:
+        org_content = f.read()
+
+    mod_name = fn[:-3] if fn.endswith('.py') else fn
+    mod_name = mod_name[:-9] if mod_name.endswith('/__init__') else mod_name
+    mod_name = mod_name.replace('/', '.')
+    def f(m):
+        return '"""\n%s\n%s\n' % (mod_name, '~' * len(mod_name))
+    new_content = re.sub(r'^"""\n(kallithea\..*\n)(~+\n)?', f, org_content, count=1, flags=re.MULTILINE)
+
+    if new_content != org_content:
+        with open(fn, 'w') as f:
+            f.write(new_content)