From 4d3d8ddd34c6992baa7b635bb7fb611560c32ad4 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 16 Oct 2018 09:01:22 +0200 Subject: [PATCH] File utils moved to new file plugin --- platypush/plugins/file.py | 41 ++++++++++++++++++++++++++++++++++++++ platypush/plugins/utils.py | 30 ---------------------------- 2 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 platypush/plugins/file.py diff --git a/platypush/plugins/file.py b/platypush/plugins/file.py new file mode 100644 index 000000000..aa134f351 --- /dev/null +++ b/platypush/plugins/file.py @@ -0,0 +1,41 @@ +from platypush.plugins import Plugin, action + + +class FilePlugin(Plugin): + """ + A plugin for general-purpose file methods + """ + + @action + def get(self, filename): + """ + Gets the content of a file + + :param filename: Path of the file + :type filename: str + """ + + with open(filename, 'r') as f: + return f.read() + + @action + def write(self, filename, content, append=False): + """ + Writes content to a specified filename + + :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: + f.write(content) + +# vim:sw=4:ts=4:et: + diff --git a/platypush/plugins/utils.py b/platypush/plugins/utils.py index c774aa9f2..f16277906 100644 --- a/platypush/plugins/utils.py +++ b/platypush/plugins/utils.py @@ -19,36 +19,6 @@ class UtilsPlugin(Plugin): time.sleep(seconds) - @action - def file_get(self, filename): - """ - Gets the content of a file - - :param filename: Path of the file - :type filename: str - """ - - with open(filename, 'r') as f: - return f.read() - - @action - def file_write(self, filename, content, append=False): - """ - Writes content to a specified filename - - :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: - f.write(content) # vim:sw=4:ts=4:et: