Commit 7f76b6cc authored by Ryan Herbert's avatar Ryan Herbert Committed by Mikael Salson make file output optional

since we may not want to export to a file, leaving the filepath variable
at None will disable the file writing capabilities.
parent 01db44c6
......@@ -4,18 +4,21 @@ from six import string_types
class VidjilWriter(object):
def __init__(self, filepath, pretty=False):
def __init__(self, filepath=None, pretty=False):
self._filepath = filepath
self.pretty = pretty
self.buffer = ""
self.buffering = False
self.conserveBuffer = False
self.file = None
def __enter__(self):
if self._filepath:
self.file = open(self._filepath, 'w')
return self
def __exit__(self, exc_type, exc_value, traceback):
if self.file:
def write(self, prefix, event, value, previous):
......@@ -23,7 +26,7 @@ class VidjilWriter(object):
if self.buffering:
self.buffer += res
return ""
elif self.file:
return res
......@@ -67,6 +70,7 @@ class VidjilWriter(object):
def writeBuffer(self):
if self.file:
return self.buffer
......@@ -106,7 +110,7 @@ class VidjilParser(object):
if writer is not None:
self._writer = writer
self._writer = VidjilWriter('out.json')
self._writer = VidjilWriter()
self._model_prefixes = []
self.prefixes = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment