[elbe-devel] [PATCH 1/3] asciidoclog: add extra option to allow appending
John Ogness
john.ogness at linutronix.de
Fri Apr 27 01:43:05 CEST 2018
Some functions may need to append to an existing file. Provide an
option to allow that.
If not specified, the option defaults to overwrite instead of
append. This preserves the old behavior for existing code.
Signed-off-by: John Ogness <john.ogness at linutronix.de>
---
elbepack/asciidoclog.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/elbepack/asciidoclog.py b/elbepack/asciidoclog.py
index 4912253a..dc806fed 100644
--- a/elbepack/asciidoclog.py
+++ b/elbepack/asciidoclog.py
@@ -89,11 +89,14 @@ class LogBase(object):
class ASCIIDocLog (LogBase):
- def __init__(self, fname):
+ def __init__(self, fname, append=False):
self.fname = fname
- if os.path.isfile(fname):
- os.unlink(fname)
- fp = file(fname, "w", 0)
+ if append:
+ fp = file(fname, "a", 0)
+ else:
+ if os.path.isfile(fname):
+ os.unlink(fname)
+ fp = file(fname, "w", 0)
LogBase.__init__(self, fp)
--
2.11.0
More information about the elbe-devel
mailing list