Created
September 7, 2014 16:03
-
-
Save simodima/7dd0c94dcc905ec420af to your computer and use it in GitHub Desktop.
Convert files with pandoc from a format to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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