From 9f4f301ba8f4a85a3c3819251c97cc844916cfd9 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Mon, 20 Apr 2026 15:14:18 +0200 Subject: [PATCH] made cssh more user friendly by using argparse to parse its arguments fixes [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=4366] --- home/bin/make_color.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/home/bin/make_color.py b/home/bin/make_color.py index 8db94c9..22646c1 100755 --- a/home/bin/make_color.py +++ b/home/bin/make_color.py @@ -1,9 +1,9 @@ #!/usr/bin/env python # this program generates a color value by hashing the input string -import sys from colorsys import hsv_to_rgb from hashlib import md5 +import argparse def float_to_16b(component): @@ -28,17 +28,26 @@ def hsv_to_linux(hue, saturation, value): if __name__ == '__main__': - seed_string = sys.argv[1] + + parser = argparse.ArgumentParser(description="Generate a rgb color by hashing the input string", epilog="Example usage: make_color.py cloud.ipr.univ-rennes.fr 0.7 0.5 linux") + parser.add_argument("seed_string", type=str, help="the string to be hashed to generate the pseudo random hue of the color") + parser.add_argument("color_value", type=float, help="the value (luminance) of the color between 0.0 and 1.0") + parser.add_argument("color_saturation", type=float, help="the saturation of the color between 0.0 and 1.0") + parser.add_argument("rgb_string_format", type=str, choices=['osx', 'linux'], help="the format of the output color string ('osx' for '{r:d16, g:d16, b:d16}' or 'linux' for '(r:d8, g:d8, b:d8)'") + + args = parser.parse_args() + + seed_string = args.seed_string # print('seed_string = ', seed_string) - color_value = float(sys.argv[2]) - color_saturation = float(sys.argv[3]) - string_format = sys.argv[4] # eg 'osx' 'linux' + color_value = args.color_value + color_saturation = args.color_saturation + rgb_string_format = args.rgb_string_format # eg 'osx' 'linux' # color_hue = int(md5(seed_string).hexdigest()[:8], 16) # taken from http://www.guguncube.com/3237/python-string-to-number-hash color_hue = float(int(md5(seed_string.encode('utf-8')).hexdigest(), 16) % 100000) / 100000.0 # print(color_hue) - if string_format == 'osx': + if rgb_string_format == 'osx': print(hsv_to_osx(color_hue, color_saturation, color_value)) - if string_format == 'linux': + if rgb_string_format == 'linux': print(hsv_to_linux(color_hue, color_saturation, color_value))