Skip to content

Commit

Permalink
Add cli: create a quiet log output
Browse files Browse the repository at this point in the history
  • Loading branch information
Wabri committed Aug 1, 2020
1 parent 193a295 commit 538f25a
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
-h, --help print this help and exit
Logging:
-q, --quiet quiet (no output) [TODO]
-q, --quiet quiet (no output)
-l=FILE, --log=FILE create a log file [TODO]
I/O Images:
-i=FILE, --img=FILE specify input image name
Expand Down Expand Up @@ -53,6 +55,7 @@

BLACK_REPLACE = "2E3440"
DEFAULT_EX = ".png"
QUIET_MODE = False


def is_colors_selected(selection, color_name):
Expand All @@ -78,6 +81,28 @@ def is_colors_selected(selection, color_name):
return True


def log(string):
"""<Short Description>
<Description>
Parameters
----------
<argument name>: <type>
<argument description>
<argument>: <type>
<argument description>
Returns
-------
<type>
<description>
"""
if QUIET_MODE:
return
print(string)


if __name__ == '__main__':
signal(SIGINT, signal_handler)
args = sys.argv[1:]
Expand All @@ -91,6 +116,8 @@ def is_colors_selected(selection, color_name):
print(__doc__)
sys.exit(0)

QUIET_MODE = "-q" in args or "--quiet" in args

# Get absolute path of source project
src_path = path.dirname(path.realpath(__file__))

Expand All @@ -110,38 +137,38 @@ def is_colors_selected(selection, color_name):
if "--{}".format(palette) in key:

if len(key_value) == 1:
print("Use all {} color set".format(palette.capitalize()))
log("Use all {} color set".format(palette.capitalize()))
palette_set = load_palette_set(palette_path)
for colors_name in palette_set:
colors_palette = import_palette_from_file(
palette_path + colors_name + ".txt")
colors_set = create_data_colors(colors_palette)
palettedata.extend(colors_set)
else:
print("Use {} palette".format(palette.capitalize()))
log("Use {} palette".format(palette.capitalize()))
selected_colors = key_value[1].split(",")
palette_set = load_palette_set(palette_path)
for selected_color_set in selected_colors:
for colors_name in palette_set:
if is_colors_selected(selected_color_set, colors_name):
print("Selected {} as {}".format(
log("Selected {} as {}".format(
selected_color_set, colors_name))
colors_palette = import_palette_from_file(
palette_path + colors_name + ".txt")
colors_set = create_data_colors(colors_palette)
palettedata.extend(colors_set)
if len(palettedata) == 0:
print("No colors set correctly given!")
print("Exit!")
log("No colors set correctly given!")
log("Exit!")

is_image = key in ("--img" or "-i")
IMAGE_PATTERN = r'([A-z]|[\/|\.|\-|\_|\s])*\.([a-z]{3}|[a-z]{4})$'
if is_image:
if len(key_value) > 1 and (re.search(IMAGE_PATTERN, key_value[1]) is not None):
input_image = key_value[1]
print("Load image {}".format(src_path + "/" + input_image))
log("Load image {}".format(src_path + "/" + input_image))
else:
print("You need to pass the image path!")
log("You need to pass the image path!")
sys.exit(1)
continue
del is_image
Expand All @@ -153,10 +180,10 @@ def is_colors_selected(selection, color_name):
# If the image name have already an extension do not set the default one
output_image_name += "" if re.search(
IMAGE_PATTERN, output_image_name) else DEFAULT_EX
print("Output image {}".format(
log("Output image {}".format(
src_path + "/" + output_image_name))
else:
print("No output filename specify within the arguments!")
log("No output filename specify within the arguments!")
continue

sys.exit(0)
Expand Down

0 comments on commit 538f25a

Please sign in to comment.