Esempio n. 1
0
def convert():
    if len(sys.argv) == 1:
        print("This is Pweave document converter %s. Enter pweave-convert -h for help " % pweave.__version__)
        sys.exit()

    parser = OptionParser(usage="pweave-convert [options] sourcefile", version="Part of Pweave " + pweave.__version__)
    parser.add_option("-i", "--input-format", dest="informat", default='noweb',
                      help="Input format: noweb, notebook or script")
    parser.add_option("-f", "--output-format", dest="outformat", default='html',
                      help="Output format script, noweb or notebook")
    parser.add_option("-l", "--list-formats", dest="listformats", action="store_true", default=False,
                      help="List input / output formats")
    parser.add_option("-p", "--pandoc", dest="pandoc_args", default=None,
                      help="passed to pandoc for converting doc chunks")

    (options, args) = parser.parse_args()

    try:
        infile = args[0]
    except IndexError:
        infile = ""

    pweave.convert(file=infile,
                   informat=options.informat,
                   outformat=options.outformat,
                   pandoc_args=options.pandoc_args,
                   listformats=options.listformats)
Esempio n. 2
0
def test_convert():
    """Test pweave-convert"""
    REF = 'tests/convert_test_ref.Pnw'
    infile = 'tests/convert_test.txt'
    outfile = 'tests/convert_test.Pnw'
    pweave.convert(infile, informat="script", outformat="noweb")
    assert (open(outfile).read() == open(REF).read())
def convert():
    if len(sys.argv) == 1:
        print(
            "This is Pweave document converter %s. Enter Pweave-convert -h for help "
            % pweave.__version__)
        sys.exit()

    parser = OptionParser(usage="Pweave-convert [options] sourcefile",
                          version="Part of Pweave " + pweave.__version__)
    parser.add_option("-i",
                      "--input-format",
                      dest="informat",
                      default='noweb',
                      help="Input format: noweb, notebook or script")
    parser.add_option("-f",
                      "--output-format",
                      dest="outformat",
                      default='html',
                      help="Output format script or noweb")
    parser.add_option("-p",
                      "--pandoc",
                      dest="pandoc_args",
                      default=None,
                      help="passed to pandoc for converting doc chunks")

    (options, args) = parser.parse_args()

    infile = args[0]

    #print options
    pweave.convert(infile, options.informat, options.outformat,
                   options.pandoc_args)
Esempio n. 4
0
def test_convert():
    """Test pweave-convert"""
    REF = 'tests/convert_test_ref.Pnw'
    infile = 'tests/convert_test.txt'
    outfile = 'tests/convert_test.Pnw'
    pweave.convert(infile, informat="script", outformat="noweb")
    assertSameContent(REF, outfile)
Esempio n. 5
0
def test_convert():
    """Test pweave-convert"""
    REF = 'tests/convert_test_ref.Pnw'
    infile = 'tests/convert_test.txt'
    outfile = 'tests/convert_test.Pnw'
    pweave.convert(infile, informat="script", outformat="noweb")
    assert(open(outfile).read() == open(REF).read())
Esempio n. 6
0
def test_nbformat():
    """Test whether we can write an IPython Notebook.
    """
    REF = 'tests/simple_REF.ipynb'
    infile = 'tests/simple.mdw'
    outfile = 'tests/simple.ipynb'
    # pandoc_args = None skips the call to pandoc
    pweave.convert(file=infile, informat="noweb", outformat="notebook")

    assertSameContent(REF, outfile)
