summaryrefslogtreecommitdiff
path: root/pywal
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-07-22 09:46:45 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-07-22 09:46:45 +1000
commit12f9211cd4a255226d151545e0532c8507af7361 (patch)
treed85086cbdd39709dbf43455b4136f4f3ad3404da /pywal
parent97de3110de378856e04ce17d41a8d75935b28767 (diff)
general: Remove comments that just repeat what the code does.
Diffstat (limited to 'pywal')
-rw-r--r--pywal/__main__.py10
-rw-r--r--pywal/export.py24
-rw-r--r--pywal/image.py2
-rw-r--r--pywal/magic.py18
-rw-r--r--pywal/sequences.py2
-rw-r--r--pywal/util.py15
6 files changed, 16 insertions, 55 deletions
diff --git a/pywal/__main__.py b/pywal/__main__.py
index 3a47a8a..92e3d4b 100644
--- a/pywal/__main__.py
+++ b/pywal/__main__.py
@@ -16,7 +16,6 @@ def get_args():
description = "wal - Generate colorschemes on the fly"
arg = argparse.ArgumentParser(description=description)
- # Add the args.
arg.add_argument("-c", action="store_true",
help="Delete all cached colorschemes.")
@@ -51,7 +50,6 @@ def get_args():
def process_args(args):
"""Process args."""
- # If no args were passed.
if not len(sys.argv) > 1:
print("error: wal needs to be given arguments to run.\n"
" Refer to \"wal -h\" for more info.")
@@ -62,34 +60,27 @@ def process_args(args):
" Refer to \"wal -h\" for more info.")
exit(1)
- # -q
if args.q:
sys.stdout = sys.stderr = open(os.devnull, "w")
- # -c
if args.c:
shutil.rmtree(wal.CACHE_DIR / "schemes")
util.create_dir(wal.CACHE_DIR / "schemes")
- # -r
if args.r:
wal.reload_colors(args.t)
- # -v
if args.v:
print(f"wal {wal.__version__}")
exit(0)
- # -i
if args.i:
image_file = wal.get_image(args.i)
colors_plain = wal.create_palette(img=image_file, quiet=args.q)
- # -f
elif args.f:
colors_plain = util.read_file_json(args.f)
- # -i or -f
if args.i or args.f:
wal.send_sequences(colors_plain, args.t)
@@ -99,7 +90,6 @@ def process_args(args):
wal.export_all_templates(colors_plain)
wal.reload_env()
- # -o
if args.o:
util.disown(args.o)
diff --git a/pywal/export.py b/pywal/export.py
index 06ad215..1dc72bf 100644
--- a/pywal/export.py
+++ b/pywal/export.py
@@ -9,37 +9,21 @@ from pywal import util
def template(colors, input_file, output_dir):
"""Read template file, substitute markers and
save the file elsewhere."""
- # Import the template.
- with open(input_file) as file:
- template_data = file.readlines()
-
- # Format the markers.
+ template_data = util.read_file_raw(input_file)
template_data = "".join(template_data).format(**colors)
-
- # Get the template name.
- template_file = os.path.basename(input_file)
-
- # Export the template.
- output_file = output_dir / template_file
- util.save_file(template_data, output_file)
-
- print(f"export: Exported {template_file}.")
+ template_name = os.path.basename(input_file)
+ util.save_file(template_data, output_dir / template_name)
+ print(f"export: Exported {template_name}.")
def export_all_templates(colors, output_dir, template_dir=None):
"""Export all template files."""
- # Add the template dir to module path.
template_dir = template_dir or \
os.path.join(os.path.dirname(__file__), "templates")
- # Merge all colors (specials and normals) into one dict so we can access
- # their values simpler.
all_colors = {"wallpaper": colors["wallpaper"],
**colors["special"],
**colors["colors"]}
-
- # Turn all those colors into util.Color instances for accessing the
- # .hex and .rgb formats
all_colors = {k: util.Color(v) for k, v in all_colors.items()}
# pylint: disable=W0106
diff --git a/pywal/image.py b/pywal/image.py
index 43bc7b5..a7a314d 100644
--- a/pywal/image.py
+++ b/pywal/image.py
@@ -16,12 +16,10 @@ def get_random_image(img_dir, cache_dir):
current_wall = util.read_file(current_wall)
current_wall = os.path.basename(current_wall[0])
- # Add all images to a list excluding the current wallpaper.
file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
images = [img for img in os.scandir(img_dir)
if img.name.endswith(file_types) and img.name != current_wall]
- # If no images are found, use the current wallpaper.
if not images:
print("image: No new images found (nothing to do), exiting...")
quit(1)
diff --git a/pywal/magic.py b/pywal/magic.py
index 9dc528c..5768c71 100644
--- a/pywal/magic.py
+++ b/pywal/magic.py
@@ -5,7 +5,6 @@ import re
import shutil
import subprocess
-# from pywal.settings import color_count
from pywal import util
@@ -21,17 +20,13 @@ def imagemagick(color_count, img):
def gen_colors(img, color_count):
"""Format the output from imagemagick into a list
of hex colors."""
- # Check if the user has Imagemagick installed.
if not shutil.which("convert"):
print("error: imagemagick not found, exiting...\n"
"error: wal requires imagemagick to function.")
exit(1)
- # Generate initial scheme.
raw_colors = imagemagick(color_count, img)
- # If imagemagick finds less than 16 colors, use a larger source number
- # of colors.
index = 0
while len(raw_colors) - 1 < color_count:
index += 1
@@ -46,19 +41,16 @@ def gen_colors(img, color_count):
"for the image. Exiting...")
quit(1)
- # Remove the first element, which isn't a color.
+ # Remove the first element because it isn't a color code.
del raw_colors[0]
- # Create a list of hex colors.
return [re.search("#.{6}", str(col)).group(0) for col in raw_colors]
def get_colors(img, cache_dir, color_count, quiet):
"""Get the colorscheme."""
- # Cache the wallpaper name.
util.save_file(img, cache_dir / "wal")
- # Cache the sequences file.
# _home_dylan_img_jpg.json
cache_file = cache_dir / "schemes" / \
img.replace("/", "_").replace(".", "_")
@@ -71,11 +63,9 @@ def get_colors(img, cache_dir, color_count, quiet):
else:
util.msg("wal: Generating a colorscheme...", quiet)
- # Generate the colors.
colors = gen_colors(img, color_count)
colors = sort_colors(img, colors)
- # Cache the colorscheme.
util.save_file_json(colors, cache_file)
util.msg("wal: Generation complete.", quiet)
@@ -87,24 +77,18 @@ def sort_colors(img, colors):
we will later save in json format."""
raw_colors = colors[:1] + colors[9:] + colors[8:]
- # Wallpaper.
colors = {"wallpaper": img}
- # Special colors.
colors_special = {}
colors_special.update({"background": raw_colors[0]})
colors_special.update({"foreground": raw_colors[15]})
colors_special.update({"cursor": raw_colors[15]})
- # Colors 0-15.
colors_hex = {}
[colors_hex.update({f"color{index}": color}) # pylint: disable=W0106
for index, color in enumerate(raw_colors)]
-
- # Color 8.
colors_hex["color8"] = util.set_grey(raw_colors)
- # Add the colors to a dict.
colors["special"] = colors_special
colors["colors"] = colors_hex
diff --git a/pywal/sequences.py b/pywal/sequences.py
index 7533f19..d7f1fa9 100644
--- a/pywal/sequences.py
+++ b/pywal/sequences.py
@@ -40,7 +40,6 @@ def send_sequences(colors, vte, cache_dir):
if not vte:
sequences.append(set_special(708, colors["special"]["background"]))
- # Get the list of terminals.
terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/")
if len(term) < 4]
terminals.append(cache_dir / "sequences")
@@ -48,7 +47,6 @@ def send_sequences(colors, vte, cache_dir):
# Send the sequences to all open terminals.
# pylint: disable=W0106
[util.save_file("".join(sequences), term) for term in terminals]
-
print("colors: Set terminal colors")
diff --git a/pywal/util.py b/pywal/util.py
index 1030b60..0891feb 100644
--- a/pywal/util.py
+++ b/pywal/util.py
@@ -44,24 +44,31 @@ 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."""
with open(export_file, "w") as file: