]> git.lyx.org Git - lyx.git/blob - development/tools/updatedocs.py
Correctly interpret return value of LyXRC::read(FileName const & filename, bool check...
[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 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             # This is a hack, but without modifying the doc LyX refuses to save and stays open
44             # FIXME: Is self-insert a; char-delete-backward always a noop?
45             #        What if change-tracking is enabled?
46             cmd = [lyx, '-f', '-x', 'command-sequence self-insert a; char-delete-backward; buffer-write; lyx-quit', i]
47             subprocess.call(cmd)
48     os.chdir(olddir)
49
50
51 def main(argv):
52
53     toolsdir = os.path.dirname(argv[0])
54
55     # first generate LFUNs.lyx
56     lyxaction = os.path.abspath(os.path.join(toolsdir, "../../src/LyXAction.cpp"))
57     lfunspath = os.path.abspath(os.path.join(toolsdir, "../../lib/doc"))
58     lfuns = os.path.join(lfunspath, "LFUNs.lyx")
59     # genlfuns refuses to overwrite files
60     if os.path.exists(lfuns):
61         os.rename(lfuns, os.path.join(lfunspath, "LFUNs.lyx.old"))
62     # genlfuns requires a trailing slash
63     genlfuns(["genlfuns", lyxaction, lfunspath + os.sep])
64
65     # then update all docs
66     lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
67     systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
68     if len(argv) > 1:
69         sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
70         lyx = os.path.abspath(argv[1])
71     else:
72         lyx = ''
73     docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
74     for docpath in docpaths:
75         docdir = os.path.abspath(os.path.join(toolsdir, docpath))
76         convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
77
78     return 0
79
80
81 if __name__ == "__main__":
82     main(sys.argv)