From f110ef2f41d0aca14acd4a5f1aec6011f770c3c6 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 16 Nov 2014 12:43:52 +0100 Subject: [PATCH] Convert updatelayouts.sh to python This makes the script usable on windows and speeds it up by an order of magnitude, since no new process needs to be forked for each layout file. It also does not conevrt .old files again. --- development/tools/updatelayouts.py | 38 ++++++++++++++++++++++++++++++ development/tools/updatelayouts.sh | 23 ------------------ lib/scripts/layout2layout.py | 2 +- src/TextClass.cpp | 5 ++-- 4 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 development/tools/updatelayouts.py delete mode 100644 development/tools/updatelayouts.sh diff --git a/development/tools/updatelayouts.py b/development/tools/updatelayouts.py new file mode 100644 index 0000000000..f3ec98e558 --- /dev/null +++ b/development/tools/updatelayouts.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# file updatelayouts.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 all layout files to current format +# The old files are backuped with extension ".old" + + +import os, re, string, sys, subprocess, tempfile, shutil + +sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), "../../lib/scripts")) +from layout2layout import main as layout2layout + +def main(argv): + + toolsdir = os.path.dirname(argv[0]) + layoutdir = os.path.join(toolsdir, '../../lib/layouts') + os.chdir(layoutdir) + for i in os.listdir("."): + (base, ext) = os.path.splitext(i) + if ext == ".old": + continue + args = ["layout2layout", i + ".old", i] + shutil.copy(args[2], args[1]) + layout2layout(args) + + return 0 + + +if __name__ == "__main__": + main(sys.argv) diff --git a/development/tools/updatelayouts.sh b/development/tools/updatelayouts.sh deleted file mode 100644 index 7a15a58fd7..0000000000 --- a/development/tools/updatelayouts.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# find out where we are relative to the program directory -curdir=$(pwd); -progloc=$0; -pathto=${progloc%/*}; -# get us into development/tools -if [ "$progloc" != "$pathto" ]; then - if ! cd $pathto; then - echo "Couldn't get to development/tools!"; - exit 1; - fi -fi - -if ! cd ../../lib/layouts/; then - echo "Couldn't get to lib/layouts!"; - exit 1; -fi - -for i in *; do - cp $i $i.old; - python ../scripts/layout2layout.py <$i.old >$i; -done diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 199a31834e..d269d585d7 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -175,7 +175,7 @@ import os, re, string, sys # Manual (section "Declaring a new text class"). # You might also want to consider running the -# development/tools/updatelayouts.sh script to update all +# development/tools/updatelayouts.py script to update all # layout files to the new format. currentFormat = 51 diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 23fd1eed9a..e0e302a9ac 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -58,9 +58,8 @@ namespace lyx { // LayoutFile.cpp. Additions will never do so, but syntax changes // could. See LayoutFileList::addEmptyClass() and, especially, the // definition of the layoutpost string. -// You should also run (or ask someone who has bash to run) the -// development/tools/updatelayouts.sh script, to update the format of -// all of our layout files. +// You should also run the development/tools/updatelayouts.py script, +// to update the format of all of our layout files. // int const LAYOUT_FORMAT = 51; //spitz: add ToggleIndent tag