r660 - in branches/jrst-docutils-jython: . docutils/src/main/resources/docutils docutils/src/main/resources/docutils/docutils jrst/src/main/java/org/nuiton/jrst jrst/src/test/java/org/nuiton/jrst
Author: jpages Date: 2012-05-15 16:21:13 +0200 (Tue, 15 May 2012) New Revision: 660 Url: http://nuiton.org/repositories/revision/jrst/660 Log: Nettoyage de certaines lignes ou fichiers qui ne servaient pas. Removed: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java branches/jrst-docutils-jython/toRst1-in.xml Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py branches/jrst-docutils-jython/docutils/src/main/resources/docutils/docutils/core.py branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py =================================================================== --- branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-05-14 16:01:52 UTC (rev 659) +++ branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-05-15 14:21:13 UTC (rev 660) @@ -17,8 +17,6 @@ # '__pyclasspath__/docutils/writers/html4css1/html4css1.css', # python doesn't be able to find the resource, so it must have the # absolute path to the jar to read it with jaropen after. - # - # TODO (?) : Modifier pour que cela fonctionne pour la génération de site def jaropen(resourcePath, mode, bufsize=-1): if "__pyclasspath__" in resourcePath: # Replace the relative resource filepath by the absolute path Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/docutils/core.py =================================================================== --- branches/jrst-docutils-jython/docutils/src/main/resources/docutils/docutils/core.py 2012-05-14 16:01:52 UTC (rev 659) +++ branches/jrst-docutils-jython/docutils/src/main/resources/docutils/docutils/core.py 2012-05-15 14:21:13 UTC (rev 660) @@ -212,24 +212,16 @@ """ exit = None try: - print "if" if self.settings is None: - print "self.settings is None" self.process_command_line( argv, usage, description, settings_spec, config_section, **(settings_overrides or {})) - print "end if" - self.set_io() - print "set_io" + self.set_io() self.document = self.reader.read(self.source, self.parser, self.settings) - print "document" - self.apply_transforms() - print "apply_transforms" + self.apply_transforms() output = self.writer.write(self.document, self.destination) - print "output = self.writer.write(self.document, self.destination)" self.writer.assemble_parts() - print "writer.assemble_parts()" except SystemExit, error: exit = 1 exit_status = error.code Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-05-14 16:01:52 UTC (rev 659) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-05-15 14:21:13 UTC (rev 660) @@ -27,7 +27,6 @@ import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.io.*; -import java.lang.reflect.Field; import java.net.URL; import java.util.*; @@ -39,7 +38,6 @@ import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -57,7 +55,6 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.Resource; import org.nuiton.util.StringUtil; -import org.python.core.PyObject; import org.python.util.PythonInterpreter; /** @@ -150,9 +147,6 @@ /** XML output format type */ public static final String TYPE_XML = "xml"; - /** Boolean to know if PySystemState has already been initialized */ - private static boolean INITIALIZED = false; - /** * key, Out type; value: chain of XSL file to provide wanted file for output */ @@ -431,18 +425,8 @@ public static Document generateXML(File in) throws Exception { // RST to XML transformation via Docutils and a temporary file File out = File.createTempFile("result", ".xml"); - - FileWriter fileWriter = new FileWriter(out); - BufferedWriter bufferedWriter = null; - - try { - bufferedWriter = new BufferedWriter(fileWriter); - fileWriter.write(""); - } finally { - bufferedWriter.close(); - } - out = generateDocument(TYPE_XML, in, out); + SAXReader saxReader = new SAXReader(); return saxReader.read(out); } @@ -452,7 +436,7 @@ // Name of the main Python script final String runner = "__run__"; - log.info(out); + //log.info(out); /* Transformation of the __run__ URL into a path that python will use For example the URL is : @@ -471,6 +455,7 @@ String commandImport = "import __run__"; interp.exec(commandImport); + // If the OS is windows, escapes the backslashs in the filepath String filePath = in.getAbsolutePath(); String property = System.getProperty("os.name"); if (property.contains("win")) { @@ -480,7 +465,6 @@ // Execution of the docutils script to transform rst to xml String commandExec = String.format("__run__.exec_docutils('%s', '%s', '%s')", docutilsPath, outputType, filePath); - log.info("commandExec : " + commandExec); FileOutputStream fileOutputStream = null; try { // Sets an output stream to build the output file Deleted: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java 2012-05-14 16:01:52 UTC (rev 659) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java 2012-05-15 14:21:13 UTC (rev 660) @@ -1,91 +0,0 @@ -/* - * #%L - * JRst :: Api - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jrst; - -import java.net.URL; -import java.util.Properties; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.python.core.PySystemState; -import org.python.util.JarRunner; -import org.python.util.PythonInterpreter; - -/** - * Created with IntelliJ IDEA. - * User: jpages - * Date: 4/16/12 - * Time: 11:09 AM - * To change this template use File | Settings | File Templates. - */ -public class JRSTJython { - - /** to use log facility, just put in your code: log.info("..."); */ - protected static Log log = LogFactory.getLog(JRSTJython.class); - - /* - Essai avec Streams - @Test - public void testJython() throws Exception { - Properties props = new Properties(); - props.setProperty("python.path", "/home/yoros/Apps/Stage/docutils-0.8.1"); - PythonInterpreter.initialize(System.getProperties(), props, - new String[]{""}); - InputStream in = JRSTReaderTest.class - .getResourceAsStream("/test.rst"); - InputStream rst2xml = JRST.class - .getResourceAsStream("/docutils/build/scripts-2.7/rst2xml.py"); - - PythonInterpreter interp = new PythonInterpreter(); - interp.setIn(in); - interp.execfile(rst2xml); - } - */ - - // Essai avec JarRunner - @Test - public void testJython2() throws Exception { - URL resource = getClass().getResource("/__run__.py"); - System.out.println(resource); - - String docutilsPath = resource.getPath().replaceAll("__run__.py", ""); - docutilsPath = docutilsPath.replaceAll("!", ""); - docutilsPath = docutilsPath.replaceAll("file:", ""); - JarRunner.run(new String[]{docutilsPath, "XML", "/home/yoros/workspace/jrst-docutils-jython/target/surefire-workdir/toRst1-in.rst", "toRst1-in.xml"}); - } - - @Test - public void test() { - Properties props = PySystemState.getBaseProperties(); - System.out.println(props.getProperty("python.path")); - props.setProperty("python.path", "/home/yoros/workspace/jrst-docutils-jython/jrst/src/main/resources/Lib:/home/yoros/workspace/jrst-docutils-jython/jrst/src/main/resources/build:/docutils/build/scripts-2.7/rst2xml.py"); - PythonInterpreter.initialize(PySystemState.getBaseProperties(), props, new String[0]); - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile("src/main/resources/docutils/build/scripts-2.7/rst2xml.py"); - //interp.exec("import sys"); - // System.out.println("path python = " + interp.eval("sys.path")); - //interp.exec("import docutils"); - } -} \ No newline at end of file Deleted: branches/jrst-docutils-jython/toRst1-in.xml =================================================================== (Binary files differ)
participants (1)
-
jpages@users.nuiton.org