當前位置: 首頁>>代碼示例>>Python>>正文


Python Logger.warn方法代碼示例

本文整理匯總了Python中misc.Logger.warn方法的典型用法代碼示例。如果您正苦於以下問題:Python Logger.warn方法的具體用法?Python Logger.warn怎麽用?Python Logger.warn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在misc.Logger的用法示例。


在下文中一共展示了Logger.warn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Master

# 需要導入模塊: from misc import Logger [as 別名]
# 或者: from misc.Logger import warn [as 別名]

#.........這裏部分代碼省略.........
        live_activity_group_ids = self._translate_live_activity_groups_names_to_ids(constructor_args['live_activity_groups'])
        unpacked_arguments = {}
        unpacked_arguments['space.name'] = constructor_args['space_name']
        unpacked_arguments['space.description'] = constructor_args['space_description']
        unpacked_arguments['_eventId_save'] = 'Save'
        unpacked_arguments['liveActivityGroupIds'] = live_activity_group_ids
        if not self._api_object_exists(Space, constructor_args, self.get_space):
            space = Space().new(self.uri, unpacked_arguments)
            self.log.info("Master:new_space:%s" % space)
            return space
        else:
            return []

    def new_named_script(self, name, description, language, content, scheduled=None):
        """Creates a new named script."""
        raise NotImplementedError

    """ Private methods below """

    def _translate_live_activity_groups_names_to_ids(self, live_activity_groups):
        """
        Converts live activity groups dicts to list of ids

        :param live_activities: list of dictionaries containing following keys::

            {\
            "live_activity_group_name" : "some_name",\
            }

        :rtype: list
        """
        live_activity_groups_ids = []
        for lag_data in live_activity_groups:
            live_activity_group = self.get_live_activity_group(lag_data)
            live_activity_groups_ids.append(live_activity_group.id())
        self.log.info("Translated %s live_activity_groups_names to ids with a result of %s" % (len(live_activity_groups_ids), live_activity_groups_ids) )
        return live_activity_groups_ids

    def _translate_live_activities_names_to_ids(self, live_activities):
        """
        Converts live activities dicts to list of ids

        :param live_activities: list of dictionaries containing following keys::

            {\
            "live_activity_name" : "some_name",\
            "space_controller_name" : "some controller name"\
            }

        :rtype: list
        """
        live_activity_ids = []
        for la_data in live_activities:
            self.log.info("Getting Live Activity for data: %s" % la_data)
            live_activity = self.get_live_activity(la_data)
            live_activity_ids.append(live_activity.id())
        self.log.info("Translated %s live_activity_names to ids with a result of %s" % (len(live_activity_ids), live_activity_ids) )
        return live_activity_ids

    """ Private methods below """

    def _api_object_exists(self, object_type, constructor_args, getter_method):
        self.log.info("Checking whether object %s with following attributes %s exists in the API" % (object_type, constructor_args))

        api_object = getter_method(constructor_args)

        if api_object:
            self.log.warn("Object already exists: %s" % api_object)
            return True
        else:
            self.log.info("Object does not exist yet")
            return False



    def _validate_single_getter_results(self, response, expected_type, exception):
        """
        Validates response from the API. Runs type and other simple checks.

        :param response: list of objects returned from api

        :param expected_type: expected type of the object

        :param exception: exception to throw if response is invalid

        :rtype: interactivespaces object
        """

        if len(response) > 1:
            raise exception("API query returned more than one row")
        elif len(response) == 0:
            return None
        elif isinstance(response[0], expected_type):
            try:
                api_object = response[0].fetch()
                self.log.info("Getter method returned Object:%s" % str(api_object))
                return api_object
            except Exception, e:
                raise
        else:
開發者ID:EndPointCorp,項目名稱:interactivespaces-python-api,代碼行數:104,代碼來源:master.py


注:本文中的misc.Logger.warn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。