def step__test(**kargs): config, config_path, test_port = itemgetter('config', 'config_path', 'test_port')(kargs) if is_no(input('Do you want to test if everything works? [Y/n]: ')): return current_port = config.get('server.port') replace_hocon_value(config_path, 'server.port', test_port) print(f'Port set to {test_port}, come back once you are done testing') print( "If the colors are weird, run the image through the fiddle to convert the colors. Play around with the settings until it looks good." ) print( "If the above doesn't fix it, double check the board information in pxls.conf." ) print( "You can run this script again with the `--step N` parameter where N is the step number from which restart the script" ) print("Or you can try fixing the settings manually") print() input( "Once you are ready, close the server and press enter to set the port back." ) replace_hocon_value(config_path, 'server.port', current_port)
def step__set_canvas_dimensions(**kargs): config, config_path = itemgetter('config', 'config_path')(kargs) for k in ('width', 'height'): old = config.get(f'board.{k}') new = None while new is None: new_input = input(f'New {k} [{old}]: ') if len(new_input) == 0: new = old else: try: new = int(new_input) except ValueError: print('Dimensions is not an integer') replace_hocon_value(config_path, k, new)
def step__update_palette(**kargs): config, config_path = itemgetter('config', 'config_path')(kargs) if not is_yes(input('Update palette colors? [y/N]: ')): return color_regex = re.compile(r'^#[a-f0-9]{6}$', re.IGNORECASE) palette = config.get('board.palette') new_palette = None while new_palette is None: try: new_palette = json_loads(input('Paste Palette array: ')) if type(new_palette) != list or any( type(v) != str or not color_regex.match(v) for v in new_palette): new_palette = None raise Exception('Invalid array format') palette = new_palette except: print( 'Invalid array format. Array must be in the format: \'["#000000", "#FF0000", ...]\'' ) replace_hocon_value(config_path, 'board.palette', new_palette) print('Palette updated') if not is_yes(input('Update default color index? [y/N]: ')): return new_default_color = None while new_default_color is None: try: new_default_color = int(input('New default color index: ')) if new_default_color < 0 or new_default_color >= len(palette): new_default_color = None print('Default color index out of range') except ValueError: print('New default color index is not an integer') replace_hocon_value(config_path, 'board.defaultColor', new_default_color) print('Default color index updated')
def step__set_canvas_code(**kargs): config, config_path, current = itemgetter('config', 'config_path', 'prev_canvas_code')(kargs) suggested = None try: suggested = str(int(current) + 1) except ValueError: pass new = None while new is None: new = input( f"New canvas code?{' [' + suggested + ']' if suggested else ''}: {current} -> " ) if len(new) == 0: new = suggested # None if suggestion couldn't be determined elif new == '-': new = current replace_hocon_value(config_path, 'canvascode', new)