mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-18 07:36:41 +02:00
api: Cleanup
This commit is contained in:
parent
7d1fc8d4d3
commit
a34a9c5977
@ -60,23 +60,22 @@ def process_args(args):
|
|||||||
" Refer to \"wal -h\" for more info.")
|
" Refer to \"wal -h\" for more info.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
if args.v:
|
||||||
|
print(f"wal {wal.__version__}")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
if args.q:
|
if args.q:
|
||||||
sys.stdout = sys.stderr = open(os.devnull, "w")
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
|
|
||||||
if args.c:
|
if args.c:
|
||||||
shutil.rmtree(wal.CACHE_DIR / "schemes")
|
shutil.rmtree(wal.CACHE_DIR / "schemes")
|
||||||
util.create_dir(wal.CACHE_DIR / "schemes")
|
|
||||||
|
|
||||||
if args.r:
|
if args.r:
|
||||||
wal.reload_colors(args.t)
|
wal.reload_colors(args.t)
|
||||||
|
|
||||||
if args.v:
|
|
||||||
print(f"wal {wal.__version__}")
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
if args.i:
|
if args.i:
|
||||||
image_file = wal.get_image(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:
|
elif args.f:
|
||||||
colors_plain = util.read_file_json(args.f)
|
colors_plain = util.read_file_json(args.f)
|
||||||
@ -96,7 +95,6 @@ def process_args(args):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main script function."""
|
"""Main script function."""
|
||||||
util.create_dir(wal.CACHE_DIR / "schemes")
|
|
||||||
args = get_args()
|
args = get_args()
|
||||||
process_args(args)
|
process_args(args)
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ from pywal import util
|
|||||||
def reload_xrdb(cache_dir):
|
def reload_xrdb(cache_dir):
|
||||||
"""Merge the colors into the X db so new terminals use them."""
|
"""Merge the colors into the X db so new terminals use them."""
|
||||||
if shutil.which("xrdb"):
|
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():
|
def reload_i3():
|
||||||
|
@ -71,12 +71,16 @@ def read_file_raw(input_file):
|
|||||||
|
|
||||||
def save_file(data, export_file):
|
def save_file(data, export_file):
|
||||||
"""Write data to a file."""
|
"""Write data to a file."""
|
||||||
|
create_dir(os.path.dirname(export_file))
|
||||||
|
|
||||||
with open(export_file, "w") as file:
|
with open(export_file, "w") as file:
|
||||||
file.write(data)
|
file.write(data)
|
||||||
|
|
||||||
|
|
||||||
def save_file_json(data, export_file):
|
def save_file_json(data, export_file):
|
||||||
"""Write data to a json file."""
|
"""Write data to a json file."""
|
||||||
|
create_dir(os.path.dirname(export_file))
|
||||||
|
|
||||||
with open(export_file, "w") as file:
|
with open(export_file, "w") as file:
|
||||||
json.dump(data, file, indent=4)
|
json.dump(data, file, indent=4)
|
||||||
|
|
||||||
@ -107,10 +111,10 @@ def disown(*cmd):
|
|||||||
preexec_fn=os.setpgrp)
|
preexec_fn=os.setpgrp)
|
||||||
|
|
||||||
|
|
||||||
def msg(input_msg, quiet):
|
def msg(input_msg, notify):
|
||||||
"""Print to the terminal and display a libnotify
|
"""Print to the terminal and display a libnotify
|
||||||
notification."""
|
notification."""
|
||||||
if not quiet:
|
if notify:
|
||||||
disown("notify-send", input_msg)
|
disown("notify-send", input_msg)
|
||||||
|
|
||||||
print(input_msg)
|
print(input_msg)
|
||||||
|
@ -25,9 +25,9 @@ def get_image(img, cache_dir=CACHE_DIR):
|
|||||||
|
|
||||||
|
|
||||||
def create_palette(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."""
|
"""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):
|
def send_sequences(colors, vte, cache_dir=CACHE_DIR):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user