mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
3ab58d155c
Thanks Scott for the idea to modify the document. This seems to work, but I am not surer whether it is safe in all cases, so better warn if this is used.
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
#! /usr/bin/env python
|
|
# -*- 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
|
|
|
|
|
|
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 != '':
|
|
# This is a hack, but without modifying the doc LyX refuses to save and stays open
|
|
# FIXME: Is self-insert a; char-delete-backward always a noop?
|
|
# What if change-tracking is enabled?
|
|
cmd = [lyx, '-f', '-x', 'command-sequence self-insert a; char-delete-backward; buffer-write; lyx-quit', i]
|
|
subprocess.call(cmd)
|
|
os.chdir(olddir)
|
|
|
|
|
|
def main(argv):
|
|
|
|
toolsdir = os.path.dirname(argv[0])
|
|
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)
|