r649 - in branches/jrst-docutils-jython: docutils docutils/src/main/resources docutils/src/main/resources/docutils jrst/src/main/java/org/nuiton/jrst jrst/src/test/java/org/nuiton/jrst jrst/src/test/java/org/nuiton/jrst/bugs
Author: jpages Date: 2012-04-26 18:29:18 +0200 (Thu, 26 Apr 2012) New Revision: 649 Url: http://nuiton.org/repositories/revision/jrst/649 Log: Mise ?\195?\160 jour du script python __run__.py (lecture dans le jar pas encore fonctionnelle) Added: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py Removed: branches/jrst-docutils-jython/docutils/src/main/resources/__run__.py Modified: branches/jrst-docutils-jython/docutils/docutils.iml branches/jrst-docutils-jython/docutils/pom.xml branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java Modified: branches/jrst-docutils-jython/docutils/docutils.iml =================================================================== --- branches/jrst-docutils-jython/docutils/docutils.iml 2012-04-24 14:43:20 UTC (rev 648) +++ branches/jrst-docutils-jython/docutils/docutils.iml 2012-04-26 16:29:18 UTC (rev 649) @@ -4,7 +4,7 @@ <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/resources/docutils" isTestSource="false" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> Modified: branches/jrst-docutils-jython/docutils/pom.xml =================================================================== (Binary files differ) Deleted: branches/jrst-docutils-jython/docutils/src/main/resources/__run__.py =================================================================== --- branches/jrst-docutils-jython/docutils/src/main/resources/__run__.py 2012-04-24 14:43:20 UTC (rev 648) +++ branches/jrst-docutils-jython/docutils/src/main/resources/__run__.py 2012-04-26 16:29:18 UTC (rev 649) @@ -1,41 +0,0 @@ -#!/usr/bin/python -# coding=utf-8 - -import os, sys - -# Save the path of __run__.py -pathname = os.path.abspath(os.path.dirname(sys.argv[0])) - -# Add the lib path to sys.path -lib_path = os.path.dirname(sys.argv[1]) + '/docutils' -sys.path.append(lib_path) - -# Add the scripts path to sys.path -scriptpath = lib_path + '/build/scripts-2.7' -sys.path.append(scriptpath) - -# Change the order of the arguments of the script : -# In the python scripts rst2*, the input file name must be the first argument -typeExport = sys.argv[2] # Type of the output file -sys.argv[1] = sys.argv[3] # Name of the input file become -sys.argv[2] = sys.argv[4] # Name of the output file -sys.argv.pop(4) -sys.argv.pop(3) - - -if typeExport == "XML": - import rst2xml -elif typeExport == "HTML": - import rst2html -elif typeExport == "ODT": - import rst2odt -elif typeExport == "LATEX": - import rst2latex -elif typeExport == "MAN": - import rst2man -elif typeExport == "S5": - import rst2s5 -elif typeExport == "XETEX": - import rst2xetex -else: - print "1st argument : Output format / 2nd : Input filename / 3rd : Output filename" \ No newline at end of file Copied: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py (from rev 647, branches/jrst-docutils-jython/docutils/src/main/resources/__run__.py) =================================================================== --- branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py (rev 0) +++ branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-04-26 16:29:18 UTC (rev 649) @@ -0,0 +1,71 @@ +#!/usr/bin/python +# coding=utf-8 + +import __builtin__, os, sys, string +import java.io.File + + +incompleteDictionary = False +try: + __builtin__.__dict__["openlegacy"] +except: + incompleteDictionary = True + +print "a faire : %s" % incompleteDictionary + +# Save the path of __run__.py +pathname = os.path.abspath(os.path.dirname(sys.argv[0])) + +# Add the lib path to sys.path +print sys.argv +lib_path = os.path.dirname(sys.argv[1]) +sys.path.append(lib_path) + +# if it has not already been defined, the function jaropen will be able to +# read into the jar. +if incompleteDictionary: + print __builtin__ + print __builtin__.__dict__["open"] + + def jaropen(jarpath, mode, bufsize=-1): + if "__pyclasspath__" in jarpath: + print "lib_path : " + lib_path + jarpath = string.replace(jarpath, '__pyclasspath__', lib_path+"!") + print "Jaropen: " + jarpath + " " + mode + if ("jar!" in jarpath): + f = File(jarpath) + istream = f.toURI().toURL().openStream(); + f = __builtin__.openlegacy(inStream, bufsize) + else: + f = __builtin__.openlegacy(jarpath, mode, bufsize) + return f + + __builtin__.__dict__["openlegacy"] = __builtin__.__dict__["open"] + __builtin__.__dict__["open"] = jaropen +else: + print "Else : Deja fait !" + +# Add the lib path to sys.path +print sys.argv +lib_path = os.path.dirname(sys.argv[1]) +sys.path.append(lib_path) + +# Add the scripts path to sys.path +scriptpath = lib_path + '/build/scripts-2.7' +sys.path.append(scriptpath) + +# Call publish_file with the good arguments +typeOutput = sys.argv[2].lower() +filein = sys.argv[3] +fileout = sys.argv[4] + + +# If Docutils can manage this output format, we call it +from docutils.core import publish_file, default_description + +listType = ["xml", "html", "odt", "latex", "man", "s5", "xetex"] +if typeOutput in listType: + print publish_file( source_path=filein, destination_path=fileout, + writer_name=typeOutput.lower() ) +else: + print "Wrong output format" 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-04-24 14:43:20 UTC (rev 648) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-04-26 16:29:18 UTC (rev 649) @@ -44,6 +44,7 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.Resource; import org.nuiton.util.StringUtil; +import org.python.modules.zipimport.zipimporter; import org.python.util.JarRunner; /** @@ -428,22 +429,19 @@ } public static File generateDocument(String outputType, File in, File out) throws Exception { - - //If we are here, we can overwrite on the file - //out.createNewFile(); - + // On récupère le chemin vers le script principal de docutils URL resource = in.getClass().getResource("/__run__.py"); String docutilsPath = resource.getPath().replaceAll("__run__.py", ""); docutilsPath = docutilsPath.replaceAll("!", ""); docutilsPath = docutilsPath.replaceAll("file:", ""); log.info("Run Python with args: " + Arrays.toString(new String[]{docutilsPath, outputType, in.getPath(), out.getPath()})); - JarRunner.run(new String[]{docutilsPath, outputType, in.getPath(), out.getPath()}); - return out; + return out; } + public static String generateRST(Document doc) throws IOException { // Creation d'un visitor qui convertie de l'xml vers le rst DocUtilsVisitor visitor = new DocUtils2RST(); Modified: 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-04-24 14:43:20 UTC (rev 648) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java 2012-04-26 16:29:18 UTC (rev 649) @@ -61,7 +61,7 @@ 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("/home/yoros/workspace/jrst-docutils-jython/jrst/src/main/resources/docutils/build/scripts-2.7/rst2xml.py"); + 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"); Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java 2012-04-24 14:43:20 UTC (rev 648) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java 2012-04-26 16:29:18 UTC (rev 649) @@ -31,7 +31,7 @@ import org.nuiton.jrst.JRST; import org.nuiton.jrst.JRSTAbstractTest; -import java.io.File; +import java.io.*; /** * Test concernant les admonitions. @@ -59,9 +59,26 @@ // out.deleteOnExit(); JRST.generate(JRST.Format.HTML.name(), in, out, JRST.Overwrite.ALLTIME); + String chaine=""; + + //lecture du fichier texte + try{ + InputStream ips=new FileInputStream(out); + InputStreamReader ipsr=new InputStreamReader(ips); + BufferedReader br=new BufferedReader(ipsr); + String ligne; + while ((ligne=br.readLine())!=null){ + System.out.println(ligne); + } + br.close(); + } + catch (Exception e){ + System.out.println(e.toString()); + } + String content = FileUtils.readFileToString(out); // Must contains <div class="note"> assertTrue(content.contains("<div class=\"note\">")); } -} +} \ No newline at end of file
participants (1)
-
jpages@users.nuiton.org