diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-07-22 11:19:17 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-07-22 11:19:17 +1000 |
| commit | a34a9c597722056f4eba4b689775f9f202a35822 (patch) | |
| tree | 5f26537f24772b21fa0a048e597dcb51ec347562 | |
| parent | 7d1fc8d4d3ea3a182b567a4d54c87574f0506fcd (diff) | |
api: Cleanup
| -rw-r--r-- | pywal/__main__.py | 12 | ||||
| -rw-r--r-- | pywal/reload.py | 4 | ||||
| -rw-r--r-- | pywal/util.py | 8 | ||||
| -rw-r--r-- | pywal/wal.py | 4 |
4 files changed, 16 insertions, 12 deletions
diff --git a/pywal/__main__.py b/pywal/__main__.py index 92e3d4b..5adf038 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -60,23 +60,22 @@ def process_args(args): " Refer to \"wal -h\" for more info.") exit(1) + if args.v: + print(f"wal {wal.__version__}") + exit(0) + if args.q: sys.stdout = sys.stderr = open(os.devnull, "w") if args.c: shutil.rmtree(wal.CACHE_DIR / "schemes") - util.create_dir(wal.CACHE_DIR / "schemes") if args.r: wal.reload_colors(args.t) - if args.v: - print(f"wal {wal.__version__}") - exit(0) - if args.i: image_file = wal.get_image(args.i) - colors_plain = wal.create_palette(img=image_file, quiet=args.q) + colors_plain = wal.create_palette(img=image_file, notify=not args.q) elif args.f: colors_plain = util.read_file_json(args.f) @@ -96,7 +95,6 @@ def process_args(args): def main(): """Main script function.""" - util.create_dir(wal.CACHE_DIR / "schemes") args = get_args() process_args(args) diff --git a/pywal/reload.py b/pywal/reload.py index 77a496a..66fdea9 100644 --- a/pywal/reload.py +++ b/pywal/reload.py @@ -10,7 +10,9 @@ from pywal import util def reload_xrdb(cache_dir): """Merge the colors into the X db so new terminals use them.""" if shutil.which("xrdb"): - subprocess.call(["xrdb", "-merge", cache_dir / "colors.Xresources"]) + subprocess.call(["xrdb", "-merge", cache_dir / "colors.Xresources"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) def reload_i3(): diff --git a/pywal/util.py b/pywal/util.py index b109744..6338989 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -71,12 +71,16 @@ def read_file_raw(input_file): 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) @@ -107,10 +111,10 @@ def disown(*cmd): preexec_fn=os.setpgrp) -def msg(input_msg, quiet): +def msg(input_msg, notify): """Print to the terminal and display a libnotify notification.""" - if not quiet: + if notify: disown("notify-send", input_msg) print(input_msg) diff --git a/pywal/wal.py b/pywal/wal.py index 695645a..e9e3e85 100644 --- a/pywal/wal.py +++ b/pywal/wal.py @@ -25,9 +25,9 @@ def get_image(img, cache_dir=CACHE_DIR): def create_palette(img, cache_dir=CACHE_DIR, - color_count=COLOR_COUNT, quiet=True): + color_count=COLOR_COUNT, notify=False): """Create a palette and return it as a dict.""" - return magic.get_colors(img, cache_dir, color_count, quiet) + return magic.get_colors(img, cache_dir, color_count, notify) def send_sequences(colors, vte, cache_dir=CACHE_DIR): |
