Added append action to file plugin

This commit is contained in:
Fabio Manganiello 2018-10-17 09:02:22 +02:00
parent 2eccd41420
commit 3458fb8a23
1 changed files with 18 additions and 7 deletions

View File

@ -19,22 +19,33 @@ class FilePlugin(Plugin):
return f.read()
@action
def write(self, filename, content, append=False):
def write(self, filename, content):
"""
Writes content to a specified filename
Writes content to a specified filename. Previous content will be truncated.
:param filename: Path of the file
:type filename: str
:param content: Content to write
:type content: str
:param append: If set, the content will be appended to the file (default: False, truncate file upon write)
:type append: bool
"""
mode = 'a' if append else 'w'
with open(filename, mode) as f:
with open(filename, 'w') as f:
f.write(content)
@action
def append(self, filename, content):
"""
Append content to a specified filename
:param filename: Path of the file
:type filename: str
:param content: Content to write
:type content: str
"""
with open(filename, 'a') as f:
f.write(content)
# vim:sw=4:ts=4:et: