api: Cleanup

This commit is contained in:
Dylan Araps 2017-07-22 11:19:17 +10:00
parent 7d1fc8d4d3
commit a34a9c5977
4 changed files with 16 additions and 12 deletions

View File

@ -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)

View File

@ -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():

View File

@ -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)

View File

@ -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):