]> git.lyx.org Git - lyx.git/blob - development/tools/updatedocs.py
Cmake export tests: doc/ja/EmbeddedObjects.lyx compilable again
[lyx.git] / development / tools / updatedocs.py
1 #! /usr/bin/env python
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
18
19 def convertdir(docdir, prefix, lyx2lyx, lyx, systemlyxdir):
20     olddir = os.getcwd()
21     os.chdir(docdir)
22     for i in os.listdir("."):
23         if os.path.isdir(i):
24             if i != 'attic':
25                 subdir = os.path.join(docdir, i)
26                 subprefix = os.path.join(prefix, i)
27                 convertdir(subdir, subprefix, lyx2lyx, lyx, systemlyxdir)
28             continue
29         (base, ext) = os.path.splitext(i)
30         if ext != ".lyx":
31             continue
32         old = i + ".old"
33         shutil.copy(i, old)
34         if sys.executable and sys.executable != '':
35             cmd = [sys.executable, lyx2lyx, old, '-s', systemlyxdir, '-o', i]
36         else:
37             # assume that python is in the path
38             cmd = [lyx2lyx, old, '-s', systemlyxdir, '-o', i]
39         sys.stderr.write('Converting %s\n' % os.path.join(prefix, i))
40         subprocess.call(cmd)
41         if lyx != '':
42             # This is a hack, but without modifying the doc LyX refuses to save and stays open
43             # FIXME: Is self-insert a; char-delete-backward always a noop?
44             #        What if change-tracking is enabled?
45             cmd = [lyx, '-f', '-x', 'command-sequence self-insert a; char-delete-backward; buffer-write; lyx-quit', i]
46             subprocess.call(cmd)
47     os.chdir(olddir)
48
49
50 def main(argv):
51
52     toolsdir = os.path.dirname(argv[0])
53     lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
54     systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
55     if len(argv) > 1:
56         sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
57         lyx = os.path.abspath(argv[1])
58     else:
59         lyx = ''
60     docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
61     for docpath in docpaths:
62         docdir = os.path.abspath(os.path.join(toolsdir, docpath))
63         convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
64
65     return 0
66
67
68 if __name__ == "__main__":
69     main(sys.argv)