2 # vim: set ts=4 sts=4 sw=4 textwidth=112:
4 class RarslaveMessage (object):
5 def __init__ (self, msg, printquiet):
7 self.printquiet = printquiet
10 return "%s" % self.msg
13 # A message is verbose only if we should
14 # print it when we are not printing quietly
15 return not self.printquiet
17 class RarslaveLogger (object):
18 # This class will log multiple messages, one for each set that is operated on.
19 # It will then be able to print all of them out.
25 def getUniqueID (self):
26 # Generate a unique id. This implementation is pretty simple,
27 # just generating an increasing set of integers.
29 # This function also sets up the dictionary which will hold the messages.
31 self.__msg_dict[self.__uniq_num] = []
33 return self.__uniq_num
35 def isValidID (self, id):
36 # Check if the id given is a valid one. This is done by checking if
37 # the id is in the dictionary.
38 return id in self.__msg_dict.keys()
40 def addMessage (self, id, msg, printquiet=True):
41 # Add a message to the dictionary, to be printed later.
42 # The printquiet variable controls whether the message will be printed
43 # normally, or only in verbose mode. The default is to print always.
46 assert self.isValidID (id)
48 # Get the list from the dictionary, then add the message to it
49 self.__msg_dict[id].append (RarslaveMessage (msg, printquiet))
51 def printAllMessages (self, verbose=False):
52 # Print all messages in groups by id
53 for k in self.__msg_dict.keys():
54 for msg in self.__msg_dict[k]:
56 # Skip verbose messages if we're not in verbose mode
57 if msg.isVerbose() and not verbose:
67 if __name__ == '__main__':