]> git.lyx.org Git - features.git/commitdiff
Convert updatelayouts.sh to python
authorGeorg Baum <baum@lyx.org>
Sun, 16 Nov 2014 11:43:52 +0000 (12:43 +0100)
committerGeorg Baum <baum@lyx.org>
Sun, 16 Nov 2014 11:43:52 +0000 (12:43 +0100)
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 [new file with mode: 0644]
development/tools/updatelayouts.sh [deleted file]
lib/scripts/layout2layout.py
src/TextClass.cpp

diff --git a/development/tools/updatelayouts.py b/development/tools/updatelayouts.py
new file mode 100644 (file)
index 0000000..f3ec98e
--- /dev/null
@@ -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 (file)
index 7a15a58..0000000
+++ /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
index 199a31834e2a18296d49eba65105686c7324a85f..d269d585d79c6a0441264ac2cbe9f64965da7b68 100644 (file)
@@ -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
index 23fd1eed9a43bb43a5a0fe256ec190c309ead0dd..e0e302a9acf0dfd0d1d287a0371e5467091ba6a3 100644 (file)
@@ -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