[svn r804] Added function to retrieve backend details (total space, free space, etc)
3 __author__ = "Artur Duque de Souza"
4 __author_email__ = "artur.souza@indt.org.br"
11 __all__ = ("Log", "log_structure")
13 class log_structure(object):
14 """Structure to hold log info."""
16 def __init__(self, log=None):
24 """This class implements a log where we can store status of
25 all transcoders (even from those that are not running any more)."""
31 def insert(self, tid, name):
32 """Insert a given tid on the log structure"""
33 if not self.logs.has_key(tid):
34 self.logs[tid] = log_structure(logging.getLogger(name))
40 def remove(self, tid=None):
41 """Cleans up all log stored for a
42 given tid or for all transcodes."""
51 def get_status(self, tid=None, all=False):
52 """Get the status of all transcoders or
53 of just one of them if it's given an tid."""
56 for tids, logs in self.logs.items():
57 if len(logs.history) > 0:
59 ret[tids] = logs.history[-1]
61 ret[tids] = logs.history
63 elif self.logs.has_key(tid) and len(self.logs[tid].history) > 0:
65 return self.logs[tid].history[-1]
67 return self.logs[tid].history
72 def _update_status(self, tid=None, msg=""):
73 """Update the status of a given tid. Private method that
74 is only called inside error/info/debug wrappers"""
76 self.logs[tid].history.append(msg)
82 def error(self, tid, msg):
83 """Python's Log.error wrapper"""
84 if self.logs.has_key(tid):
85 self.logs[tid].log.error("%s" % msg)
86 return self._update_status(tid, msg)
91 def info(self, tid, msg):
92 """Python's Log.info wrapper"""
93 if self.logs.has_key(tid):
94 self.logs[tid].log.info("%s" % msg)
95 self._update_status(tid, msg)
101 def debug(self, tid, msg):
102 """Python's Log.debug wrapper"""
103 if self.logs.has_key(tid):
104 self.logs[tid].log.debug("%s" % msg)
105 self._update_status(tid, msg)