Ejemplo n.º 1
0
    def _migrate_asset_defaults(self):
        # convert asset_defaults to assets:
        if 'asset_defaults' in self.fc:
            self.log.debug('Renaming key: asset_defaults -> assets:')
            YamlRoundtrip.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:")
                    YamlRoundtrip.copy_with_comments(assets, 'animations',
                                                     assets, 'images',
                                                     True, self.log)
                else:
                    YamlRoundtrip.rename_key('animations', 'images', assets,
                                             self.log)
                YamlRoundtrip.del_key_with_comments(self.fc, 'animations',
                                                    self.log)

            if 'movies' in assets:
                YamlRoundtrip.rename_key('movies', 'videos', assets, self.log)

            if 'images' in assets:
                self.log.debug("Converting assets:images:")

                for settings in assets['images'].values():
                    YamlRoundtrip.del_key_with_comments(settings, 'target',
                                                        self.log)

            if 'sounds' in assets:
                self.log.debug("Converting assets:sounds:")
Ejemplo n.º 2
0
    def _remove_key(self, first_key, key):
        # actually removes the key from the dict, with nested dicts only
        # (no lists in there)

        if not key:  # single item
            if first_key in self.fc:

                YamlRoundtrip.del_key_with_comments(self.fc, first_key,
                                                    self.log)
                return True

        try:
            if self.fc[first_key].mlget(key, list_ok=True) is not None:
                # mlget just verifies with a nested dict / list
                # index that the key is found.
                final_key = key.pop(-1)
                dic = self.fc[first_key]

                while key:
                    # Loop to get the parent container of the
                    # lowest level key
                    dic = dic[key.pop(0)]

                YamlRoundtrip.del_key_with_comments(dic, final_key, self.log)
                return True
        except (KeyError, IndexError):
            pass

        return False
Ejemplo n.º 3
0
    def _create_window_slide(self):
        if 'window' in self.fc and 'elements' in self.fc['window']:
            elements = self.fc['window']['elements']

            if isinstance(elements, dict):
                elements = [elements]

            if 'slides' not in self.fc:
                self.log.debug("Creating 'slides:' section")
                self.fc['slides'] = CommentedMap()

            slide_name = V4Migrator._get_slide_name('window')

            self.log.debug("Creating slide: %s with %s display widget(s) from "
                           "the old window: config", slide_name, len(elements))

            self.log.debug("Adding '%s' slide", slide_name)
            self.fc['slides'][slide_name] = CommentedMap()
            self.fc['slides'][slide_name] = (
                self._migrate_elements(elements, 'window'))

            YamlRoundtrip.del_key_with_comments(self.fc['window'], 'elements',
                                                self.log)

            if 'slide_player' not in self.fc:
                self.fc['slide_player'] = CommentedMap()
                self.log.debug("Creating slide_player: section")

            self.log.debug("Creating slide_player:machine_reset_phase3: entry"
                           "to show slide '%s' on boot", slide_name)
            self.fc['slide_player']['machine_reset_phase_3'] = CommentedMap()
            self.fc['slide_player']['machine_reset_phase_3'][slide_name] = \
                CommentedMap()
            self.fc['slide_player']['machine_reset_phase_3'][slide_name][
                'target'] = 'window'
Ejemplo n.º 4
0
 def _migrate_layer(self, element):
     # Migrate layer
     YamlRoundtrip.rename_key('layer', 'z', element, self.log)
     YamlRoundtrip.rename_key('h_pos', 'anchor_x', element, self.log)
     YamlRoundtrip.rename_key('v_pos', 'anchor_y', element, self.log)
     YamlRoundtrip.rename_key('font', 'style', element, self.log)
     YamlRoundtrip.rename_key('shade', 'brightness', element, self.log)
     YamlRoundtrip.del_key_with_comments(element, 'pixel_spacing', self.log)
     YamlRoundtrip.del_key_with_comments(element, 'antialias', self.log)
     YamlRoundtrip.del_key_with_comments(element, 'thickness', self.log)
     YamlRoundtrip.del_key_with_comments(element, 'bg_shade', self.log)
     YamlRoundtrip.del_key_with_comments(element, 'slide', self.log)
     return element
Ejemplo n.º 5
0
    def _migrate_mode_timers(self):
        if 'timers' in self.fc:
            for timer_name in self.fc['timers']:
                if "start_paused" in self.fc['timers'][timer_name]:
                    if not self.fc['timers'][timer_name]['start_paused']:
                        self.fc['timers'][timer_name]["start_running"] = True
                    elif ("start_running" not in self.fc['timers'][timer_name] or
                            not self.fc['timers'][timer_name]["start_running"]):
                        self.fc['timers'][timer_name]["start_running"] = False
                    else:
                        raise ValueError("Both start_paused and start_running are true. This is impossible")

                    YamlRoundtrip.del_key_with_comments(self.fc['timers'][timer_name], 'start_paused', self.log)
Ejemplo n.º 6
0
    def _migrate_element_x_and_anchor(self, element, display, width):
        if 'x' in element:
            old_x = element['x']
        else:
            old_x = 'None'

        if 'anchor_x' not in element and 'x' in element:
            element['anchor_x'] = 'left'

        try:
            if 'anchor_x' not in element or element['anchor_x'] == 'left':
                element['x'] = self._format_anchor_and_value(
                    'left', element['x'])

            elif element['anchor_x'] in ('middle', 'center'):
                element['x'] = self._format_anchor_and_value(
                    'center', element['x'])

            elif element['anchor_x'] == 'right':
                element['x'] = self._format_anchor_and_value(
                    'right', element['x'])

            self.log.debug(
                "Changing x:%s to x:%s (Based on anchor_x:%s"
                "and %s width:%s)", old_x, element['x'], element['anchor_x'],
                display, width)

        except KeyError:
            pass

        try:
            if element['anchor_x'] in ('middle', 'center'):
                YamlRoundtrip.del_key_with_comments(element, 'anchor_x',
                                                    self.log)
        except KeyError:
            pass

        if ('anchor_x' in element and 'x' not in element
                and element['anchor_x'] != 'center'):
            element['x'] = element['anchor_x']
        return element
