]> git.lyx.org Git - lyx.git/blob - development/tools/updatedocs.py
Move Lexer to support/ directory (and lyx::support namespace)
[lyx.git] / development / tools / updatedocs.py
1 #! /usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 # file updatedocs.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7
8 # author Georg Baum
9
10 # Full author contact details are available in file CREDITS
11
12 # This script converts documentation .lyx files to current format
13 # The old files are backuped with extension ".old"
14
15
16 import os, re, string, sys, subprocess, shutil
17 from gen_lfuns import main as genlfuns
18
19
20 def convertdir(docdir, prefix, lyx2lyx, lyx, systemlyxdir):
21     olddir = os.getcwd()
22     os.chdir(docdir)
23     for i in os.listdir("."):
24         if os.path.isdir(i):
25             if i != 'attic':
26                 subdir = os.path.join(docdir, i)
27                 subprefix = os.path.join(prefix, i)
28                 convertdir(subdir, subprefix, lyx2lyx, lyx, systemlyxdir)
29             continue
30         (base, ext) = os.path.splitext(i)
31         if ext != ".lyx":
32             continue
33         old = i + ".old"
34         shutil.copy(i, old)
35         if sys.executable and sys.executable != '':
36             cmd = [sys.executable, lyx2lyx, old, '-s', systemlyxdir, '-o', i]
37         else:
38             # assume that python is in the path
39             cmd = [lyx2lyx, old, '-s', systemlyxdir, '-o', i]
40         sys.stderr.write('Converting %s\n' % os.path.join(prefix, i))
41         subprocess.call(cmd)
42         if lyx != '':
43             cmd = [lyx, '-f', '-x', 'command-sequence buffer-write force; lyx-quit', i]
44             subprocess.call(cmd)
45     os.chdir(olddir)
46
47
48 def main(argv):
49
50     toolsdir = os.path.dirname(argv[0])
51
52     # first generate LFUNs.lyx
53     lyxaction = os.path.abspath(os.path.join(toolsdir, "../../src/LyXAction.cpp"))
54     lfunspath = os.path.abspath(os.path.join(toolsdir, "../../lib/doc"))
55     lfuns = os.path.join(lfunspath, "LFUNs.lyx")
56     # genlfuns refuses to overwrite files
57     if os.path.exists(lfuns):
58         os.rename(lfuns, os.path.join(lfunspath, "LFUNs.lyx.old"))
59     # genlfuns requires a trailing slash
60     genlfuns(["genlfuns", lyxaction, lfunspath + os.sep])
61
62     # then update all docs
63     lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
64     systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
65     if len(argv) > 1:
66         sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
67         lyx = os.path.abspath(argv[1])
68     else:
69         lyx = ''
70     docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
71     for docpath in docpaths:
72         docdir = os.path.abspath(os.path.join(toolsdir, docpath))
73         convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
74
75     return 0
76
77
78 if __name__ == "__main__":
79     main(sys.argv)