예제 #1
0
    def construct_topic(self, path, schema):
        topic = self.__topic_manager.find(path)

        if topic:
            updated = Topic(None, schema.name, schema.description,
                            topic.is_public, topic.info, None, None)

            self.__topic_manager.update(topic.path, updated)

        else:
            info = TopicInfo(TopicInfo.FORMAT_JSON, None, None,
                             None)  # for the v2 API, schema_id goes in Topic
            constructed = Topic(path, schema.name, schema.description, True,
                                info, True, schema.schema_id)

            self.__topic_manager.create(constructed)
예제 #2
0
파일: topic.py 프로젝트: motius/scs_core
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        # AbstractTopic...
        path = jdict.get('topic')
        name = jdict.get('name')
        description = jdict.get('description')

        is_public = jdict.get('public')

        info = TopicInfo.construct_from_jdict(jdict.get('topic-info'))

        # Topic...
        rollups_enabled = jdict.get('rollups-enabled')
        schema_id = jdict.get('schema-id')

        return Topic(path, name, description, is_public, info, rollups_enabled, schema_id)
예제 #3
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        # AbstractTopic...
        path = jdict.get('topic')
        name = jdict.get('name')
        description = jdict.get('description')

        is_public = jdict.get('public')

        info = TopicInfo.construct_from_jdict(jdict.get('topic-info'))

        # DerivedTopic...
        unit = jdict.get('unit')
        derived_data = DerivedData.construct_from_jdict(
            jdict.get('derived-data'))

        return DerivedTopic(path, name, description, is_public, info, unit,
                            derived_data)
예제 #4
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        # AbstractTopic...
        path = jdict.get('topic')
        name = jdict.get('name')
        description = jdict.get('description')

        is_public = jdict.get('public')

        info = TopicInfo.construct_from_jdict(jdict.get('topic-info'))

        # UserTopic...
        unit = jdict.get('unit')
        stats = TopicStats.construct_from_jdict(jdict.get('stats'))

        owner_gravatar_hash = jdict.get('owner-gravatar-hash')

        return UserTopic(path, name, description, is_public, info, unit, stats,
                         owner_gravatar_hash)
예제 #5
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        # AbstractTopic...
        path = jdict.get('topic')
        name = jdict.get('name')
        description = jdict.get('description')

        is_public = jdict.get('public')

        info = TopicInfo.construct_from_jdict(jdict.get('topic-info'))

        # TopicMetadata...
        if jdict.get('derived-topics'):
            derived_topics = [DerivedTopic.construct_from_jdict(dt_jdict) for dt_jdict in jdict.get('derived-topics')]
        else:
            derived_topics = []

        bookmark_count = jdict.get('bookmark-count')
        stats = TopicStats.construct_from_jdict(jdict.get('stats'))

        return TopicMetadata(path, name, description, is_public, info, derived_topics, bookmark_count, stats)
예제 #6
0
    # ----------------------------------------------------------------------------------------------------------------
    # run...

    if cmd.set():
        if topic:
            if cmd.schema_id is not None:
                print(
                    "topic: It is not possible to change the schema ID of an existing topic.",
                    file=sys.stderr)
                cmd.print_help(sys.stderr)
                exit(1)

            name = topic.name if cmd.name is None else cmd.name
            description = topic.description if cmd.description is None else cmd.description

            info = TopicInfo(
                TopicInfo.FORMAT_JSON) if topic.info is None else topic.info

            # update Topic...
            updated = Topic(None, name, description, topic.is_public, info,
                            None, None)

            manager.update(topic.path, updated)

            topic = manager.find(topic.path)

        else:
            if not cmd.is_complete():
                print(
                    "topic: All fields required for topic creation must be provided.",
                    file=sys.stderr)
                cmd.print_help(sys.stderr)