summaryrefslogtreecommitdiff
path: root/pywal/util.py
diff options
context:
space:
mode:
authorDylan Araps <dylanaraps@users.noreply.github.com>2017-07-23 15:37:14 +1000
committerGitHub <noreply@github.com>2017-07-23 15:37:14 +1000
commit0c1d76e2b3611b541316dc8d7eb67f18cec5e7f2 (patch)
treeaaf8141c62789dcfc4f72af24ae96df71459a084 /pywal/util.py
parent9c871ec567504c2566c4ce9f3d382f544cb62b57 (diff)
parent07b8ad8e0d97f54277c2e744f745ba3e47d0e53c (diff)
Merge pull request #52 from dylanaraps/api
api: Start work on a proper api.
Diffstat (limited to 'pywal/util.py')
-rw-r--r--pywal/util.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/pywal/util.py b/pywal/util.py
index 6c5b420..1df3c9f 100644
--- a/pywal/util.py
+++ b/pywal/util.py
@@ -44,32 +44,40 @@ def set_grey(colors):
def read_file(input_file):
- """Read data from a file."""
- with open(input_file) as file:
+ """Read data from a file and trim newlines."""
+ with open(input_file, "r") as file:
data = file.read().splitlines()
return data
def read_file_json(input_file):
"""Read data from a json file."""
- with open(input_file) as json_file:
+ with open(input_file, "r") as json_file:
data = json.load(json_file)
- # If wallpaper is unset, set it to "None"
- if "wallpaper" not in data:
- data["wallpaper"] = "None"
+ return data
+
+def read_file_raw(input_file):
+ """Read data from a file as is, don't strip
+ newlines or other special characters.."""
+ with open(input_file, "r") as file:
+ data = file.readlines()
return data
def save_file(data, export_file):
"""Write data to a file."""
+ create_dir(os.path.dirname(export_file))
+
with open(export_file, "w") as file:
file.write(data)
def save_file_json(data, export_file):
"""Write data to a json file."""
+ create_dir(os.path.dirname(export_file))
+
with open(export_file, "w") as file:
json.dump(data, file, indent=4)
@@ -98,3 +106,12 @@ def disown(*cmd):
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
preexec_fn=os.setpgrp)
+
+
+def msg(input_msg, notify):
+ """Print to the terminal and display a libnotify
+ notification."""
+ if notify:
+ disown("notify-send", input_msg)
+
+ print(input_msg)