general: Remove duplicate code.

This commit is contained in:
Dylan Araps 2017-06-29 20:05:11 +10:00
parent d9a22726cb
commit 0834cd024b
2 changed files with 32 additions and 4 deletions

View File

@ -11,6 +11,7 @@ from pywal.settings import CACHE_DIR, __version__
from pywal import export_colors
from pywal import gen_colors
from pywal import set_colors
from pywal import reload
from pywal import wallpaper
from pywal import util
@ -94,15 +95,15 @@ def process_args(args):
if not args.n:
wallpaper.set_wallpaper(image)
# Set the colors.
set_colors.send_sequences(colors_plain, args.t)
export_colors.export_all_templates(colors_plain)
# -f
elif args.f:
colors_plain = util.read_file_json(args.f)
# -i or -f
if args.i or args.f:
set_colors.send_sequences(colors_plain, args.t)
export_colors.export_all_templates(colors_plain)
reload.reload_env()
# -o
if args.o:

27
pywal/reload.py Normal file
View File

@ -0,0 +1,27 @@
"""
Reload programs.
"""
import shutil
import subprocess
from pywal.settings import CACHE_DIR
from pywal import util
def reload_i3():
"""Reload i3 colors."""
if shutil.which("i3-msg"):
util.disown("i3-msg", "reload")
def reload_xrdb():
"""Merge the colors into the X db so new terminals use them."""
if shutil.which("xrdb"):
subprocess.call(["xrdb", "-merge", CACHE_DIR / "colors.Xresources"])
def reload_env():
"""Reload environment programs."""
reload_i3()
reload_xrdb()
print("reload: Reloaded environment.")