mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Create a setup.py command: man_pages to generate man pages in all languages
This commit is contained in:
parent
5d9a4aee9d
commit
fa191ab55a
@ -17,6 +17,8 @@ import sys, os, subprocess, shutil
|
|||||||
SPHINX_BUILD = 'sphinx-build2'
|
SPHINX_BUILD = 'sphinx-build2'
|
||||||
|
|
||||||
j, d, a = os.path.join, os.path.dirname, os.path.abspath
|
j, d, a = os.path.join, os.path.dirname, os.path.abspath
|
||||||
|
BASE = d(a(__file__))
|
||||||
|
|
||||||
|
|
||||||
def sphinx_build(language, base, builder='html', bdir='html', t=None, quiet=True):
|
def sphinx_build(language, base, builder='html', bdir='html', t=None, quiet=True):
|
||||||
destdir = j(base, bdir)
|
destdir = j(base, bdir)
|
||||||
@ -29,11 +31,12 @@ def sphinx_build(language, base, builder='html', bdir='html', t=None, quiet=True
|
|||||||
ans += ['-w', j(destdir, 'sphinx-build-warnings.txt')]
|
ans += ['-w', j(destdir, 'sphinx-build-warnings.txt')]
|
||||||
if t:
|
if t:
|
||||||
ans += ['-t', t]
|
ans += ['-t', t]
|
||||||
ans += ['-d', j(base, 'doctrees'), '.', destdir]
|
ans += ['-d', j(base, 'doctrees'), BASE, destdir]
|
||||||
print(' '.join(ans))
|
print(' '.join(ans))
|
||||||
subprocess.check_call(ans)
|
subprocess.check_call(ans)
|
||||||
return destdir
|
return destdir
|
||||||
|
|
||||||
|
|
||||||
def build_manual(language, base):
|
def build_manual(language, base):
|
||||||
sb = partial(sphinx_build, language, base)
|
sb = partial(sphinx_build, language, base)
|
||||||
onlinedir = sb(t='online')
|
onlinedir = sb(t='online')
|
||||||
@ -41,6 +44,7 @@ def build_manual(language, base):
|
|||||||
latexdir = sb('mylatex', 'latex')
|
latexdir = sb('mylatex', 'latex')
|
||||||
pwd = os.getcwdu()
|
pwd = os.getcwdu()
|
||||||
os.chdir(latexdir)
|
os.chdir(latexdir)
|
||||||
|
|
||||||
def run_cmd(cmd):
|
def run_cmd(cmd):
|
||||||
p = subprocess.Popen(cmd, stdout=open(os.devnull, 'wb'), stdin=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=open(os.devnull, 'wb'), stdin=subprocess.PIPE)
|
||||||
p.stdin.close()
|
p.stdin.close()
|
||||||
@ -63,6 +67,7 @@ def build_manual(language, base):
|
|||||||
from calibre.ebooks.oeb.polish.container import epub_to_azw3
|
from calibre.ebooks.oeb.polish.container import epub_to_azw3
|
||||||
epub_to_azw3(epub_dest)
|
epub_to_azw3(epub_dest)
|
||||||
|
|
||||||
|
|
||||||
def build_pot(base):
|
def build_pot(base):
|
||||||
cmd = [SPHINX_BUILD, '-b', 'gettext', '-t', 'online', '-t', 'gettext', '.', base]
|
cmd = [SPHINX_BUILD, '-b', 'gettext', '-t', 'online', '-t', 'gettext', '.', base]
|
||||||
print (' '.join(cmd))
|
print (' '.join(cmd))
|
||||||
@ -70,7 +75,13 @@ def build_pot(base):
|
|||||||
os.remove(j(base, 'generated.pot'))
|
os.remove(j(base, 'generated.pot'))
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
|
||||||
|
def build_man_pages(language, base):
|
||||||
|
sphinx_build(language, base, builder='man', bdir=language)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
import argparse
|
||||||
os.chdir(d(a(__file__)))
|
os.chdir(d(a(__file__)))
|
||||||
os.environ['__appname__'] = __appname__
|
os.environ['__appname__'] = __appname__
|
||||||
os.environ['__version__'] = __version__
|
os.environ['__version__'] = __version__
|
||||||
@ -81,12 +92,20 @@ if __name__ == '__main__':
|
|||||||
import json
|
import json
|
||||||
os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(json.load(open('locale/completed.json', 'rb')))
|
os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(json.load(open('locale/completed.json', 'rb')))
|
||||||
sphinx_build(language, base, t='online', quiet=False)
|
sphinx_build(language, base, t='online', quiet=False)
|
||||||
|
print ('Manual built in', j(base, 'html'))
|
||||||
else:
|
else:
|
||||||
language, base = sys.argv[1:]
|
p = argparse.ArgumentParser()
|
||||||
|
p.add_argument('language', help='The language to build for')
|
||||||
|
p.add_argument('base', help='The destination directory')
|
||||||
|
p.add_argument('--man-pages', default=False, action='store_true', help='Build man pages')
|
||||||
|
args = p.parse_args()
|
||||||
|
language, base = args.language, args.base
|
||||||
if language == 'gettext':
|
if language == 'gettext':
|
||||||
build_pot(base)
|
build_pot(base)
|
||||||
|
elif args.man_pages:
|
||||||
|
os.environ['CALIBRE_OVERRIDE_LANG'] = language
|
||||||
|
build_man_pages(language, base)
|
||||||
else:
|
else:
|
||||||
os.environ['CALIBRE_OVERRIDE_LANG'] = language
|
os.environ['CALIBRE_OVERRIDE_LANG'] = language
|
||||||
build_manual(language, base)
|
build_manual(language, base)
|
||||||
if language != 'gettext':
|
print ('Manual for', language, 'built in', j(base, 'html'))
|
||||||
print ('Manual for', language, 'built in', j(base, 'html'))
|
|
||||||
|
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'pot', 'translations', 'get_translations', 'iso639', 'iso3166',
|
'pot', 'translations', 'get_translations', 'iso639', 'iso3166',
|
||||||
'build', 'mathjax',
|
'build', 'mathjax', 'man_pages',
|
||||||
'gui',
|
'gui',
|
||||||
'develop', 'install',
|
'develop', 'install',
|
||||||
'kakasi', 'coffee', 'rapydscript', 'cacerts', 'recent_uas', 'resources',
|
'kakasi', 'coffee', 'rapydscript', 'cacerts', 'recent_uas', 'resources',
|
||||||
@ -64,7 +64,7 @@ recent_uas = RecentUAs()
|
|||||||
rapydscript = RapydScript()
|
rapydscript = RapydScript()
|
||||||
|
|
||||||
from setup.publish import Manual, TagRelease, Stage1, Stage2, \
|
from setup.publish import Manual, TagRelease, Stage1, Stage2, \
|
||||||
Stage3, Stage4, Stage5, Publish, PublishBetas
|
Stage3, Stage4, Stage5, Publish, PublishBetas, ManPages
|
||||||
manual = Manual()
|
manual = Manual()
|
||||||
tag_release = TagRelease()
|
tag_release = TagRelease()
|
||||||
stage1 = Stage1()
|
stage1 = Stage1()
|
||||||
@ -74,6 +74,7 @@ stage4 = Stage4()
|
|||||||
stage5 = Stage5()
|
stage5 = Stage5()
|
||||||
publish = Publish()
|
publish = Publish()
|
||||||
publish_betas = PublishBetas()
|
publish_betas = PublishBetas()
|
||||||
|
man_pages = ManPages()
|
||||||
|
|
||||||
from setup.upload import (UploadUserManual, UploadDemo, UploadInstallers,
|
from setup.upload import (UploadUserManual, UploadDemo, UploadInstallers,
|
||||||
UploadToServer, ReUpload)
|
UploadToServer, ReUpload)
|
||||||
|
@ -271,6 +271,65 @@ class Manual(Command):
|
|||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
|
||||||
|
|
||||||
|
class ManPages(Command):
|
||||||
|
|
||||||
|
description = '''Build the man pages '''
|
||||||
|
|
||||||
|
def add_options(self, parser):
|
||||||
|
parser.add_option('--man-dir', help='Where to generate the man pages')
|
||||||
|
parser.add_option('--compress-man-pages', default=False, action='store_true', help='Compress the generated man pages')
|
||||||
|
|
||||||
|
def run(self, opts):
|
||||||
|
self.build_man_pages(opts.man_dir or 'man-pages', opts.compress_man_pages)
|
||||||
|
|
||||||
|
def build_man_pages(self, dest, compress=False):
|
||||||
|
dest = os.path.abspath(dest)
|
||||||
|
if os.path.exists(dest):
|
||||||
|
shutil.rmtree(dest)
|
||||||
|
os.makedirs(dest)
|
||||||
|
self.info('\tCreating man pages in {}...'.format(dest))
|
||||||
|
base = self.j(self.d(self.SRC), 'manual')
|
||||||
|
languages = list(
|
||||||
|
json.load(open(self.j(base, 'locale', 'completed.json'), 'rb'))
|
||||||
|
)
|
||||||
|
languages = ['en'] + list(set(languages) - {'en'})
|
||||||
|
os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(languages)
|
||||||
|
try:
|
||||||
|
os.makedirs(dest)
|
||||||
|
except EnvironmentError:
|
||||||
|
pass
|
||||||
|
jobs = []
|
||||||
|
for l in languages:
|
||||||
|
jobs.append((
|
||||||
|
['calibre-debug', self.j(base, 'build.py'), '--', '--man-pages', l, dest],
|
||||||
|
'\n\n**************** Building translations for: %s' % l)
|
||||||
|
)
|
||||||
|
if not parallel_build(jobs, self.info, verbose=False):
|
||||||
|
raise SystemExit(1)
|
||||||
|
shutil.rmtree(self.j(dest, 'doctrees'))
|
||||||
|
cwd = os.getcwdu()
|
||||||
|
os.chdir(dest)
|
||||||
|
try:
|
||||||
|
for x in os.listdir('.'):
|
||||||
|
if x == 'en':
|
||||||
|
os.rename(x, 'man1')
|
||||||
|
else:
|
||||||
|
os.mkdir(self.j(x, 'man1'))
|
||||||
|
for y in os.listdir(x):
|
||||||
|
if y != 'man1':
|
||||||
|
os.rename(self.j(x, y), self.j(x, 'man1', y))
|
||||||
|
if compress:
|
||||||
|
jobs = []
|
||||||
|
for dirpath, dirnames, filenames in os.walk('.'):
|
||||||
|
for f in filenames:
|
||||||
|
if f.endswith('.1'):
|
||||||
|
jobs.append((['gzip', '--best', self.j(dirpath, f)], ''))
|
||||||
|
if not parallel_build(jobs, self.info, verbose=False):
|
||||||
|
raise SystemExit(1)
|
||||||
|
finally:
|
||||||
|
os.chdir(cwd)
|
||||||
|
|
||||||
|
|
||||||
class TagRelease(Command):
|
class TagRelease(Command):
|
||||||
|
|
||||||
description = 'Tag a new release in git'
|
description = 'Tag a new release in git'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user