aboutsummaryrefslogtreecommitdiff
path: root/git-arr
diff options
context:
space:
mode:
authorAlberto Bertogli <albertito@blitiri.com.ar>2020-05-24 03:36:43 +0200
committerAlberto Bertogli <albertito@blitiri.com.ar>2020-05-24 05:50:39 +0200
commit1183d6f817046a9f2b82a8d61b56046f046afb3f (patch)
treec97cd9382583fb5b7b9ae7c83efdc684ef7b3cf5 /git-arr
parentcbb36e087c1bcf1c81de53e920baf0c681abfd87 (diff)
downloadgit-arr-fork-1183d6f817046a9f2b82a8d61b56046f046afb3f.zip
Move to Python 3
Python 3 was released more than 10 years ago, and support for Python 2 is going away, with many Linux distributions starting to phase it out. This patch migrates git-arr to Python 3. The generated output is almost exactly the same, there are some minor differences such as HTML characters being quoted more aggresively, and handling of paths with non-utf8 values.
Diffstat (limited to 'git-arr')
-rwxr-xr-xgit-arr24
1 files changed, 11 insertions, 13 deletions
diff --git a/git-arr b/git-arr
index 5c4e7db..98a6bc7 100755
--- a/git-arr
+++ b/git-arr
@@ -1,21 +1,15 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
git-arr: A git web html generator.
"""
-from __future__ import print_function
-
+import configparser
import math
import optparse
import os
import re
import sys
-try:
- import configparser
-except ImportError:
- import ConfigParser as configparser
-
import bottle
import git
@@ -64,7 +58,7 @@ def load_config(path):
'generate_patch': 'yes',
}
- config = configparser.SafeConfigParser(defaults)
+ config = configparser.ConfigParser(defaults)
config.read(path)
# Do a first pass for general sanity checking and recursive expansion.
@@ -118,7 +112,7 @@ def load_config(path):
r.info.commits_per_page = config.getint(s, 'commits_per_page')
r.info.max_pages = config.getint(s, 'max_pages')
if r.info.max_pages <= 0:
- r.info.max_pages = sys.maxint
+ r.info.max_pages = sys.maxsize
r.info.generate_tree = config.getboolean(s, 'tree')
r.info.root_diff = config.getboolean(s, 'rootdiff')
r.info.generate_patch = config.getboolean(s, 'generate_patch')
@@ -263,6 +257,10 @@ def blob(repo, bname, fname, dirname = ''):
fname = git.smstr.from_url(fname)
path = dirname.raw + fname.raw
+ # Handle backslash-escaped characters, which are not utf8.
+ # This matches the generated links from git.unquote().
+ path = path.encode("utf8").decode("unicode-escape").encode("latin1")
+
content = repo.blob(path, bname)
if content is None:
bottle.abort(404, "File %r not found in branch %s" % (path, bname))
@@ -339,7 +337,7 @@ def generate(output, only = None):
else:
# Otherwise, be lazy if we were given a function to run, or write
# always if they gave us a string.
- if isinstance(func_or_str, (str, unicode)):
+ if isinstance(func_or_str, str):
print(path)
s = func_or_str
else:
@@ -348,7 +346,7 @@ def generate(output, only = None):
print(path)
s = func_or_str(*args)
- open(path, 'w').write(s.encode('utf8', errors = 'xmlcharrefreplace'))
+ open(path, 'w').write(s)
if mtime:
os.utime(path, (mtime, mtime))
@@ -398,7 +396,7 @@ def generate(output, only = None):
write_to('static/syntax.css', read_f, [static_path + '/syntax.css'],
os.stat(static_path + '/syntax.css').st_mtime)
- rs = sorted(repos.values(), key = lambda r: r.name)
+ rs = sorted(list(repos.values()), key = lambda r: r.name)
if only:
rs = [r for r in rs if r.name in only]