From 97ce776e7ba68d1966fddba475b11e85a6c53420 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 29 Jul 2019 04:43:28 +0200 Subject: scripts: autopep8 --- scripts/gen_help_html.py | 156 ++++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 69 deletions(-) (limited to 'scripts/gen_help_html.py') diff --git a/scripts/gen_help_html.py b/scripts/gen_help_html.py index dbdeb3c162..a319cde64e 100644 --- a/scripts/gen_help_html.py +++ b/scripts/gen_help_html.py @@ -81,8 +81,8 @@ SITENAVI_PLAIN = '

' + SITENAVI_LINKS_PLAIN + '

' SITENAVI_WEB = '

' + SITENAVI_LINKS_WEB + '

' SITENAVI_SEARCH = '
' + SITENAVI_LINKS_WEB + \ -'
' + '
' TEXTSTART = """
@@ -100,74 +100,76 @@ FOOTER2 = """ """.format( - generated_date='{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()), - commit='?') + generated_date='{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()), + commit='?') RE_TAGLINE = re.compile(r'(\S+)\s+(\S+)') PAT_WORDCHAR = '[!#-)+-{}~\xC0-\xFF]' -PAT_HEADER = r'(^.*~$)' -PAT_GRAPHIC = r'(^.* `$)' +PAT_HEADER = r'(^.*~$)' +PAT_GRAPHIC = r'(^.* `$)' PAT_PIPEWORD = r'(?|.)?)' -PAT_SPECIAL = r'(<.+?>|\{.+?}|' \ - r'\[(?:range|line|count|offset|\+?cmd|[-+]?num|\+\+opt|' \ - r'arg|arguments|ident|addr|group)]|' \ - r'(?<=\s)\[[-a-z^A-Z0-9_]{2,}])' -PAT_TITLE = r'(Vim version [0-9.a-z]+|VIM REFERENCE.*)' -PAT_NOTE = r'((? \t]+[a-zA-Z0-9/])' -PAT_WORD = r'((?|.)?)' +PAT_SPECIAL = r'(<.+?>|\{.+?}|' \ + r'\[(?:range|line|count|offset|\+?cmd|[-+]?num|\+\+opt|' \ + r'arg|arguments|ident|addr|group)]|' \ + r'(?<=\s)\[[-a-z^A-Z0-9_]{2,}])' +PAT_TITLE = r'(Vim version [0-9.a-z]+|VIM REFERENCE.*)' +PAT_NOTE = r'((? \t]+[a-zA-Z0-9/])' +PAT_WORD = r'((?$') -RE_EG_END = re.compile(r'\S') -RE_SECTION = re.compile(r'[-A-Z .][-A-Z0-9 .()]*(?=\s+\*)') -RE_STARTAG = re.compile(r'\s\*([^ \t|]+)\*(?:\s|$)') +RE_HRULE = re.compile(r'[-=]{3,}.*[-=]{3,3}$') +RE_EG_START = re.compile(r'(?:.* )?>$') +RE_EG_END = re.compile(r'\S') +RE_SECTION = re.compile(r'[-A-Z .][-A-Z0-9 .()]*(?=\s+\*)') +RE_STARTAG = re.compile(r'\s\*([^ \t|]+)\*(?:\s|$)') RE_LOCAL_ADD = re.compile(r'LOCAL ADDITIONS:\s+\*local-additions\*$') + class Link(object): __slots__ = 'link_plain_same', 'link_pipe_same', \ 'link_plain_foreign', 'link_pipe_foreign', \ 'filename' def __init__(self, link_plain_same, link_plain_foreign, - link_pipe_same, link_pipe_foreign, filename): - self.link_plain_same = link_plain_same + link_pipe_same, link_pipe_foreign, filename): + self.link_plain_same = link_plain_same self.link_plain_foreign = link_plain_foreign - self.link_pipe_same = link_pipe_same - self.link_pipe_foreign = link_pipe_foreign - self.filename = filename + self.link_pipe_same = link_pipe_same + self.link_pipe_foreign = link_pipe_foreign + self.filename = filename + class VimH2H(object): def __init__(self, tags, version=None, is_web_version=True): - self._urls = { } + self._urls = {} self._version = version self._is_web_version = is_web_version for line in RE_NEWLINE.split(tags): @@ -183,6 +185,7 @@ class VimH2H(object): def do_add_tag(self, filename, tag): tag_quoted = urllib.parse.quote_plus(tag) + def mkpart1(doc): return '' + html_escape[tag] + '' + def mklinks(cssclass): - return (part1_same + cssclass + part2, + return (part1_same + cssclass + part2, part1_foreign + cssclass + part2) cssclass_plain = 'd' m = RE_LINKWORD.match(tag) if m: opt, ctrl, special = m.groups() - if opt is not None: cssclass_plain = 'o' - elif ctrl is not None: cssclass_plain = 'k' - elif special is not None: cssclass_plain = 's' + if opt is not None: + cssclass_plain = 'o' + elif ctrl is not None: + cssclass_plain = 'k' + elif special is not None: + cssclass_plain = 's' links_plain = mklinks(cssclass_plain) links_pipe = mklinks('l') self._urls[tag] = Link( @@ -213,18 +220,23 @@ class VimH2H(object): links = self._urls.get(tag) if links is not None: if links.filename == curr_filename: - if css_class == 'l': return links.link_pipe_same - else: return links.link_plain_same + if css_class == 'l': + return links.link_pipe_same + else: + return links.link_plain_same else: - if css_class == 'l': return links.link_pipe_foreign - else: return links.link_plain_foreign + if css_class == 'l': + return links.link_pipe_foreign + else: + return links.link_plain_foreign elif css_class is not None: return '' + html_escape[tag] + \ - '' - else: return html_escape[tag] + '' + else: + return html_escape[tag] def to_html(self, filename, contents, encoding): - out = [ ] + out = [] inexample = 0 filename = str(filename) @@ -247,10 +259,11 @@ class VimH2H(object): if inexample == 2: if RE_EG_END.match(line): inexample = 0 - if line[0] == '<': line = line[1:] + if line[0] == '<': + line = line[1:] else: out.extend(('', html_escape[line], - '\n')) + '\n')) continue if RE_EG_START.match(line_tabs): inexample = 1 @@ -266,12 +279,12 @@ class VimH2H(object): out.append(html_escape[line[lastpos:pos]]) lastpos = match.end() header, graphic, pipeword, starword, command, opt, ctrl, \ - special, title, note, url, word = match.groups() + special, title, note, url, word = match.groups() if pipeword is not None: out.append(self.maplink(pipeword, filename, 'l')) elif starword is not None: out.extend(('', html_escape[starword], '')) + '" class="t">', html_escape[starword], '')) elif command is not None: out.extend(('', html_escape[command], '')) @@ -300,14 +313,15 @@ class VimH2H(object): if lastpos < len(line): out.append(html_escape[line[lastpos:]]) out.append('\n') - if inexample == 1: inexample = 2 + if inexample == 1: + inexample = 2 header = [] header.append(HEAD.format(encoding=encoding, filename=filename)) header.append(HEAD_END) if self._is_web_version and is_help_txt: vers_note = VERSION_NOTE.replace('{version}', self._version) \ - if self._version else '' + if self._version else '' header.append(INTRO.replace('{vers-note}', vers_note)) if self._is_web_version: header.append(SITENAVI_SEARCH) @@ -318,6 +332,7 @@ class VimH2H(object): header.append(TEXTSTART) return ''.join(chain(header, out, (FOOTER, sitenavi_footer, FOOTER2))) + class HtmlEscCache(dict): def __missing__(self, key): r = key.replace('&', '&') \ @@ -326,9 +341,8 @@ class HtmlEscCache(dict): self[key] = r return r -html_escape = HtmlEscCache() - +html_escape = HtmlEscCache() def slurp(filename): @@ -340,17 +354,20 @@ def slurp(filename): with open(filename, encoding='latin-1') as f: return f.read(), 'latin-1' + def usage(): return "usage: " + sys.argv[0] + " IN_DIR OUT_DIR [BASENAMES...]" + def main(): - if len(sys.argv) < 3: sys.exit(usage()) + if len(sys.argv) < 3: + sys.exit(usage()) in_dir = sys.argv[1] out_dir = sys.argv[2] basenames = sys.argv[3:] - print( "Processing tags...") + print("Processing tags...") h2h = VimH2H(slurp(os.path.join(in_dir, 'tags'))[0], is_web_version=False) if len(basenames) == 0: @@ -358,9 +375,9 @@ def main(): for basename in basenames: if os.path.splitext(basename)[1] != '.txt' and basename != 'tags': - print( "Ignoring " + basename) + print("Ignoring " + basename) continue - print( "Processing " + basename + "...") + print("Processing " + basename + "...") path = os.path.join(in_dir, basename) text, encoding = slurp(path) outpath = os.path.join(out_dir, basename + '.html') @@ -368,4 +385,5 @@ def main(): of.write(h2h.to_html(basename, text, encoding)) of.close() + main() -- cgit