Esempio n. 7
0
def convert():
    if len(sys.argv) == 1:
        print(
            "This is Pweave document converter %s. Enter pweave-convert -h for help "
            % pweave.__version__)
        sys.exit()

    parser = OptionParser(
        usage="pweave-convert [options] sourcefile",
        version="Part of Pweave " + pweave.__version__,
    )
    parser.add_option(
        "-i",
        "--input-format",
        dest="informat",
        default="noweb",
        help="Input format: noweb, notebook or script",
    )
    parser.add_option(
        "-f",
        "--output-format",
        dest="outformat",
        default="html",
        help="Output format script, noweb or notebook",
    )
    parser.add_option(
        "-l",
        "--list-formats",
        dest="listformats",
        action="store_true",
        default=False,
        help="List input / output formats",
    )
    parser.add_option(
        "-p",
        "--pandoc",
        dest="pandoc_args",
        default=None,
        help="passed to pandoc for converting doc chunks",
    )

    (options, args) = parser.parse_args()

    try:
        infile = args[0]
    except IndexError:
        infile = ""

    pweave.convert(
        file=infile,
        informat=options.informat,
        outformat=options.outformat,
        pandoc_args=options.pandoc_args,
        listformats=options.listformats,
    )
Esempio n. 8
0
        def testMethod(self):
            basename, _, _ = infile.rpartition('.')
            outfile = basename + '.' + outext
            self.setNewOutfile(outfile)

            pweave.convert(self.absPathTo(infile),
                           informat=informat,
                           outformat=outformat)

            self.REFERENCE = self.absPathTo(basename + '_REF.' + outext)
            self.assertSameAsReference()
Esempio n. 9
0
        def testMethod(self):
            basename, _, _ = infile.rpartition('.')
            outfile = basename + '.' + outext
            self.setNewOutfile(outfile)

            pweave.convert(self.absPathTo(infile),
                           informat=informat,
                           outformat=outformat)

            self.REFERENCE = self.absPathTo(basename + '_REF.' + outext)
            self.assertSameAsReference()
Esempio n. 10
0
def test_nbformat():
    """Test whether we can write an IPython Notebook.
    """
    REF = 'tests/simple_REF.ipynb'
    infile = 'tests/simple.mdw'
    outfile = 'tests/simple.ipynb'
    # pandoc_args = None skips the call to pandoc
    pweave.convert(file=infile, informat="noweb", outformat="notebook")

    # Compare the outfile and the ref
    out = open(outfile)
    ref = open(REF)
    assert (out.read() == ref.read())
Esempio n. 11
0
def test_nbformat():
    """Test whether we can write an IPython Notebook.
    """
    REF = 'tests/simple_REF.ipynb'
    infile = 'tests/simple.mdw'
    outfile = 'tests/simple.ipynb'
    # pandoc_args = None skips the call to pandoc
    pweave.convert(file=infile, informat="noweb", outformat="notebook")

    # Compare the outfile and the ref
    out = open(outfile)
    ref = open(REF)
    assert(out.read() == ref.read())
Esempio n. 12
0
def convert():
    if len(sys.argv)==1:
        print("This is Pweave document converter %s. Enter Pweave-convert -h for help " % pweave.__version__)
        sys.exit()

    parser = OptionParser(usage="Pweave-convert [options] sourcefile", version="Part of Pweave " + pweave.__version__)
    parser.add_option("-i", "--input-format", dest="informat", default='noweb',
                      help="Input format: noweb, notebook or script")
    parser.add_option("-f", "--output-format", dest="outformat", default='html',
                      help = "Output format script or noweb")
    parser.add_option("-p", "--pandoc", dest="pandoc_args", default=None,
                      help = "passed to pandoc for converting doc chunks")
    
    (options, args) = parser.parse_args()

    infile = args[0]

    #print options
    pweave.convert(infile, options.informat, options.outformat, options.pandoc_args)
Esempio n. 13
0
import os
import glob
import pweave
import shutil

os.chdir('originals')
docs = glob.glob('*.txt')

for doc in docs:    
    pweave.convert(doc, "wiki", "noweb", "-f mediawiki -t rst")
    new = "../converted/" + doc.replace(".txt", ".Pnw")
    shutil.move(doc.replace(".txt", '.Pnw'), new)
    pweave.convert(doc, "wiki", "ipython", "-f mediawiki -t markdown")
    new = "../tmp/" + doc.replace(".txt", ".py")
    shutil.move(doc.replace(".txt", '.py'), new)
Esempio n. 14
0
 def testConvert(self):
     pweave.convert(self.absPathTo(self.INFILE),
                    informat=self.INFORMAT,
                    outformat=self.OUTFORMAT)
     self.assertSameAsReference()