fixed make_color.py to work on machines that don't have python2

work related to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=4405]
This commit is contained in:
Guillaume Raffy 2026-06-17 16:01:10 +02:00
parent 6bc44363de
commit 87a2d3ca22
1 changed files with 7 additions and 2 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# this program generates a color value by hashing the input string
from colorsys import hsv_to_rgb
from hashlib import md5
import argparse
import logging
def float_to_16b(component):
# print(hex_comp)
@ -28,6 +28,7 @@ def hsv_to_linux(hue, saturation, value):
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
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")
@ -44,6 +45,10 @@ if __name__ == '__main__':
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
# logging.debug(md5(seed_string.encode('utf-8')).hexdigest())
# logging.debug(int(md5(seed_string.encode('utf-8')).hexdigest(), 16))
# logging.debug(int(md5(seed_string.encode('utf-8')).hexdigest(), 16) % 100000)
# logging.debug('color_hue : %f', color_hue)
# print(color_hue)
if rgb_string_format == 'osx':