Fixed stitch_text on Python 2

This commit is contained in:
Daniele Varrazzo 2018-01-10 22:49:00 +00:00
parent bad9b8b383
commit 04f1f06b9f

View File

@ -5,6 +5,7 @@
import os import os
import sys import sys
def main(): def main():
if len(sys.argv) != 3: if len(sys.argv) != 3:
sys.stderr.write("usage: %s index.rst text-dir\n") sys.stderr.write("usage: %s index.rst text-dir\n")
@ -17,20 +18,20 @@ def main():
return 0 return 0
def iter_file_base(fn): def iter_file_base(fn):
f = open(fn) f = open(fn)
have_line = iter(f).__next__
while not have_line().startswith('.. toctree'): while not next(f).startswith('.. toctree'):
pass pass
while have_line().strip().startswith(':'): while next(f).strip().startswith(':'):
pass pass
yield os.path.splitext(os.path.basename(fn))[0] yield os.path.splitext(os.path.basename(fn))[0]
n = 0 n = 0
while True: while True:
line = have_line() line = next(f)
if line.isspace(): if line.isspace():
continue continue
if line.startswith(".."): if line.startswith(".."):
@ -44,6 +45,7 @@ def iter_file_base(fn):
# maybe format changed? # maybe format changed?
raise Exception("Not enough files found. Format change in index.rst?") raise Exception("Not enough files found. Format change in index.rst?")
def emit(basename, txt_dir): def emit(basename, txt_dir):
f = open(os.path.join(txt_dir, basename + ".txt")) f = open(os.path.join(txt_dir, basename + ".txt"))
for line in f: for line in f: