This instance will be upgraded to Heptapod 0.23.2 on 2021-08-05 at 11:00 UTC+2 (a few minutes of down time)

Commit 4d45fdf7 authored by Lars Hupel's avatar Lars Hupel
Browse files

Python 3 compatibility

--HG--
branch : depends-on
parent 8fd2fe1fe836
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# vim: set fileencoding=utf-8 : # vim: set fileencoding=utf-8 :
## ##
## Dependencies: Python 2.7 ## Dependencies: Python 2.7 or Python 3.5
## ##
## This script reads a metadata file and generates the topics.shtml, ## This script reads a metadata file and generates the topics.shtml,
## index.shtml and the entry pages on afp.sf.net. ## index.shtml and the entry pages on afp.sf.net.
...@@ -11,16 +11,24 @@ ...@@ -11,16 +11,24 @@
## For adding new entries see ../doc/editors/new-entry-checkin.html ## For adding new entries see ../doc/editors/new-entry-checkin.html
## ##
# Cross-python compatibility
from __future__ import print_function
try:
import configparser
except ImportError:
from six.moves import configparser
from collections import OrderedDict from collections import OrderedDict
from optparse import OptionParser from optparse import OptionParser
from sys import argv, stderr from sys import argv, stderr
from functools import partial from functools import partial
from operator import itemgetter
import codecs import codecs
import ConfigParser
import os import os
import re import re
from termcolor import colored from termcolor import colored
# global config # global config
### input templates ### input templates
...@@ -339,20 +347,20 @@ def debug(message, indent = 0, title = ""): ...@@ -339,20 +347,20 @@ def debug(message, indent = 0, title = ""):
debug("}", indent) debug("}", indent)
else: else:
if title: if title:
print >> stderr, (u"Debug: {0}{1}: {2}".format(' ' * indent, title, message)) print(u"Debug: {0}{1}: {2}".format(' ' * indent, title, message), file=stderr)
else: else:
print >> stderr, (u"Debug: {0}{1}".format(' ' * indent, message)) print(u"Debug: {0}{1}".format(' ' * indent, message), file=stderr)
def warn(message): def warn(message):
if options.enable_warnings: if options.enable_warnings:
print >> stderr, (colored(u"Warning: {0}".format(message), 'yellow', attrs=['bold'])) print(colored(u"Warning: {0}".format(message), 'yellow', attrs=['bold']), file=stderr)
def notice(message): def notice(message):
if options.enable_warnings: if options.enable_warnings:
print >> stderr, (u"Notice: {0}".format(message)) print(u"Notice: {0}".format(message), file=stderr)
def error(message, exception = None, abort = False): def error(message, exception = None, abort = False):
print >> stderr, (colored(u"Error: {0}".format(message), 'red', attrs=['bold'])) print(colored(u"Error: {0}".format(message), 'red', attrs=['bold']), file=stderr)
if exception: if exception:
error("*** exception message:") error("*** exception message:")
error(u"*** {0!s} {1!s}".format(exception, type(exception))) error(u"*** {0!s} {1!s}".format(exception, type(exception)))
...@@ -366,9 +374,9 @@ def check_fs(meta_entries, directory): ...@@ -366,9 +374,9 @@ def check_fs(meta_entries, directory):
meta_entries = set(k for k, _ in meta_entries.items()) meta_entries = set(k for k, _ in meta_entries.items())
# check for entries not existing in filesystem # check for entries not existing in filesystem
for fs_missing in meta_entries - fs_entries: for fs_missing in meta_entries - fs_entries:
print >> stderr, (colored(u"Check: In metadata: entry {0} doesn't exist in filesystem".format(fs_missing), 'yellow', attrs=['bold'])) print(colored(u"Check: In metadata: entry {0} doesn't exist in filesystem".format(fs_missing), 'yellow', attrs=['bold']), file=stderr)
for meta_missing in fs_entries - meta_entries: for meta_missing in fs_entries - meta_entries:
print >> stderr, (colored(u"Check: In filesystem: entry {0} doesn't exist in metadata".format(meta_missing), 'yellow', attrs=['bold'])) print(colored(u"Check: In filesystem: entry {0} doesn't exist in metadata".format(meta_missing), 'yellow', attrs=['bold']), file=stderr)
return len(fs_entries ^ meta_entries) return len(fs_entries ^ meta_entries)
# takes the 'raw' data from metadata file as input and performs: # takes the 'raw' data from metadata file as input and performs:
...@@ -425,7 +433,7 @@ def validate(entry, attributes): ...@@ -425,7 +433,7 @@ def validate(entry, attributes):
# reads the metadata file and returns a dict mapping each entry to the attributes # reads the metadata file and returns a dict mapping each entry to the attributes
# specified. one can rely upon that they conform to the attribute_schema # specified. one can rely upon that they conform to the attribute_schema
def parse(filename): def parse(filename):
parser = ConfigParser.RawConfigParser(dict_type = OrderedDict) parser = configparser.RawConfigParser(dict_type = OrderedDict)
try: try:
parser.readfp(codecs.open(filename, encoding='UTF-8', errors='strict')) parser.readfp(codecs.open(filename, encoding='UTF-8', errors='strict'))
return OrderedDict((sec, validate(sec, dict(parser.items(sec)))) for sec in parser.sections()) return OrderedDict((sec, validate(sec, dict(parser.items(sec)))) for sec in parser.sections())
...@@ -451,7 +459,7 @@ def read_versions(filename): ...@@ -451,7 +459,7 @@ def read_versions(filename):
error("Not processing releases") error("Not processing releases")
return [] return []
else: else:
versions.sort(None, lambda (v, d): d, True) versions.sort(key = itemgetter(1), reverse = True)
return versions return versions
# reads the list of entry releases (metadata/releases) # reads the list of entry releases (metadata/releases)
...@@ -533,7 +541,7 @@ def collect_years(entries): ...@@ -533,7 +541,7 @@ def collect_years(entries):
(attributes['date'] if attributes['date'] != '' else 'unknown', entry, attributes) (attributes['date'] if attributes['date'] != '' else 'unknown', entry, attributes)
for entry, attributes in entries for entry, attributes in entries
] ]
extracted.sort(None, lambda (y, e, a): y, True) extracted.sort(key = itemgetter(0), reverse = True)
years = OrderedDict() years = OrderedDict()
for date, entry, attributes in extracted: for date, entry, attributes in extracted:
key = date[0:4] if date != 'unknown' else date key = date[0:4] if date != 'unknown' else date
...@@ -601,14 +609,14 @@ def generate_author_list(authors, spacer, last_spacer, ignore_mail = True, ignor ...@@ -601,14 +609,14 @@ def generate_author_list(authors, spacer, last_spacer, ignore_mail = True, ignor
else: else:
return name return name
authors = map(_to_str, authors) authors = list(map(_to_str, authors))
if len(authors) == 0: if len(authors) == 0:
return "" return ""
elif len(authors) == 1: elif len(authors) == 1:
return authors[0] return authors[0]
else: else:
return u"{0}{1}{2}".format( return u"{0}{1}{2}".format(
spacer.join(authors[:len(authors)-1]), spacer.join(authors[:len(authors)-1]),
last_spacer, last_spacer,
authors[len(authors)-1] authors[len(authors)-1]
) )
...@@ -666,7 +674,9 @@ def format_entry_pre_text(title, text): ...@@ -666,7 +674,9 @@ def format_entry_pre_text(title, text):
) )
def depends_on_string(deps): def depends_on_string(deps):
return ', '.join(html_entry_link.format(dep, dep + ".shtml") for dep in deps) sorted_deps = list(deps)
sorted_deps.sort()
return ', '.join(html_entry_link.format(dep, dep + ".shtml") for dep in sorted_deps)
def format_depends_on(deps): def format_depends_on(deps):
if len(deps) == 0: if len(deps) == 0:
...@@ -720,7 +730,7 @@ def generate_entry(entry, attributes, param): ...@@ -720,7 +730,7 @@ def generate_entry(entry, attributes, param):
elif param == "older": elif param == "older":
if len(attributes['releases']) > 1: if len(attributes['releases']) > 1:
str = "" str = ""
for version, release_dates in attributes['releases'].items()[1:]: for version, release_dates in list(attributes['releases'].items())[1:]:
str += "".join(html_entry_older_release.format(version, release_date) for release_date in release_dates) str += "".join(html_entry_older_release.format(version, release_date) for release_date in release_dates)
result = html_entry_older_list.format(str) result = html_entry_older_list.format(str)
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment