File: updatedocs.py

package info (click to toggle)
lyx 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 138,444 kB
  • sloc: cpp: 244,268; ansic: 106,398; xml: 72,791; python: 39,384; sh: 7,666; makefile: 6,584; pascal: 2,143; perl: 2,101; objc: 1,084; tcl: 163; sed: 16
file content (79 lines) | stat: -rwxr-xr-x 2,748 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/python3
# -*- coding: utf-8 -*-

# file updatedocs.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.

# author Georg Baum

# Full author contact details are available in file CREDITS

# This script converts documentation .lyx files to current format
# The old files are backuped with extension ".old"


import os, re, string, sys, subprocess, shutil
from gen_lfuns import main as genlfuns


def convertdir(docdir, prefix, lyx2lyx, lyx, systemlyxdir):
    olddir = os.getcwd()
    os.chdir(docdir)
    for i in os.listdir("."):
        if os.path.isdir(i):
            if i != 'attic':
                subdir = os.path.join(docdir, i)
                subprefix = os.path.join(prefix, i)
                convertdir(subdir, subprefix, lyx2lyx, lyx, systemlyxdir)
            continue
        (base, ext) = os.path.splitext(i)
        if ext != ".lyx":
            continue
        old = i + ".old"
        shutil.copy(i, old)
        if sys.executable and sys.executable != '':
            cmd = [sys.executable, lyx2lyx, old, '-s', systemlyxdir, '-o', i]
        else:
            # assume that python is in the path
            cmd = [lyx2lyx, old, '-s', systemlyxdir, '-o', i]
        sys.stderr.write('Converting %s\n' % os.path.join(prefix, i))
        subprocess.call(cmd)
        if lyx != '':
            cmd = [lyx, '-f', '-x', 'command-sequence buffer-write force; lyx-quit', i]
            subprocess.call(cmd)
    os.chdir(olddir)


def main(argv):

    toolsdir = os.path.dirname(argv[0])

    # first generate LFUNs.lyx
    lyxaction = os.path.abspath(os.path.join(toolsdir, "../../src/LyXAction.cpp"))
    lfunspath = os.path.abspath(os.path.join(toolsdir, "../../lib/doc"))
    lfuns = os.path.join(lfunspath, "LFUNs.lyx")
    # genlfuns refuses to overwrite files
    if os.path.exists(lfuns):
        os.rename(lfuns, os.path.join(lfunspath, "LFUNs.lyx.old"))
    # genlfuns requires a trailing slash
    genlfuns(["genlfuns", lyxaction, lfunspath + os.sep])

    # then update all docs
    lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
    systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
    if len(argv) > 1:
        sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
        lyx = os.path.abspath(argv[1])
    else:
        lyx = ''
    docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
    for docpath in docpaths:
        docdir = os.path.abspath(os.path.join(toolsdir, docpath))
        convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)

    return 0


if __name__ == "__main__":
    main(sys.argv)