Ejemplo n.º 7
0
    def _migrate_element_y_and_anchor(self, element, display, height):
        if 'y' in element:
            old_y = element['y']
            element['y'] *= -1
        else:
            old_y = 'None'

        if 'anchor_y' not in element and 'y' in element:
            element['anchor_y'] = 'top'

        try:
            if 'anchor_y' not in element or element['anchor_y'] == 'bottom':
                element['y'] = self._format_anchor_and_value(
                    'bottom', element['y'])
            elif element['anchor_y'] in ('middle', 'center'):
                element['y'] = self._format_anchor_and_value(
                    'middle', element['y'])
            elif element['anchor_y'] == 'top':
                element['y'] = self._format_anchor_and_value(
                    'top', element['y'])

            self.log.debug(
                "Changing y:%s to y:%s (Based on anchor_y:%s"
                "and %s height:%s)", old_y, element['y'], element['anchor_y'],
                display, height)

        except KeyError:
            pass

        try:
            if element['anchor_y'] in ('middle', 'center'):
                YamlRoundtrip.del_key_with_comments(element, 'anchor_y',
                                                    self.log)

        except KeyError:
            pass

        if ('anchor_y' in element and 'y' not in element
                and element['anchor_y'] != 'middle'):
            element['y'] = element['anchor_y']
        return element
Ejemplo n.º 8
0
    def _migrate_assets(self, section_name):
        if section_name in self.fc:

            keys_to_keep = set(self.mpf_config_spec[section_name].keys())
            empty_entries = set()

            self.log.debug("Converting %s: section", section_name)

            if self.fc[section_name]:

                for name, settings in self.fc[section_name].items():
                    self.log.debug("Converting %s:%s:", section_name, name)
                    if isinstance(settings, dict):
                        keys = set(settings.keys())
                        keys_to_remove = keys - keys_to_keep

                        for key in keys_to_remove:
                            YamlRoundtrip.del_key_with_comments(settings, key,
                                                                self.log)

                    if not settings:
                        self.log.debug("%s:%s: is now empty. Will remove it.",
                                       section_name, name)
                        empty_entries.add(name)

                for name in empty_entries:
                    YamlRoundtrip.del_key_with_comments(self.fc[section_name],
                                                        name, self.log)

            if not self.fc[section_name]:
                self.log.debug("%s: is now empty. Will remove it.",
                               section_name)
                YamlRoundtrip.del_key_with_comments(self.fc, section_name,
                                                    self.log)
Ejemplo n.º 9
0
    def _migrate_light_player(self):
        # light_player: section in v3 was used for both playing light scripts
        # and playing shows

        if 'light_player' not in self.fc:
            return

        self.log.debug("Migrating light_player: section")

        for event, actions in self.fc['light_player'].items():
            if not isinstance(actions, list):
                actions = [actions]
            this_events_shows = CommentedMap()

            for dummy_i, action in enumerate(actions):

                if 'show' in action:
                    show_name = action.pop('show')

                elif 'script' in action:
                    show_name = action.pop('script')

                elif 'key' in action:
                    show_name = action.pop('key')

                else:
                    continue

                if 'action' in action and action['action'] == 'start':
                    del action['action']

                this_events_shows[show_name] = action

            self._add_to_show_player(event, this_events_shows)

        YamlRoundtrip.del_key_with_comments(self.fc, 'light_player', self.log)
Ejemplo n.º 10
0
    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':
            YamlRoundtrip.rename_key('size', 'font_size', element, self.log)

        if element_type != 'dmd':
            YamlRoundtrip.del_key_with_comments(element, 'bg_color', self.log)

        if element_type == 'virtualdmd' and V4Migrator.color_dmd:
            YamlRoundtrip.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:
            YamlRoundtrip.rename_key('movie', 'video', element, self.log)

            if 'repeat' in element:  # indented on purpose
                YamlRoundtrip.rename_key('repeat', 'loop', element, self.log)
            if 'loops' in element:  # indented on purpose
                YamlRoundtrip.rename_key('loops', 'loop', element, self.log)

        self._convert_tokens(element)

        return element
Ejemplo n.º 11
0
    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")

            YamlRoundtrip.del_key_with_comments(self.fc['dmd'], 'physical',
                                                self.log)
            YamlRoundtrip.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
                YamlRoundtrip.del_key_with_comments(self.fc['dmd'], 'type',
                                                    self.log)
                YamlRoundtrip.rename_key('dmd', 'physical_rgb_dmd', self.fc,
                                         self.log)

            else:  # physical mono DMD
                YamlRoundtrip.del_key_with_comments(self.fc['dmd'], 'type',
                                                    self.log)

                YamlRoundtrip.rename_key('dmd', 'physical_dmd', self.fc,
                                         self.log)

            YamlRoundtrip.del_key_with_comments(self.fc['displays']['dmd'],
                                                'physical', self.log)
            YamlRoundtrip.del_key_with_comments(self.fc['displays']['dmd'],
                                                'shades', self.log)
            YamlRoundtrip.del_key_with_comments(self.fc['displays']['dmd'],
                                                'fps', self.log)