예제 #1
0
    def from_dict(cls, collection, data, parent=None, **kwargs):
        if parent is None:
            raise ValueError('Missing required parameter: "parent"')

        touched = set()

        # Construct episode mapping
        episode_mapping = cls(
            collection,
            parent,

            # Identifier
            season=get_attribute(touched, data, 'season', parent.season),
            number=get_attribute(touched, data, 'number', parent.number))

        # Parse "timeline" attribute
        if 'timeline' in data:
            episode_mapping.timeline = dict([
                (k, Range.from_dict(collection, v)) for k, v in get_attribute(
                    touched, data, 'timeline', {}).items()
            ])

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched) if not k.startswith('_')
        ]

        if omitted:
            log.warn('EpisodeMapping.from_dict() omitted %d attribute(s): %s',
                     len(omitted), ', '.join(omitted))

        return episode_mapping
예제 #2
0
    def from_dict(cls, collection, data, **kwargs):
        touched = set()

        # Construct movie
        show = cls(collection,
                   identifiers=get_attribute(touched, data, 'identifiers'),
                   names=set(get_attribute(touched, data, 'names', [])),
                   supplemental=get_attribute(touched, data, 'supplemental',
                                              {}),
                   **get_attribute(touched, data, 'parameters', {}))

        # Construct seasons
        if 'seasons' in data:
            show.seasons = dict([
                (k, ModelRegistry['Season'].from_dict(collection,
                                                      v,
                                                      key=k,
                                                      parent=show))
                for k, v in get_attribute(touched, data, 'seasons').items()
            ])

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched) if not k.startswith('_')
        ]

        if omitted:
            log.warn('Show.from_dict() omitted %d attribute(s): %s',
                     len(omitted), ', '.join(omitted))

        return show
예제 #3
0
    def from_dict(cls, collection, data, **kwargs):
        touched = set()

        # Construct movie
        show = cls(
            collection,

            identifiers=get_attribute(touched, data, 'identifiers'),
            names=set(get_attribute(touched, data, 'names', [])),

            supplemental=get_attribute(touched, data, 'supplemental', {}),
            **get_attribute(touched, data, 'parameters', {})
        )

        # Construct seasons
        if 'seasons' in data:
            show.seasons = dict([
                (k, ModelRegistry['Season'].from_dict(collection, v, key=k, parent=show))
                for k, v in get_attribute(touched, data, 'seasons').items()
            ])

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched)
            if not k.startswith('_')
        ]

        if omitted:
            log.warn('Show.from_dict() omitted %d attribute(s): %s', len(omitted), ', '.join(omitted))

        return show
예제 #4
0
    def from_dict(cls, collection, data, parent=None, **kwargs):
        if parent is None:
            raise ValueError('Missing required parameter: "parent"')

        touched = set()

        # Construct episode mapping
        episode_mapping = cls(
            collection,
            parent,

            # Identifier
            season=get_attribute(touched, data, 'season', parent.season),
            number=get_attribute(touched, data, 'number', parent.number)
        )

        # Parse "timeline" attribute
        if 'timeline' in data:
            episode_mapping.timeline = dict([
                (k, Range.from_dict(collection, v))
                for k, v in get_attribute(touched, data, 'timeline', {}).items()
            ])

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched)
            if not k.startswith('_')
        ]

        if omitted:
            log.warn('EpisodeMapping.from_dict() omitted %d attribute(s): %s', len(omitted), ', '.join(omitted))

        return episode_mapping
