def _migrate_physical_dmd(self): if ('dmd' in self.fc and 'physical' in self.fc['dmd'] and self.fc['dmd']['physical']): self.log.debug("Converting physical dmd: settings") YamlInterface.del_key_with_comments(self.fc['dmd'], 'physical', self.log) YamlInterface.del_key_with_comments(self.fc['dmd'], 'fps', self.log) if 'type' in self.fc['dmd'] and self.fc['dmd']['type'] == 'color': # physical color DMD YamlInterface.del_key_with_comments(self.fc['dmd'], 'type', self.log) YamlInterface.rename_key('dmd', 'physical_rgb_dmd', self.fc, self.log) else: # physical mono DMD YamlInterface.del_key_with_comments(self.fc['dmd'], 'type', self.log) YamlInterface.rename_key('dmd', 'physical_dmd', self.fc, self.log) YamlInterface.del_key_with_comments(self.fc['displays']['dmd'], 'physical', self.log) YamlInterface.del_key_with_comments(self.fc['displays']['dmd'], 'shades', self.log) YamlInterface.del_key_with_comments(self.fc['displays']['dmd'], 'fps', self.log)
def _migrate_show_file(self): self.log.debug("Migrating show file: %s", self.file_name) show_name_stub = os.path.splitext(os.path.split(self.file_name)[1])[0] self._add_show_version() # Convert tocks to time self._convert_tocks_to_time(self.fc) # migrate the components in each step self.log.debug("Converting settings for each show step") slide_num = 0 for i, step in enumerate(self.fc): self._remove_tags(step) if 'display' in step: self.log.debug("Show step %s: Converting 'display' section", i + 1) found_transition = False for widget in step['display']: if 'transition' in widget: found_transition = True break if found_transition: step['display'] = CommentedMap( widgets=self._migrate_elements(step['display'])) for widget in step['display']['widgets']: self._convert_tokens(widget) if 'transition' in widget: YamlInterface.copy_with_comments( widget, 'transition', step['display'], 'transition', True, self.log) else: step['display'] = self._migrate_elements(step['display']) self._convert_tokens(step['display']) YamlInterface.rename_key('display', 'slides', step) slide_num += 1 old_slides = step['slides'] step['slides'] = CommentedMap() step['slides']['{}_slide_{}'.format(show_name_stub, slide_num)] = old_slides return True
def _recursive_rename(self, old, new, target): if isinstance(target, list): for item in target: self._recursive_rename(old, new, item) elif isinstance(target, dict): if old in target: YamlInterface.rename_key(old, new, target, self.log) for item in target.values(): self._recursive_rename(old, new, item)
def _migrate_shot_profiles(self): if 'shot_profiles' not in self.fc: return for settings in self.fc['shot_profiles'].values(): if 'states' in settings: for dummy_i, state_settings in enumerate(settings['states']): if 'loops' in state_settings and state_settings['loops']: state_settings['loops'] = -1 YamlInterface.rename_key('light_script', 'show', state_settings)
def _remove_tags(self, dic): found = False for v in dic.values(): if isinstance(v, dict): for k1 in v.keys(): if k1.startswith('tag|'): YamlInterface.rename_key(k1, k1.strip('tag|'), v) found = True break if found: self._remove_tags(dic)
def _migrate_layer(self, element): # Migrate layer YamlInterface.rename_key('layer', 'z', element, self.log) YamlInterface.rename_key('h_pos', 'anchor_x', element, self.log) YamlInterface.rename_key('v_pos', 'anchor_y', element, self.log) YamlInterface.rename_key('font', 'style', element, self.log) YamlInterface.rename_key('shade', 'brightness', element, self.log) YamlInterface.del_key_with_comments(element, 'pixel_spacing', self.log) YamlInterface.del_key_with_comments(element, 'antialias', self.log) YamlInterface.del_key_with_comments(element, 'thickness', self.log) YamlInterface.del_key_with_comments(element, 'bg_shade', self.log) YamlInterface.del_key_with_comments(element, 'slide', self.log) return element
def _migrate_animation_assets(self): if 'animations' in self.fc: self.log.debug("Converting assets:animations to assets:images") if 'images' in self.fc: self.log.debug("Merging animations: into current " "asset:images:") YamlInterface.copy_with_comments(self.fc, 'animations', self.fc, 'images', True, self.log) else: YamlInterface.rename_key('animations', 'images', self.fc, self.log)
def _migrate_fonts(self): # Fonts to widget_styles was already renamed, now update contents if 'widget_styles' in self.fc: self.log.debug("Converting widget_styles: from the old fonts: " "settings") for settings in self.fc['widget_styles'].values(): YamlInterface.rename_key('size', 'font_size', settings, self.log) YamlInterface.rename_key('file', 'font_name', settings, self.log) YamlInterface.rename_key('crop_top', 'adjust_top', settings, self.log) YamlInterface.rename_key('crop_bottom', 'adjust_bottom', settings, self.log) if 'font_name' in settings: self.log.debug("Converting font_name: from file to name") settings['font_name'] = os.path.splitext( settings['font_name'])[0] if self.base_name == V4Migrator.MAIN_CONFIG_FILE: if 'widget_styles' not in self.fc: self.log.debug("Creating old default font settings as " "widget_styles: section") self.fc['widget_styles'] = self._get_old_default_widget_styles() else: for k, v in self._get_old_default_widget_styles().items(): if k not in self.fc['widget_styles']: self.fc['widget_styles'][k] = v self.log.debug("Merging old built-in font settings '%s' " "into widget_styles: section", k)
def _migrate_animation(self, element): self.log.debug("Converting 'animation' display_element to animated " "'image' widget") element['type'] = 'image' YamlInterface.rename_key('play_now', 'auto_play', element, self.log) YamlInterface.rename_key('animation', 'image', element, self.log) element.pop('drop_frames', None) self.log.debug('Converting animated image loops: setting') if element['loops']: element['loops'] = -1 else: element['loops'] = 0 return element
def _migrate_switches(self): if 'switches' not in self.fc: return for switch_settings in self.fc['switches'].values(): YamlInterface.rename_key('activation_events', 'events_when_activated', switch_settings, self.log) YamlInterface.rename_key('deactivation_events', 'events_when_deactivated', switch_settings, self.log) if 'debounce' in switch_settings: if switch_settings['debounce']: switch_settings['debounce'] = 'normal' else: switch_settings['debounce'] = 'quick'
def _do_rename(self): for rename in self.renames: if len(rename['old']) > 1: # searching for nested key found_section = Util.get_from_dict(self.fc, rename['old'][:-1]) if not found_section: continue self.log.debug('Renaming key: %s: -> %s:', ':'.join(rename['old']), rename['new']) YamlInterface.rename_key(rename['old'][-1], rename['new'], found_section) else: # searching for a single key anywhere self._recursive_rename(rename['old'][0], rename['new'], self.fc)
def _do_lowercase(self, dic=None): # recurcisely converts all keys in dicts and nested dicts if not dic: dic = self.fc key_list = list(dic.keys()) for key in key_list: try: YamlInterface.rename_key(key, key.lower(), dic, self.log) except AttributeError: pass try: if isinstance(dic[key.lower()], dict): self._do_lowercase(dic[key.lower()]) except AttributeError: if isinstance(dic[key], dict): self._do_lowercase(dic[key])
def _convert_tocks_to_time(self, show_steps): self.log.debug('Converting "tocks:" to "time:" and cascading entries ' 'to the next step (since time: is for the current ' 'step versus tocks: being for the previous step)') previous_tocks = 0 for i, step in enumerate(show_steps): previous_tocks = step['tocks'] if not i: step['tocks'] = 0 else: step['tocks'] = '+{}'.format(previous_tocks) YamlInterface.rename_key('tocks', 'time', step, self.log) if len(show_steps) > 1: show_steps.append(CommentedMap()) show_steps[-1]['time'] = '+{}'.format(previous_tocks) return show_steps
def _migrate_light_scripts(self): if 'light_scripts' not in self.fc: return YamlInterface.rename_key('light_scripts', 'shows', self.fc, self.log) for show_contents in self.fc['shows'].values(): self._convert_tocks_to_time(show_contents) for step in show_contents: if 'color' in step: step['color'] = self._get_color(step['color']) if len(str(step['color'])) > 2: YamlInterface.rename_key('color', '(leds)', step, self.log) step['leds'] = CommentedMap() YamlInterface.copy_with_comments(step, '(leds)', step['leds'], '(leds)', True, self.log) else: YamlInterface.rename_key('color', '(lights)', step, self.log) step['lights'] = CommentedMap() YamlInterface.copy_with_comments(step, '(lights)', step['lights'], '(lights)', True, self.log)
def _migrate_asset_defaults(self): # convert asset_defaults to assets: if 'asset_defaults' in self.fc: self.log.debug('Renaming key: asset_defaults -> assets:') YamlInterface.rename_key('asset_defaults', 'assets', self.fc, self.log) assets = self.fc['assets'] if 'animations' in assets: self.log.debug("Converting assets:animations to assets:images") if 'images' in assets: self.log.debug("Merging animations: into current " "asset:images:") YamlInterface.copy_with_comments(assets, 'animations', assets, 'images', True, self.log) else: YamlInterface.rename_key('animations', 'images', assets, self.log) YamlInterface.del_key_with_comments(self.fc, 'animations', self.log) if 'movies' in assets: YamlInterface.rename_key('movies', 'videos', assets, self.log) if 'images' in assets: self.log.debug("Converting assets:images:") for settings in assets['images'].values(): YamlInterface.del_key_with_comments(settings, 'target', self.log) if 'sounds' in assets: self.log.debug("Converting assets:sounds:")
def _element_to_widget(self, element, display): # takes an element dict, returns a widget dict width, height = self._get_width_and_height_for_display(element, display) try: element_type = element['type'].lower() except KeyError: return False element = self._migrate_layer(element) type_map = dict(virtualdmd='dmd', text='text', shape='shape', animation='animation', image='image', movie='video', character_picker='character_picker', entered_chars='entered_chars') # Migrate the element type element['type'] = type_map[element_type] self.log.debug('Converting "%s" display_element to "%s" widget', element_type, element['type']) if element_type == 'text': YamlInterface.rename_key('size', 'font_size', element, self.log) if element_type != 'dmd': YamlInterface.del_key_with_comments(element, 'bg_color', self.log) if element_type == 'virtualdmd' and V4Migrator.color_dmd: YamlInterface.del_key_with_comments(element, 'pixel_color', self.log) self.log.debug('Changing widget type from "dmd" to "color_dmd"') element['type'] = 'color_dmd' element = self._migrate_element_x_and_anchor(element, display, height) element = self._migrate_element_y_and_anchor(element, display, width) if element_type == 'animation': element = self._migrate_animation(element) elif element_type == 'shape': element = self._migrate_shape(element) if 'decorators' in element: element = self._migrate_decorators(element, 'decorators', 'animations') if 'cursor_decorators' in element: element = self._migrate_decorators(element, 'cursor_decorators', 'cursor_animations') if 'color' in element: element['color'] = self._get_color(element['color']) if 'movie' in element: YamlInterface.rename_key('movie', 'video', element, self.log) if 'repeat' in element: # indented on purpose YamlInterface.rename_key('repeat', 'loop', element, self.log) if 'loops' in element: # indented on purpose YamlInterface.rename_key('loops', 'loop', element, self.log) self._convert_tokens(element) return element