Skip to content

Instantly share code, notes, and snippets.

@toretto460
Created September 7, 2014 16:03
Show Gist options
  • Save toretto460/7dd0c94dcc905ec420af to your computer and use it in GitHub Desktop.
Save toretto460/7dd0c94dcc905ec420af to your computer and use it in GitHub Desktop.
Convert files with pandoc from a format to another
from subprocess import call
import os
class PandocConverter:
def __init__(self, destination = 'dist', enableLogger = True):
self.commandBase = ['pandoc']
self.destination = destination
self.isLoggerEnabled = enableLogger
def log(self, msg):
if (self.isLoggerEnabled):
print msg;
def list_files_in_folder(self, folder):
basePath = os.path.abspath(folder)
files = os.listdir(basePath)
files.sort()
return map(lambda f: os.path.join(basePath,f), files)
def ensure_dir(self, directory):
if not os.path.exists(directory):
os.makedirs(directory)
def compile_doc(self, files, formats, outputBaseName, options = []):
for format in formats:
self.ensure_dir(self.destination)
compiledDoc = "%s/%s.%s" % (self.destination, outputBaseName, format)
self.log("Generating %s" % (compiledDoc))
commandOut = ['-o', compiledDoc]
call(self.commandBase + files + options + commandOut)
return compiledDoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment