コード例 #1
0
ファイル: scripts.py プロジェクト: mpastell/Pweave
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)
コード例 #2
0
ファイル: test_pweave.py プロジェクト: trsaunders/Pweave
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())
コード例 #3
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)
コード例 #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)
コード例 #5
0
ファイル: test_pweave.py プロジェクト: magdalenat/Pweave
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())
コード例 #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)
コード例 #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,
    )
コード例 #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()
コード例 #9
0
ファイル: test_pweave.py プロジェクト: trnkatomas/Pweave
        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()
コード例 #10
0
ファイル: test_pweave.py プロジェクト: trsaunders/Pweave
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())
コード例 #11
0
ファイル: test_pweave.py プロジェクト: magdalenat/Pweave
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())
コード例 #12
0
ファイル: scripts.py プロジェクト: aaren/Pweave
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)
コード例 #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)
コード例 #14
0
ファイル: test_pweave.py プロジェクト: joelkim/Pweave
 def testConvert(self):
     pweave.convert(self.absPathTo(self.INFILE),
                    informat=self.INFORMAT,
                    outformat=self.OUTFORMAT)
     self.assertSameAsReference()