2012-12-01 19:25:32 +05:30
|
|
|
#! /usr/bin/env python
|
|
|
|
#
|
|
|
|
# update_po - a gramps tool to update translations
|
|
|
|
#
|
|
|
|
# Copyright (C) 2006-2006 Kees Bakker
|
|
|
|
# Copyright (C) 2006 Brian Matherly
|
|
|
|
# Copyright (C) 2008 Stephen George
|
|
|
|
# Copyright (C) 2012
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2014-08-09 07:59:07 +05:30
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-12-01 19:25:32 +05:30
|
|
|
|
|
|
|
"""
|
2012-12-01 19:34:51 +05:30
|
|
|
update_man.py for command line documentation.
|
2012-12-01 19:25:32 +05:30
|
|
|
|
2016-05-18 15:17:34 +05:30
|
|
|
Examples:
|
2012-12-01 19:25:32 +05:30
|
|
|
python update_man.py -t
|
|
|
|
|
|
|
|
Tests if 'sphinx' and 'python' are well configured.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
2012-12-04 00:18:03 +05:30
|
|
|
DOCUTILS = True
|
|
|
|
try:
|
|
|
|
import docutils.core, docutils.writers
|
|
|
|
except:
|
|
|
|
DOCUTILS = False
|
|
|
|
|
2012-12-01 21:32:41 +05:30
|
|
|
LANGUAGES = ['sv', 'nl', 'pl', 'cs', 'pt_BR', 'fr']
|
2015-09-01 04:27:26 +05:30
|
|
|
VERSION = '5.0.0'
|
2012-12-01 19:25:32 +05:30
|
|
|
DATE = ''
|
|
|
|
|
|
|
|
# You can set these variables from the command line.
|
|
|
|
SPHINXBUILD = 'sphinx-build'
|
|
|
|
|
2016-05-18 15:17:34 +05:30
|
|
|
if sys.platform == 'win32':
|
2012-12-01 19:25:32 +05:30
|
|
|
pythonCmd = os.path.join(sys.prefix, 'bin', 'python.exe')
|
|
|
|
sphinxCmd = os.path.join(sys.prefix, 'bin', 'sphinx-build.exe')
|
2013-01-21 01:05:35 +05:30
|
|
|
elif sys.platform in ['linux2', 'darwin', 'cygwin']:
|
2012-12-01 19:25:32 +05:30
|
|
|
pythonCmd = os.path.join(sys.prefix, 'bin', 'python')
|
|
|
|
sphinxCmd = SPHINXBUILD
|
|
|
|
else:
|
2013-01-21 01:05:35 +05:30
|
|
|
print ("Update Man ERROR: unknown system, don't know sphinx, ... commands")
|
2012-12-01 19:25:32 +05:30
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def tests():
|
|
|
|
"""
|
|
|
|
Testing installed programs.
|
|
|
|
We made tests (-t flag) by displaying versions of tools if properly
|
|
|
|
installed. Cannot run all commands without 'sphinx' and 'python'.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
print("\n=================='python'=============================\n")
|
|
|
|
os.system('''%(program)s -V''' % {'program': pythonCmd})
|
|
|
|
except:
|
|
|
|
print ('Please, install python')
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
try:
|
2015-09-01 04:27:26 +05:30
|
|
|
print("\n=================='Sphinx-build'=============================\n")
|
2012-12-01 19:25:32 +05:30
|
|
|
os.system('''%(program)s''' % {'program': sphinxCmd})
|
|
|
|
except:
|
|
|
|
print ('Please, install sphinx')
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-04 00:18:03 +05:30
|
|
|
if not DOCUTILS:
|
|
|
|
print('\nNo docutils support, cannot use -m/--man and -o/--odt arguments.')
|
2012-12-01 19:25:32 +05:30
|
|
|
|
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
The utility for handling documentation stuff.
|
|
|
|
What is need by Gramps, nothing more.
|
|
|
|
"""
|
2016-05-18 15:17:34 +05:30
|
|
|
|
|
|
|
parser = ArgumentParser(
|
|
|
|
description='This program aims to handle documentation'
|
|
|
|
' and related translated versions.',
|
2012-12-01 19:25:32 +05:30
|
|
|
)
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
parser.add_argument("-t", "--test",
|
|
|
|
action="store_true", dest="test", default=True,
|
|
|
|
help="test if 'python' and 'sphinx' are properly installed")
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
parser.add_argument("-b", "--build",
|
2012-12-03 23:49:39 +05:30
|
|
|
action="store_true", dest="build", default=False,
|
|
|
|
help="build man documentation (via sphinx-build)")
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-03 23:49:39 +05:30
|
|
|
parser.add_argument("-m", "--man",
|
|
|
|
action="store_true", dest="man", default=False,
|
|
|
|
help="build man documentation (via docutils)")
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-03 23:49:39 +05:30
|
|
|
parser.add_argument("-o", "--odt",
|
|
|
|
action="store_true", dest="odt", default=False,
|
|
|
|
help="build odt documentation (via docutils)")
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
args = parser.parse_args()
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
if args.test:
|
|
|
|
tests()
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
if args.build:
|
|
|
|
build()
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-04 00:18:03 +05:30
|
|
|
if args.man and DOCUTILS:
|
2012-12-03 23:49:39 +05:30
|
|
|
man()
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-04 00:18:03 +05:30
|
|
|
if args.odt and DOCUTILS:
|
2012-12-03 23:49:39 +05:30
|
|
|
odt()
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
def build():
|
|
|
|
"""
|
|
|
|
Build documentation.
|
|
|
|
"""
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
# testing stage
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
os.system('''%(program)s -b html . _build/html''' % {'program': sphinxCmd})
|
|
|
|
os.system('''%(program)s -b htmlhelp . _build/htmlhelp''' % {'program': sphinxCmd})
|
2012-12-04 14:21:01 +05:30
|
|
|
if DOCUTILS:
|
|
|
|
os.system('''%(program)s -b man . .''' % {'program': sphinxCmd})
|
2012-12-01 19:25:32 +05:30
|
|
|
os.system('''%(program)s -b text . _build/text''' % {'program': sphinxCmd})
|
|
|
|
os.system('''%(program)s -b changes . _build/changes''' % {'program': sphinxCmd})
|
2012-12-02 17:09:49 +05:30
|
|
|
#os.system('''%(program)s -b linkcheck . _build/linkcheck''' % {'program': sphinxCmd})
|
2012-12-01 19:25:32 +05:30
|
|
|
os.system('''%(program)s -b gettext . _build/gettext''' % {'program': sphinxCmd})
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 21:32:41 +05:30
|
|
|
for lang in LANGUAGES:
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''%(program)s -b html -D language="%(lang)s" master_doc="%(lang)s" %(lang)s %(lang)s'''
|
2012-12-01 21:32:41 +05:30
|
|
|
% {'lang': lang, 'program': sphinxCmd})
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''%(program)s -b htmlhelp -D language="%(lang)s" master_doc="%(lang)s" %(lang)s %(lang)s'''
|
2012-12-01 21:32:41 +05:30
|
|
|
% {'lang': lang, 'program': sphinxCmd})
|
2012-12-04 14:21:01 +05:30
|
|
|
if DOCUTILS:
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''%(program)s -b man %(lang)s %(lang)s'''
|
2012-12-04 14:21:01 +05:30
|
|
|
% {'lang': lang, 'program': sphinxCmd})
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''%(program)s -b text -D language="%(lang)s" master_doc="%(lang)s" %(lang)s %(lang)s'''
|
2012-12-01 21:32:41 +05:30
|
|
|
% {'lang': lang, 'program': sphinxCmd})
|
|
|
|
# for update/migration
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''%(program)s -b gettext -D language="%(lang)s" master_doc="%(lang)s" . _build/gettext/%(lang)s'''
|
2012-12-01 21:32:41 +05:30
|
|
|
% {'lang': lang, 'program': sphinxCmd})
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-03 23:49:39 +05:30
|
|
|
def man():
|
|
|
|
"""
|
|
|
|
man file generation via docutils (python)
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-04 00:18:03 +05:30
|
|
|
from docutils.core import publish_cmdline, default_description
|
|
|
|
from docutils.writers import manpage
|
2012-12-03 23:49:39 +05:30
|
|
|
"""
|
2016-05-18 15:17:34 +05:30
|
|
|
|
|
|
|
os.system('''rst2man en.rst gramps.1''')
|
|
|
|
|
2012-12-03 23:49:39 +05:30
|
|
|
for lang in LANGUAGES:
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''rst2man %(lang)s/%(lang)s.rst -l %(lang)s %(lang)s/gramps.1'''
|
2012-12-03 23:49:39 +05:30
|
|
|
% {'lang': lang})
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-03 23:49:39 +05:30
|
|
|
def odt():
|
|
|
|
"""
|
|
|
|
odt file generation via docutils (python)
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-04 00:18:03 +05:30
|
|
|
from docutils.core import publish_cmdline_to_binary, default_description
|
|
|
|
from docutils.writers.odf_odt import Writer, Reader
|
2012-12-03 23:49:39 +05:30
|
|
|
"""
|
2016-05-18 15:17:34 +05:30
|
|
|
|
|
|
|
os.system('''rst2odt en.rst gramps.odt''')
|
|
|
|
|
2012-12-03 23:49:39 +05:30
|
|
|
for lang in LANGUAGES:
|
2016-05-18 15:17:34 +05:30
|
|
|
os.system('''rst2odt %(lang)s/%(lang)s.rst -l %(lang)s %(lang)s/gramps.odt'''
|
2012-12-03 23:49:39 +05:30
|
|
|
% {'lang': lang})
|
2016-05-18 15:17:34 +05:30
|
|
|
|
2012-12-01 19:25:32 +05:30
|
|
|
if __name__ == "__main__":
|
2016-01-01 02:47:35 +05:30
|
|
|
main()
|