Skip to content

Commit

Permalink
python3 migration: docbook-manual.py
Browse files Browse the repository at this point in the history
Fixes #27384
  • Loading branch information
dregad committed Oct 8, 2020
1 parent 03a4c93 commit 58b2356
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions build/docbook-manual.py
@@ -1,4 +1,4 @@
#!/usr/bin/python -u
#!/usr/bin/python3 -u

import errno
import getopt
Expand Down Expand Up @@ -29,7 +29,7 @@


def usage():
print '''Usage: docbook-manual /path/to/mantisbt/docbook /path/to/install \
print('''Usage: {} /path/to/mantisbt/docbook /path/to/install \
[<lang> ...]
Options: -h | --help Print this usage message
-d | --delete Delete install directory before building
Expand All @@ -39,15 +39,16 @@ def usage():
--txt Build TXT manual
--release Build single file types used for
release tarballs
-a | --all Build all manual types'''
-a | --all Build all manual types
'''.format(path.basename(__file__)))
# end usage()


def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options)
except getopt.GetoptError, err:
print str(err)
except getopt.GetoptError as err:
print(err)
usage()
sys.exit(2)

Expand Down Expand Up @@ -100,7 +101,7 @@ def main():
os.chdir(docroot)

if delete and installroot != "/" and path.isdir(installroot):
print "Deleting install directory " + installroot
print("Deleting install directory " + installroot)
for root, dirs, files in os.walk(installroot, topdown=False):
for name in files:
os.remove(path.join(root, name))
Expand All @@ -110,7 +111,7 @@ def main():
buildcount = 0

# Process all existing manuals
for dir in os.walk(docroot).next()[1]:
for dir in next(os.walk(docroot))[1]:
if dir == '.svn' or dir == 'template' or dir == 'erd':
continue

Expand All @@ -121,7 +122,7 @@ def main():
if len(languages) > 0:
langs = languages
else:
langs = os.walk(builddir).next()[1]
langs = next(os.walk(builddir))[1]
if langs.count('.svn'):
langs.remove('.svn')
if langs.count('tmp'):
Expand All @@ -130,13 +131,12 @@ def main():
if path.exists('publican.cfg'):
# Build docbook with PUBLICAN

print "Building manual in '%s'\n" % builddir
print("Building manual in '{}'\n".format(builddir))
os.system('publican clean')
os.system('publican build --formats=%s --langs=%s' % (
types[PUBLICAN], ','.join(langs))
)
os.system('publican build --formats={} --langs={}'.format(
types[PUBLICAN], ','.join(langs)))

print "\nCopying generated manuals to '%s'" % installroot
print("\nCopying generated manuals to '{}'".format(installroot))
for lang in langs:
builddir = path.join('tmp', lang)
installdir = path.join(installroot, lang, dir)
Expand All @@ -152,14 +152,14 @@ def main():
# Copy HTML manuals with rsync
source = path.join(builddir, 'html*')
if len(glob.glob(source)) > 0:
rsync = "rsync -a --delete %s %s" % (
rsync = "rsync -a --delete {} {}".format(
source, installdir
)
print rsync
print(rsync)
ret = subprocess.call(rsync, shell=True)
if ret != 0:
print 'ERROR: rsync call failed with exit code ' % \
ret
print('ERROR: rsync call failed with exit code '
.format(ret))

# Copy single file manuals (PDF, TXT and EPUB)
for filetype in ['epub', 'pdf', 'txt']:
Expand All @@ -169,20 +169,19 @@ def main():
source = path.join(builddir, filetype, '*' + filetype)
dest = path.join(installdir, dir + '.' + filetype)
for sourcefile in glob.glob(source):
print "Copying '%s' to '%s'" % (sourcefile, dest)
print("Copying '{}' to '{}'".format(sourcefile, dest))
shutil.copy2(sourcefile, dest)

os.system('publican clean')
print "\nBuild complete\n"
print("\nBuild complete\n")
buildcount += len(langs)
else:
# Build docbook with MAKE

for lang in langs:
if not path.isdir(path.join(builddir, lang)):
print "WARNING: Unknown language '%s' in '%s'" % (
lang, builddir
)
print("WARNING: Unknown language '{}' in '{}'"
.format(lang, builddir))
continue

builddir = path.join(builddir, lang)
Expand All @@ -192,19 +191,19 @@ def main():
if not path.exists('Makefile'):
continue

print "Building manual in '%s'\n" % builddir
print("Building manual in '%s'\n".format(builddir))
os.system(
'make clean %s 2>&1 && '
'make INSTALL_DIR=%s install 2>&1' %
(types[MAKE], installdir)
'make clean {} 2>&1 && '
'make INSTALL_DIR={} install 2>&1'
.format(types[MAKE], installdir)
)
os.system('make clean 2>&1')
print "\nBuild complete\n"
print("\nBuild complete\n")
buildcount += 1

# end docbook build loop

print "Done - %s docbooks built.\n" % buildcount
print("Done - {} docbooks built.\n".format(buildcount))

# end main()

Expand Down

0 comments on commit 58b2356

Please sign in to comment.