예제 #5
0
    def from_dict(cls, collection, data, key=None, parent=None, **kwargs):
        if key is None:
            raise ValueError('Missing required parameter: "key"')

        if parent is None:
            raise ValueError('Missing required parameter: "parent"')

        touched = set()

        # Parse "names" attribute
        names = get_attribute(touched, data, 'names', [])

        if type(names) is list:
            names = set(names)

        # Construct season
        season = cls(
            collection,
            parent,
            key,

            identifiers=get_attribute(touched, data, 'identifiers'),
            names=names,

            supplemental=get_attribute(touched, data, 'supplemental', {}),
            **get_attribute(touched, data, 'parameters', {})
        )

        # Construct episodes
        if 'episodes' in data:
            def parse_episodes():
                for k, v in get_attribute(touched, data, 'episodes').items():
                    if type(v) is list:
                        yield k, [
                            ModelRegistry['Episode'].from_dict(collection, v_episode, key=k, parent=season)
                            for v_episode in v
                        ]
                    else:
                        yield k, ModelRegistry['Episode'].from_dict(collection, v, key=k, parent=season)

            season.episodes = dict(parse_episodes())

        # Construct mappings
        if 'mappings' in data:
            season.mappings = [
                ModelRegistry['SeasonMapping'].from_dict(collection, v, parent=season)
                for v in get_attribute(touched, data, 'mappings')
            ]

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched)
            if not k.startswith('_')
        ]

        if omitted:
            log.warn('Season.from_dict() omitted %d attribute(s): %s', len(omitted), ', '.join(omitted))

        return season
예제 #6
0
 def parse_episodes():
     for k, v in get_attribute(touched, data, 'episodes').items():
         if type(v) is list:
             yield k, [
                 ModelRegistry['Episode'].from_dict(collection, v_episode, key=k, parent=season)
                 for v_episode in v
             ]
         else:
             yield k, ModelRegistry['Episode'].from_dict(collection, v, key=k, parent=season)
예제 #7
0
    def from_dict(cls, collection, data, key=None, parent=None, **kwargs):
        if key is None:
            raise ValueError('Missing required parameter: "key"')

        if parent is None:
            raise ValueError('Missing required parameter: "parent"')

        touched = set()

        # Identifier
        number = get_attribute(touched, data, 'number')

        # Parse "names" attribute
        names = get_attribute(touched, data, 'names', [])

        if type(names) is list:
            names = set(names)

        # Construct part
        part = cls(
            collection,
            parent,
            key or number,

            identifiers=get_attribute(touched, data, 'identifiers'),
            names=names,

            supplemental=get_attribute(touched, data, 'supplemental', {}),
            **get_attribute(touched, data, 'parameters', {})
        )

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched)
            if not k.startswith('_')
        ]

        if omitted:
            log.warn('Part.from_dict() omitted %d attribute(s): %s', len(omitted), ', '.join(omitted))

        return part
예제 #8
0
    def from_dict(cls, collection, data, **kwargs):
        touched = set()

        # Construct episode mapping
        season_mapping = cls(
            collection,

            identifiers=get_attribute(touched, data, 'identifiers'),
            names=set(get_attribute(touched, data, 'names', [])),

            season=get_attribute(touched, data, 'season'),

            start=get_attribute(touched, data, 'start'),
            end=get_attribute(touched, data, 'end'),
            offset=get_attribute(touched, data, 'offset')
        )

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched)
            if not k.startswith('_')
        ]

        if omitted:
            log.warn('SeasonMapping.from_dict() omitted %d attribute(s): %s', len(omitted), ', '.join(omitted))

        return season_mapping
예제 #9
0
    def from_dict(cls, collection, data, key=None, parent=None, **kwargs):
        if key is None:
            raise ValueError('Missing required parameter: "key"')

        if parent is None:
            raise ValueError('Missing required parameter: "parent"')

        touched = set()

        # Identifier
        number = get_attribute(touched, data, 'number')

        # Parse "names" attribute
        names = get_attribute(touched, data, 'names', [])

        if type(names) is list:
            names = set(names)

        # Construct part
        part = cls(collection,
                   parent,
                   key or number,
                   identifiers=get_attribute(touched, data, 'identifiers'),
                   names=names,
                   supplemental=get_attribute(touched, data, 'supplemental',
                                              {}),
                   **get_attribute(touched, data, 'parameters', {}))

        # Ensure all attributes were touched
        omitted = [
            k for k in (set(data.keys()) - touched) if not k.startswith('_')
        ]

        if omitted:
            log.warn('Part.from_dict() omitted %d attribute(s): %s',
                     len(omitted), ', '.join(omitted))

        return part