本文整理汇总了Python中misc.Logger类的典型用法代码示例。如果您正苦于以下问题:Python Logger类的具体用法?Python Logger怎么用?Python Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: Serializer
class Serializer(object):
"""
Should be responsible for representing instances of classes in desired form
"""
def __init__(self):
self.log = Logger().get_logger()
self.log.debug("Instantiated Serializer with data %s" % self.data_hash)
pass
def __repr__(self):
return str(self.data_hash)
def __str__(self):
return self.data_hash
def _assign_attributes(self):
"""
Should change the key names from original API keys to the ones we want
:return: None
"""
for new_key, old_key in self.attributes.iteritems():
try:
self.data[new_key] = self.data_hash[old_key]
except SerializerException, e:
""" possible do something fancy here """
except Exception, e:
self.log.info("Could not assign attribute %s while operating on Object: %s because %s" % (old_key, self.data_hash, e))
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:27,代码来源:serializer.py
示例2: Searcher
class Searcher(dict):
"""
Class responsible for search methods on strings
"""
def __init__(self):
self.log = Logger().get_logger()
def wrap(self, regular_expression):
"""
Turns windows/search type of regexp into python re regexp.
It adds explicit begining '^' and end '$' to matcher and converts
all wildcards to re wildcard '(.*)'
:rtype: str
:param string: regular_expression
"""
return '^' + regular_expression.replace('*', '(.*)') + '$'
def match(self, string, regular_expression):
"""
Match string with a regular expression
:rtype: bool
:param string: given string for matching
:param regular_expression: expression to be run against the given string
"""
regular_expression = self.wrap(regular_expression)
self.log.info("Trying to match regexp: %s against string: %s" % (regular_expression, string))
regex = re.compile(regular_expression)
if re.match(regex, string):
return True
else:
return False
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:33,代码来源:helper.py
示例3: Space
class Space(Fetchable, Statusable, Deletable, Shutdownable,
Startupable, Activatable, Configurable, Metadatable,
Deployable, Cleanable):
"""
@summary: Space is a LiveActivityGroup aggregator
"""
def __init__(self, data_hash, uri, name=None, ):
self.log = Logger().get_logger()
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.class_name = self.__class__.__name__
super(Space, self).__init__()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
def __repr__(self):
return str(self.data_hash)
def __str__(self):
return self.data_hash
def create(self, live_activity_group_name, live_activity_names):
"""
@summary: Should be responsible for creating space
@param live_activity_group_name: string
@param live_activity_names: list of existing names
"""
raise NotImplementedError
def to_json(self):
"""
@summary: Should selected attributes in json form defined by the template
"""
self.serializer = SpaceSerializer(self.data_hash)
return self.serializer.to_json()
def id(self):
return self.data_hash['id']
def name(self):
"""
@param: Should return live activity name
"""
return self.data_hash['name']
def description(self):
"""
@param: Should return Space description
"""
return self.data_hash['description']
""" Private methods below """
def _get_absolute_url(self):
live_activity_group_id = self.data_hash['id']
url = "%s/space/%s/view.json" % (self.uri, live_activity_group_id)
return url
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:58,代码来源:space.py
示例4: __init__
def __init__(self, data_hash, uri, name=None, ):
self.log = Logger().get_logger()
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.class_name = self.__class__.__name__
super(Space, self).__init__()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:8,代码来源:space.py
示例5: __init__
def __init__(self, data_hash=None, uri=None):
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(SpaceController, self).__init__()
if data_hash==None and uri==None:
self.log.info("No data provided - assuming creation of new LiveActivity")
else:
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:11,代码来源:space_controller.py
示例6: __init__
def __init__(self, host='lg-head', port='8080', prefix='/interactivespaces'):
"""
@param host: default value is lg-head
@param port: default value is 8080
@param prefix: default value is /interactivespaces
@todo: refactor filter_* methods because they're not DRY
"""
self.host, self.port, self.prefix = host, port, prefix
self.log = Logger().get_logger()
self.uri = "http://%s:%s%s" % (self.host, self.port, prefix)
super(Master, self).__init__()
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:11,代码来源:master.py
示例7: __init__
def __init__(self, data_hash=None, uri=None, activity_archive_uri=None, name=None):
self.log = Logger().get_logger()
super(Activity, self).__init__()
if (data_hash==None and uri==None):
self.log.info("No data provided - assuming creation of new Activity")
elif (data_hash!=None and uri!=None):
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:11,代码来源:activity.py
示例8: __init__
def __init__(self, data_hash=None, uri=None):
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(LiveActivityGroup, self).__init__()
if data_hash==None and uri==None:
self.log.info("No data_hash and uri provided for LiveActivityGroup constructor, assuming creation")
else:
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:11,代码来源:live_activity_group.py
示例9: __init__
def __init__(self, data_hash=None, uri=None):
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(Space, self).__init__()
if (data_hash==None and uri==None):
self.log.info("No data provided - assuming creation of new Space")
elif (data_hash!=None and uri!=None):
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Space object with url=%s" % self.absolute_url)
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:11,代码来源:space.py
示例10: Deployable
class Deployable(Communicable):
"""
Should be responsible for sending the "deploy" action
"""
def __init__(self):
self.log = Logger().get_logger()
super(Deployable, self).__init__()
def send_deploy(self):
deploy_route = Path().get_route_for(self.class_name, 'deploy') % self.data_hash['id']
if self._send_deploy_request(deploy_route):
self.log.info("Successfully sent 'deploy' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_deploy_request(self, deploy_route):
"""
Makes a 'deploy' request
"""
url = "%s%s" % (self.uri, deploy_route)
self.log.info("Sending deploy GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send deploy GET request because %s" % e)
if response:
return True
else:
return False
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:31,代码来源:mixin.py
示例11: Shutdownable
class Shutdownable(Communicable):
"""
Should be responsible for sending "shutdown" command to live activities,
controllers, spaces and live groups.
"""
def __init__(self):
self.log = Logger().get_logger()
super(Shutdownable, self).__init__()
def send_shutdown(self):
shutdown_route = Path().get_route_for(self.class_name, 'shutdown') % self.data_hash['id']
if self._send_shutdown_request(shutdown_route):
self.log.info("Successfully sent shutdown for url=%s" % self.absolute_url)
return True
else:
return False
def _send_shutdown_request(self, shutdown_route):
"""
Makes a shutdown request
"""
url = "%s%s" % (self.uri, shutdown_route)
self.log.info("Sending 'shutdown' GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send 'shutdown' GET request because %s" % e)
if e=='HTTP Error 500: No connection to controller in 5000 milliseconds':
raise CommunicableException('HTTP Error 500: No connection to controller in 5000 milliseconds')
if response:
return True
else:
return False
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:35,代码来源:mixin.py
示例12: Startupable
class Startupable(Communicable):
"""
@summary: Should be responsible for sending "startup" command to live activities,
controllers, spaces and live groups.
"""
def __init__(self):
self.log = Logger().get_logger()
super(Startupable, self).__init__()
def send_startup(self):
startup_route = Path().get_route_for(self.class_name, 'startup') % self.data_hash['id']
if self._send_startup_request(startup_route):
self.log.info("Successfully sent 'startup' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_startup_request(self, startup_route):
"""
@summary: makes a startup request
"""
url = "%s%s" % (self.uri, startup_route)
self.log.info("Sending 'startup' GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send 'startup' GET request because %s" % e)
if response:
return True
else:
return False
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:33,代码来源:mixin.py
示例13: Deletable
class Deletable(Communicable):
"""
@summary: Should be responsible for the deletion of an object
"""
def __init__(self):
self.log = Logger().get_logger()
super(Deletable, self).__init__()
def send_delete(self):
"""
@summary: sends the "delete" GET request to a route
"""
delete_route = Path().get_route_for(self.class_name, 'delete') % self.data_hash['id']
if self._send_delete_request(delete_route):
self.log.info("Successfully sent 'delete' to url=%s" % self.absolute_url)
return True
else:
return False
def _send_delete_request(self, delete_route):
"""
@rtype: bool
"""
url = "%s%s" % (self.uri, delete_route)
self.log.info("Sending 'delete' to url=%s" %url)
try:
response = self._api_get_html(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send 'delete' because %s" % e)
if response:
return True
else:
return False
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:34,代码来源:mixin.py
示例14: Configurable
class Configurable(Communicable):
"""
@summary: Should be responsible for sending the "configure" action
"""
def __init__(self):
self.log = Logger().get_logger()
super(Configurable, self).__init__()
def send_configure(self):
configure_route = Path().get_route_for(self.class_name, 'configure') % self.data_hash['id']
if self._send_configure_request(configure_route):
self.log.info("Successfully sent 'configure' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_configure_request(self, configure_route):
"""
@summary: makes a 'configure' request
"""
url = "%s%s" % (self.uri, configure_route)
self.log.info("Sending configure GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send configure GET request because %s" % e)
if response:
return True
else:
return False
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:31,代码来源:mixin.py
示例15: __init__
def __init__(self, data_hash=None, uri=None):
"""
@summary: when called with constructor_args and other vars set to None, new
LiveActivity will be created
@param data_hash: should be master API liveActivity json, may be blank
@param uri: should be a link to "view.json" of the given live activity
"""
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(LiveActivity, self).__init__()
if (data_hash==None and uri==None):
self.log.info("No data provided - assuming creation of new LiveActivity")
elif (data_hash!=None and uri!=None):
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated LiveActivity object with url=%s" % self.absolute_url)
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:17,代码来源:live_activity.py
示例16: Cleanable
class Cleanable(Communicable):
"""
Should be responsible for permanent clean and cleaning the tmp
"""
def __init__(self):
self.log = Logger().get_logger()
super(Cleanable, self).__init__()
def send_clean_permanent(self):
configure_route = Path().get_route_for(self.class_name, 'clean_permanent') % self.data_hash['id']
if self._send_cleanable_request(configure_route):
self.log.info("Successfully sent 'clean_permanent' for url=%s" % self.absolute_url)
return True
else:
return False
def send_clean_tmp(self):
configure_route = Path().get_route_for(self.class_name, 'clean_tmp') % self.data_hash['id']
if self._send_cleanable_request(configure_route):
self.log.info("Successfully sent 'clean_tmp' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_cleanable_request(self, cleanable_route):
"""
Makes a cleanable request
"""
url = "%s%s" % (self.uri, cleanable_route)
self.log.info("Sending cleanable GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send cleanable GET request because %s" % e)
if e=='HTTP Error 500: No connection to controller in 5000 milliseconds':
raise CommunicableException('HTTP Error 500: No connection to controller in 5000 milliseconds')
if response:
return True
else:
return False
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:41,代码来源:mixin.py
示例17: Connectable
class Connectable(Communicable):
"""
Should be responsible for connecting/disconnecting space controllers
"""
def __init__(self):
self.log = Logger().get_logger()
super(Connectable, self).__init__()
def send_connect(self):
connect_route = Path().get_route_for(self.class_name, 'connect') % self.data_hash['id']
if self._send_connectable_request(connect_route):
self.log.info("Successfully sent 'connect' for url=%s" % self.absolute_url)
return True
else:
return False
def send_disconnect(self):
disconnect_route = Path().get_route_for(self.class_name, 'disconnect') % self.data_hash['id']
if self._send_connectable_request(disconnect_route):
self.log.info("Successfully sent 'disconnect' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_connectable_request(self, connectable_route):
"""
Makes a connectable request
"""
url = "%s%s" % (self.uri, connectable_route)
self.log.info("Sending connectable GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send connectable GET request because %s" % e)
if response:
return True
else:
return False
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:39,代码来源:mixin.py
示例18: Statusable
class Statusable(Communicable):
"""
Should be responsible for _refreshing_ status of the object,
which means that it will send "status" command to IS Controllers.
In order to fetch the fresh and most up-to-date status you should use
.fetch() method on the object.
"""
def __init__(self):
self.log = Logger().get_logger()
super(Statusable, self).__init__()
def send_status_refresh(self):
"""
Extracts self.data_hash and self.class_name from children class
and finds out to which route send GET request to ands sends it
"""
refresh_route = Path().get_route_for(self.class_name, 'status') % self.data_hash['id']
if self._send_status_refresh(refresh_route):
self.log.info("Successfully refreshed status for url=%s" % self.absolute_url)
return True
else:
return False
def _send_status_refresh(self, refresh_route):
"""
Should tell master to retrieve status info from controller
so master has the most up to date info from the controller
:param refresh_route: status.json route for specific class
:rtype: bool
"""
url = "%s%s" % (self.uri, refresh_route)
self.log.info("Sending status refresh to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send status refresh because %s" % e)
if response:
return True
else:
return False
开发者ID:EndPointCorp,项目名称:interactivespaces-python-api,代码行数:44,代码来源:mixin.py
示例19: Metadatable
class Metadatable(Communicable):
"""
@summary: Should be responsible for setting metadata
"""
def __init__(self):
self.log = Logger().get_logger()
super(Metadatable, self).__init__()
def set_metadata(self, metadata_dictionary):
"""
@summary: Accepts dictionary of keys that will be unpacked to "key=value" strings and
makes a request overwriting any previous metadata
@rtype: bool
@param metadata_args: Dictionary with keys and values
"""
metadata = {"values" : self._unpack_metadata(metadata_dictionary)}
self.log.info("Updating metadata of %s with %s" % (self.class_name, metadata))
metadata_route = Path().get_route_for(self.class_name, 'metadata') % self.data_hash['id']
if self._send_metadatable_request(metadata_route, metadata):
self.log.info("Successfully sent metadata for url=%s" % self.absolute_url)
return True
else:
return False
def _unpack_metadata(self, metadata_dictionary):
"""
@summary: accepts dictionary and converts it to string
@rtype: string
@param metadata_dictionary: dict containing metadata
"""
metadata_text = ""
try:
for key, value in metadata_dictionary.iteritems():
metadata_text = metadata_text + ("\r\n") + key + "=" + value
return metadata_text
except Exception, e:
self.log.error("Could not unpack supplied metadata dictionary because %s" % e)
raise
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:38,代码来源:mixin.py
示例20: Master
class Master(Communicable):
"""
@summary: This is the main class with all the logic needed for
high level stuff. You will typically use instance of Master for all your scripts.
"""
def __init__(self, host='lg-head', port='8080', prefix='/interactivespaces'):
"""
@param host: default value is lg-head
@param port: default value is 8080
@param prefix: default value is /interactivespaces
@todo: refactor filter_* methods because they're not DRY
"""
self.host, self.port, self.prefix = host, port, prefix
self.log = Logger().get_logger()
self.uri = "http://%s:%s%s" % (self.host, self.port, prefix)
super(Master, self).__init__()
def get_activities(self, search_pattern=None):
"""
Retrieves a list of Activity objects
@rtype: list
@param search_pattern: dictionary of regexps used for searching through Activities
- example regexp dict: {
"activity_name" : "regexp",
"activity_version" : "regexp"
}
- every search_pattern dictionary key may be blank/null
"""
url = self._compose_url(class_name='Master', method_name='get_activities', uri=self.uri)
self.log.info("Trying to retrieve url=%s" % url)
response = self._api_get_json(url)
self.log.info('Got response for "get_activities" %s ' % str(response))
self.log.info('get_activities returned %s objects' % str(len(response)))
activities = self._filter_activities(response, search_pattern)
return activities
def get_activity(self, search_pattern=None):
"""
Retrieves a list of Activity objects
@rtype: list
@param search_pattern: dictionary of regexps used for searching through Activities
- example regexp dict: {
"activity_name" : "regexp",
"activity_version" : "regexp"
}
- every search_pattern dictionary key may be blank/null
"""
url = self._compose_url(class_name='Master', method_name='get_activities', uri=self.uri)
self.log.info("Trying to retrieve url=%s" % url)
response = self._api_get_json(url)
self.log.info('Got response for "get_activities" %s ' % str(response))
self.log.info('get_activities returned %s objects' % str(len(response)))
activity = self._filter_activities(response, search_pattern)
if len(activity) > 1:
raise MasterException("get_activity returned more than one row (%s)" % len(activity))
elif isinstance(activity[0], Activity):
activity[0].fetch()
self.log.info("get_activity returned Activity:%s" % str(activity))
return activity
else:
raise MasterException("Could not get specific activity for given search pattern")
def get_live_activities(self, search_pattern=None):
"""
Retrieves a list of LiveActivity objects
@rtype: list
@param search_pattern: dictionary of regexps used for searching through LiveActivity names
- example regexp dict: {
"live_activity_name" : "regexp",
"space_controller_name" : "regexp"
}
- each search_pattern dictionary key may be blank/null
"""
url = self._compose_url(class_name='Master', method_name='get_live_activities', uri=self.uri)
self.log.info("Trying to retrieve url=%s" % url)
response = self._api_get_json(url)
self.log.debug('Got response for "get_live_activities" %s ' % str(response))
self.log.info('get_live_activities returned %s objects' % str(len(response)))
live_activities = self._filter_live_activities(response, search_pattern)
return live_activities
def get_live_activity(self, search_pattern=None):
"""
Retrieves a list of LiveActivity objects
@rtype: LiveActivity or False
@param search_pattern: dictionary of regexps used for searching through LiveActivity names
- example regexp dict: {
"live_activity_name" : "GE ViewSync Master on Node A",
"space_controller_name" : "ISCtlDispAScreen00"
}
- each search_pattern dictionary key may be blank/null
"""
url = self._compose_url(class_name='Master', method_name='get_live_activities', uri=self.uri)
self.log.info("Trying to retrieve url=%s" % url)
response = self._api_get_json(url)
self.log.debug('Got response for "get_live_activities" %s ' % str(response))
self.log.info('get_live_activities returned %s objects' % str(len(response)))
live_activity = self._filter_live_activities(response, search_pattern)
if len(live_activity) > 1:
raise MasterException("get_live_activity returned more than one row (%s)" % len(live_activity))
#.........这里部分代码省略.........
开发者ID:wzin,项目名称:interactivespaces-python-api,代码行数:101,代码来源:master.py
注:本文中的misc.Logger类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论