[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Sebastien Coavoux s.coavoux at free.fr
Tue Feb 28 22:16:24 UTC 2012


The following commit has been merged in the debian/master branch:
commit ac68c5dc600dcff785b47eb81b053cfb75c176ed
Author: Sebastien Coavoux <s.coavoux at free.fr>
Date:   Thu Jan 26 23:24:41 2012 +0100

    Code Review.
    Fixed : typo in comments
    Fixed : misplaced comments
            (My mistake, I've to fix previous one because
            I read again the docstring rules, and they are not as the
            simple comments ones)
    Added : licence in files
    Added : # -*- coding: utf-8 -*- in header
            ( Once done for each files, we should try to replace the name
            in the licence with special character like 'è' or 'ß' :P )
    
    Personal Note :
    *it's != its
    
    Feel free to (dis)agree

diff --git a/shinken/graph.py b/shinken/graph.py
index 4db7978..c617c85 100644
--- a/shinken/graph.py
+++ b/shinken/graph.py
@@ -1,31 +1,39 @@
 #!/usr/bin/env python
-#Copyright (C) 2009-2010 :
-#    Gabes Jean, naparuba at gmail.com
-#    Gerhard Lausser, Gerhard.Lausser at consol.de
-#    Gregory Starck, g.starck at gmail.com
-#    Hartmut Goebel, h.goebel at goebel-consult.de
+
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009-2011 :
+#     Gabes Jean, naparuba at gmail.com
+#     Gerhard Lausser, Gerhard.Lausser at consol.de
+#     Gregory Starck, g.starck at gmail.com
+#     Hartmut Goebel, h.goebel at goebel-consult.de
 #
-#This file is part of Shinken.
+# This file is part of Shinken.
 #
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+
+
 
 
-# Graph is a class to make graph things like DFS checks or accessibility
-# Why use an atomic bomb when a little hammer is enough?
 
 
 class Graph:
+    """Graph is a class to make graph things like DFS checks or accessibility
+    Why use an atomic bomb when a little hammer is enough?
+    
+    """
+    
     def __init__(self):
         self.nodes = {}
 
@@ -48,7 +56,7 @@ class Graph:
 
         try:
             self.nodes[from_node].append(to_node)
-        # If from_node do not exist, add it with it's son
+        # If from_node does not exist, add it with its son
         except KeyError, exp:
             self.nodes[from_node] = [to_node]
 
@@ -62,7 +70,7 @@ class Graph:
 
         #Now do the job
         for node in self.nodes:
-            #Run the dfs only if the node is not already done */
+            #Run the dfs only if the node has not been already done */
             if node.dfs_loop_status == 'DFS_UNCHECKED':
                 self.dfs_loop_search(node)
             #If LOOP_INSIDE, must be returned
@@ -78,7 +86,7 @@ class Graph:
 
     # DFS_UNCHECKED default value
     # DFS_TEMPORARY_CHECKED check just one time
-    # DFS_OK no problem for node and it's childs
+    # DFS_OK no problem for node and its children
     # DFS_NEAR_LOOP has trouble sons
     # DFS_LOOP_INSIDE is a part of a loop!
     def dfs_loop_search(self, root):
@@ -93,23 +101,23 @@ class Graph:
                 self.dfs_loop_search(child)
                 child_status = child.dfs_loop_status
 
-            # If a child already temporary checked, its a problem,
+            # If a child has already been temporary checked, it's a problem,
             # loop inside, and its a acked status
             if child_status == 'DFS_TEMPORARY_CHECKED':
                 child.dfs_loop_status = 'DFS_LOOP_INSIDE'
                 root.dfs_loop_status = 'DFS_LOOP_INSIDE'
 
-            # If a child already temporary checked, its a problem, loop inside
+            # If a child has already been temporary checked, it's a problem, loop inside
             if child_status in ('DFS_NEAR_LOOP', 'DFS_LOOP_INSIDE'):
-                # if a node is know to be part of a loop, do not let it be less
+                # if a node is known to be part of a loop, do not let it be less
                 if root.dfs_loop_status != 'DFS_LOOP_INSIDE':
                     root.dfs_loop_status = 'DFS_NEAR_LOOP'
-                # We already saw this child, it's a problem
+                # We've already seen this child, it's a problem
                 child.dfs_loop_status = 'DFS_LOOP_INSIDE'
 
         # If root have been modified, do not set it OK
-        # A node is OK if and only if all of his childs are OK
-        # if it does not have child, goes ok
+        # A node is OK if and only if all of its children are OK
+        # if it does not have a child, goes ok
         if root.dfs_loop_status == 'DFS_TEMPORARY_CHECKED':
             root.dfs_loop_status = 'DFS_OK'
 
@@ -117,7 +125,7 @@ class Graph:
     # Get accessibility packs of the graph : in one pack,
     # element are related in a way. Between packs, there is no relation
     # at all.
-    # TODO : Get it work for directionnal graph too
+    # TODO : Make it work for directionnal graph too
     # Because for now, edge must be father->son AND son->father
     def get_accessibility_packs(self):
         packs = []
@@ -137,7 +145,7 @@ class Graph:
         return packs
 
 
-    # Return all mychilds, and all childs of my childs
+    # Return all my children, and all my grandchildren
     def dfs_get_all_childs(self, root):
         root.dfs_loop_status = 'DFS_CHECKED'
 
@@ -148,7 +156,7 @@ class Graph:
         ret.update(self.nodes[root])
 
         for child in self.nodes[root]:
-            # I just don't care about already check childs
+            # I just don't care about already checked childs
             if child.dfs_loop_status == 'DFS_UNCHECKED':
                 ret.update(self.dfs_get_all_childs(child))
 
diff --git a/shinken/load.py b/shinken/load.py
index 6054e2c..da1ee00 100644
--- a/shinken/load.py
+++ b/shinken/load.py
@@ -1,60 +1,59 @@
 #!/usr/bin/env python
-#Copyright (C) 2009-2010 :
-#    Gabes Jean, naparuba at gmail.com
-#    Gerhard Lausser, Gerhard.Lausser at consol.de
-#    Gregory Starck, g.starck at gmail.com
-#    Hartmut Goebel, h.goebel at goebel-consult.de
+
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009-2011 :
+#     Gabes Jean, naparuba at gmail.com
+#     Gerhard Lausser, Gerhard.Lausser at consol.de
+#     Gregory Starck, g.starck at gmail.com
+#     Hartmut Goebel, h.goebel at goebel-consult.de
 #
-#This file is part of Shinken.
+# This file is part of Shinken.
 #
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
 
 
 import time
 import math
 
-#EXP_1=1/math.exp(5/60.0)
-#EXP_5=1/math.exp(5/(5*60.0))
-#EXP_15=1/math.exp(5/(15*60.0))
-
-#From advance load average's code (another of my projects :) )
+# From advanced load average's code (another of my projects :) )
 #def calc_load_load(load, exp,n):
 #        load = n + exp*(load - n)
 #        return (load, exp)
 
 
-#This class if for having a easy Load calculation
-#without having to send value at regular interval
-#(but it's more efficient if you do this :) ) and not
-#having a list and all. Just an object, an update and a get
-#You can define m : the average is for m minutes. The val is
-#the initial value. It's better if it's 0 but you can choice.
-
 
 class Load:
-    #m = number of minutes for the average
-    #val = initial_value
+    """This class is for having a easy Load calculation
+    without having to send value at regular interval
+    (but it's more efficient if you do this :) ) and without 
+    having a list or other stuff. It's just an object, an update and a get
+    You can define m : the average for m minutes. The val is
+    the initial value. It's better if it's 0 but you can choose.
+
+    """
+    
     def __init__(self, m=1, initial_value=0):
-        self.exp = 0 #first exp
-        self.m = m #Number of minute of the avg
-        self.last_update = 0 #last update of the value
-        self.val = initial_value #first value
+        self.exp = 0 # first exp
+        self.m = m # Number of minute of the avg
+        self.last_update = 0 # last update of the value
+        self.val = initial_value # first value
 
 
     def update_load(self, new_val):
-        #The first call do not change the value, just tag
-        #the begining of last_update
+        # The first call do not change the value, just tag
+        # the begining of last_update
         if self.last_update == 0:
             self.last_update = time.time()
             return
diff --git a/shinken/log.py b/shinken/log.py
index bd6fee5..e30c59a 100644
--- a/shinken/log.py
+++ b/shinken/log.py
@@ -1,24 +1,27 @@
 #!/usr/bin/env python
-#Copyright (C) 2009-2010 :
-#    Gabes Jean, naparuba at gmail.com
-#    Gerhard Lausser, Gerhard.Lausser at consol.de
-#    Gregory Starck, g.starck at gmail.com
-#    Hartmut Goebel, h.goebel at goebel-consult.de
+
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009-2011 :
+#     Gabes Jean, naparuba at gmail.com
+#     Gerhard Lausser, Gerhard.Lausser at consol.de
+#     Gregory Starck, g.starck at gmail.com
+#     Hartmut Goebel, h.goebel at goebel-consult.de
 #
-#This file is part of Shinken.
+# This file is part of Shinken.
 #
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
 
 import time
 import logging
@@ -32,6 +35,10 @@ local_log = None
 human_timestamp_log = False
 
 class Log:
+    """Please Add a Docstring to describe the class here"""
+    
+    
+    
     # We load the object where we will put log broks
     # with the 'add' method
     def load_obj(self, object, name_ = None):
@@ -40,6 +47,7 @@ class Log:
         obj = object
         name = name_
 
+
     # We enter a log message, we format it, and we add the log brok
     def log(self, message, format = None, print_it=True):
         global obj
@@ -48,8 +56,8 @@ class Log:
         global human_timestamp_log
 
         if print_it:
-            # If the daemon is launch with a non UTF8 shell
-            # we can habe problem in printing
+            # If the daemon is launched with a non UTF8 shell
+            # we can have problems in printing
             try:
                 print message
             except UnicodeEncodeError:
@@ -82,8 +90,8 @@ class Log:
             logging.info(s)
 
 
-    # The log can also write to a local file if need
-    # and return the filedecriptor so we can avoid to
+    # The log can also write to a local file if needed
+    # and return the file descriptor so we can avoid to
     # close it
     def register_local_log(self, path):
         global local_log
@@ -103,7 +111,7 @@ class Log:
         return basic_log_handler.stream.fileno()
         
 
-    # Clsoe the local log file at program exit
+    # Close the local log file at program exit
     def quit(self):
         global local_log
         if local_log:
diff --git a/shinken/macroresolver.py b/shinken/macroresolver.py
index 361c17b..5d94d48 100644
--- a/shinken/macroresolver.py
+++ b/shinken/macroresolver.py
@@ -1,24 +1,27 @@
 #!/usr/bin/env python
-#Copyright (C) 2009-2010 :
-#    Gabes Jean, naparuba at gmail.com
-#    Gerhard Lausser, Gerhard.Lausser at consol.de
-#    Gregory Starck, g.starck at gmail.com
-#    Hartmut Goebel, h.goebel at goebel-consult.de
+
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009-2011 :
+#     Gabes Jean, naparuba at gmail.com
+#     Gerhard Lausser, Gerhard.Lausser at consol.de
+#     Gregory Starck, g.starck at gmail.com
+#     Hartmut Goebel, h.goebel at goebel-consult.de
 #
-#This file is part of Shinken.
+# This file is part of Shinken.
 #
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
 
 
 #This class revolv Macro in commands by looking at the macros list
@@ -35,6 +38,8 @@ from shinken.borg import Borg
 
 
 class MacroResolver(Borg):
+    """Please Add a Docstring to describe the class here"""
+
 
     my_type = 'macroresolver'
     #Global macros
@@ -65,15 +70,15 @@ class MacroResolver(Borg):
     }
 
 
-    #This shall be call ONE TIME. It just put links for elements
-    #by scheduler
+    # This must be called ONCE. It just put links for elements
+    # by scheduler
     def init(self, conf):
         # For searching class and elements for ondemand
-        #we need link to types
+        # we need link to types
         self.conf = conf
         self.lists_on_demand = []
         self.hosts = conf.hosts
-        #For special void host_name handling...
+        # For special void host_name handling...
         self.host_class = self.hosts.inner_class
         self.lists_on_demand.append(self.hosts)
         self.services = conf.services
@@ -88,14 +93,14 @@ class MacroResolver(Borg):
         self.lists_on_demand.append(self.contactgroups)
         self.illegal_macro_output_chars = conf.illegal_macro_output_chars
         self.output_macros = ['HOSTOUTPUT', 'HOSTPERFDATA', 'HOSTACKAUTHOR', 'HOSTACKCOMMENT', 'SERVICEOUTPUT', 'SERVICEPERFDATA', 'SERVICEACKAUTHOR', 'SERVICEACKCOMMENT']
-        #Try cache :)
+        # Try cache :)
         #self.cache = {}
 
 
-    #Return all macros of a string, so cut the $
-    #And create a dict with it:
-    #val : value, not set here
-    #type : type of macro, like class one, or ARGN one
+    # Return all macros of a string, so cut the $
+    # And create a dict with it:
+    # val : value, not set here
+    # type : type of macro, like class one, or ARGN one
     def get_macros(self, s):
         #if s in self.cache:
         #    return self.cache[s]
@@ -116,9 +121,9 @@ class MacroResolver(Borg):
         return macros
 
 
-    #Get a value from a propertie of a element
-    #Prop can ba a function or a propertie
-    #So we call it or no
+    # Get a value from a propertie of a element
+    # Prop can be a function or a propertie
+    # So we call it or not
     def get_value_from_element(self, elt, prop):
         try:
             value = getattr(elt, prop)
@@ -131,15 +136,15 @@ class MacroResolver(Borg):
             return ''
 
 
-    #For some macros, we need to delete unwanted caracters
+    # For some macros, we need to delete unwanted caracters
     def delete_unwanted_caracters(self, s):
         for c in self.illegal_macro_output_chars:
             s = s.replace(c, '')
         return s
 
 
-    #return a dict with all environement variable came from
-    #the macros of the datas object
+    # return a dict with all environement variable came from
+    # the macros of the datas object
     def get_env_macros(self, data):
         env = {}
 
@@ -162,53 +167,53 @@ class MacroResolver(Borg):
     # This function will look at elements in data (and args if it filled)
     # to replace the macros in c_line with real value.
     def resolve_simple_macros_in_string(self, c_line, data, args=None):
-        #Now we prepare the classes for looking at the class.macros
-        data.append(self) #For getting global MACROS
+        # Now we prepare the classes for looking at the class.macros
+        data.append(self) # For getting global MACROS
         if hasattr(self, 'conf'):
             data.append(self.conf) # For USERN macros
         clss = [d.__class__ for d in data]
 
-        #we should do some loops for nested macros
-        #like $USER1$ hiding like a ninja in a $ARG2$ Macro. And if
-        #$USER1$ is pointing to $USER34$ etc etc, we should loop
-        #until we reach the botom. So the last loop is when we do
-        #not still have macros :)
+        # we should do some loops for nested macros
+        # like $USER1$ hiding like a ninja in a $ARG2$ Macro. And if
+        # $USER1$ is pointing to $USER34$ etc etc, we should loop
+        # until we reach the botom. So the last loop is when we do
+        # not still have macros :)
         still_got_macros = True
         nb_loop = 0
         while still_got_macros:
             nb_loop += 1
-            #Ok, we want the macros in the command line
+            # Ok, we want the macros in the command line
             macros = self.get_macros(c_line)
 
-            #We can get out if we do not have macros this loop
+            # We can get out if we do not have macros this loop
             still_got_macros = (len(macros)!=0)
             #print "Still go macros:", still_got_macros
 
-            #Put in the macros the type of macro for all macros
+            # Put in the macros the type of macro for all macros
             self.get_type_of_macro(macros, clss)
-            #Now we get values from elements
+            # Now we get values from elements
             for macro in macros:
-                #If type ARGN, look at ARGN cutting
+                # If type ARGN, look at ARGN cutting
                 if macros[macro]['type'] == 'ARGN' and args is not None:
                     macros[macro]['val'] = self.resolve_argn(macro, args)
                     macros[macro]['type'] = 'resolved'
-                #If class, get value from properties
+                # If class, get value from properties
                 if macros[macro]['type'] == 'class':
                     cls = macros[macro]['class']
                     for elt in data:
                         if elt is not None and elt.__class__ == cls:
                             prop = cls.macros[macro]
                             macros[macro]['val'] = self.get_value_from_element(elt, prop)
-                            #Now check if we do not have a 'output' macro. If so, we must
-                            #delete all special caracters that can be dangerous
+                            #N ow check if we do not have a 'output' macro. If so, we must
+                            # delete all special caracters that can be dangerous
                             if macro in self.output_macros:
                                 macros[macro]['val'] = self.delete_unwanted_caracters(macros[macro]['val'])
                 if macros[macro]['type'] == 'CUSTOM':
                     cls_type = macros[macro]['class']
                     macro_name = re.split('_'+cls_type, macro)[1].upper()
-                    #Ok, we've got the macro like MAC_ADDRESS for _HOSTMAC_ADDRESS
-                    #Now we get the element in data that have the type HOST
-                    #and we check if it gots the custom value
+                    # Ok, we've got the macro like MAC_ADDRESS for _HOSTMAC_ADDRESS
+                    # Now we get the element in data that have the type HOST
+                    # and we check if it gots the custom value
                     for elt in data:
                         if elt is not None and elt.__class__.my_type.upper() == cls_type:
                             if '_'+macro_name in elt.customs:
@@ -216,34 +221,37 @@ class MacroResolver(Borg):
                 if macros[macro]['type'] == 'ONDEMAND':
                     macros[macro]['val'] = self.resolve_ondemand(macro, data)
 
-            #We resolved all we can, now replace the macro in the command call
+            # We resolved all we can, now replace the macro in the command call
             for macro in macros:
                 c_line = c_line.replace('$'+macro+'$', macros[macro]['val'])
 
+            # A $$ means we want a $, it's not a macro!
+            # We replace $$ by a big dirty thing to be sur to not misinterpret it
             c_line = c_line.replace("$$", "DOUBLEDOLLAR")
 
             if nb_loop > 32: #too mouch loop, we exit
                 still_got_macros = False
 
+        # We now replace the big dirty token we made by only a simple $
         c_line = c_line.replace("DOUBLEDOLLAR", "$")
 
         #print "Retuning c_line", c_line.strip()
         return c_line.strip()
 
 
-    #Resolve a command with macro by looking at data classes.macros
-    #And get macro from item properties.
+    # Resolve a command with macro by looking at data classes.macros
+    # And get macro from item properties.
     def resolve_command(self, com, data):
         c_line = com.command.command_line
         return self.resolve_simple_macros_in_string(c_line, data, args=com.args)
 
 
-    #For all Macros in macros, set the type by looking at the
-    #MACRO name (ARGN? -> argn_type,
-    #HOSTBLABLA -> class one and set Host in class)
-    #_HOSTTOTO -> HOST CUSTOM MACRO TOTO
-    #$SERVICESTATEID:srv-1:Load$ -> MACRO SERVICESTATEID of
-    #the service Load of host srv-1
+    # For all Macros in macros, set the type by looking at the
+    # MACRO name (ARGN? -> argn_type,
+    # HOSTBLABLA -> class one and set Host in class)
+    # _HOSTTOTO -> HOST CUSTOM MACRO TOTO
+    # $SERVICESTATEID:srv-1:Load$ -> MACRO SERVICESTATEID of
+    # the service Load of host srv-1
     def get_type_of_macro(self, macros, clss):
         for macro in macros:
             # ARGN Macros
@@ -278,9 +286,9 @@ class MacroResolver(Borg):
                     continue
 
 
-    #Resolv MACROS for the ARGN
+    # Resolve MACROS for the ARGN
     def resolve_argn(self, macro, args):
-        #first, get number of arg
+        #first, get the number of args
         id = None
         r = re.search('ARG(?P<id>\d+)', macro)
         if r is not None:
@@ -291,25 +299,25 @@ class MacroResolver(Borg):
                 return ''
 
 
-    #Resolved on demande macro, quite hard on fact
+    # Resolve on-demand macro, quite hard in fact
     def resolve_ondemand(self, macro, data):
         #print "\nResolving macro", macro
         elts = macro.split(':')
         nb_parts = len(elts)
         macro_name = elts[0]
-        #Len 3 == service, 2 = all others types...
+        # Len 3 == service, 2 = all others types...
         if nb_parts == 3:
             val = ''
             #print "Got a Service on demand asking...", elts
             (host_name, service_description) = (elts[1], elts[2])
-            #host_name can be void, so it's the host in data
-            #that is important. We use our self.host_class to
-            #find the host in the data :)
+            # host_name can be void, so it's the host in data
+            # that is important. We use our self.host_class to
+            # find the host in the data :)
             if host_name == '':
                 for elt in data:
                     if elt is not None and elt.__class__ == self.host_class:
                         host_name = elt.host_name
-            #Okn now we get service
+            # Ok now we get service
             s = self.services.find_srv_by_name_and_hostname(host_name, service_description)
             if s is not None:
                 cls = s.__class__
@@ -329,7 +337,7 @@ class MacroResolver(Borg):
                         elt_name = elt.host_name
             for list in self.lists_on_demand:
                 cls = list.inner_class
-                #We search our type by look at the macro
+                # We search our type by looking at the macro
                 if macro_name in cls.macros:
                     prop = cls.macros[macro_name]
                     i = list.find_by_name(elt_name)
@@ -340,27 +348,27 @@ class MacroResolver(Borg):
         return ''
 
 
-    #Get Fri 15 May 11:42:39 CEST 2009
+    # Get Fri 15 May 11:42:39 CEST 2009
     def get_long_date_time(self):
         return time.strftime("%a %d %b %H:%M:%S %Z %Y", time.localtime()).decode('UTF-8', 'ignore')
 
 
-    #Get 10-13-2000 00:30:28
+    # Get 10-13-2000 00:30:28
     def get_short_date_time(self):
         return time.strftime("%d-%m-%Y %H:%M:%S", time.localtime())
 
 
-    #Get 10-13-2000
+    # Get 10-13-2000
     def get_date(self):
         return time.strftime("%d-%m-%Y", time.localtime())
 
 
-    #Get 00:30:28
+    # Get 00:30:28
     def get_time(self):
         return time.strftime("%H:%M:%S", time.localtime())
 
 
-    #Get epoch time
+    # Get epoch time
     def get_timet(self):
         return str(int(time.time()))
 
diff --git a/shinken/memoized.py b/shinken/memoized.py
index 830759e..7163d06 100644
--- a/shinken/memoized.py
+++ b/shinken/memoized.py
@@ -1,34 +1,42 @@
 #!/usr/bin/env python
-#Copyright (C) 2009-2010 :
-#    Gabes Jean, naparuba at gmail.com
-#    Gerhard Lausser, Gerhard.Lausser at consol.de
-#    Gregory Starck, g.starck at gmail.com
-#    Hartmut Goebel, h.goebel at goebel-consult.de
+
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009-2011 :
+#     Gabes Jean, naparuba at gmail.com
+#     Gerhard Lausser, Gerhard.Lausser at consol.de
+#     Gregory Starck, g.starck at gmail.com
+#     Hartmut Goebel, h.goebel at goebel-consult.de
 #
-#This file is part of Shinken.
+# This file is part of Shinken.
 #
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
 
 
 class memoized(object):
     """Decorator that caches a function's return value each time it is called.
     If called later with the same arguments, the cached value is returned, and
     not re-evaluated.
+    
     """
+    
+    
     def __init__(self, func):
         self.func = func
         self.cache = {}
+        
+        
     def __call__(self, *args):
         try:
             return self.cache[args]
@@ -36,53 +44,11 @@ class memoized(object):
             self.cache[args] = value = self.func(*args)
             return value
         except TypeError:
-            # uncachable -- for instance, passing a list as an argument.
-            # Better to not cache than to blow up entirely.
+            # uncatchable -- for instance, passing a list as an argument.
+            # Better to not catch it than to blow up entirely.
             return self.func(*args)
+    
+            
+    # Return the function's docstring.        
     def __repr__(self):
-        """Return the function's docstring."""
         return self.func.__doc__
-
-
-
-#def memoized(function, limit=None):
-#    if isinstance(function, int):
-#        def memoize_wrapper(f):
-#            return memoized(f, function)
-#
-#        return memoize_wrapper
-#
-#    dict = {}
-#    list = []
-#    def memoize_wrapper(*args, **kwargs):
-#       key = cPickle.dumps((args, kwargs))
-#       try:
-#          list.append(list.pop(list.index(key)))
-#       except ValueError:
-#          dict[key] = function(*args, **kwargs)
-#          list.append(key)
-#          if limit is not None and len(list) > limit:
-#             del dict[list.pop(0)]
-#
-#       return dict[key]
-
-#    memoize_wrapper._memoize_dict = dict
-#    memoize_wrapper._memoize_list = list
-#    memoize_wrapper._memoize_limit = limit
-#    memoize_wrapper._memoize_origfunc = function
-#    memoize_wrapper.func_name = function.func_name
-#    return memoize_wrapper
-
-
-
-#@memoized
-#def fibonacci(n):
-#   "Return the nth fibonacci number."
-#   print n
-#   if n in (0, 1):
-#      return n
-#   val = fibonacci(n-1) + fibonacci(n-2)
-#   return val#
-#
-#fibonacci(5)
-#fibonacci(12)
diff --git a/shinken/message.py b/shinken/message.py
index 75efab2..9d09253 100644
--- a/shinken/message.py
+++ b/shinken/message.py
@@ -1,35 +1,44 @@
 #!/usr/bin/env python
-#Copyright (C) 2009-2010 :
-#    Gabes Jean, naparuba at gmail.com
-#    Gerhard Lausser, Gerhard.Lausser at consol.de
-#    Gregory Starck, g.starck at gmail.com
-#    Hartmut Goebel, h.goebel at goebel-consult.de
+
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009-2011 :
+#     Gabes Jean, naparuba at gmail.com
+#     Gerhard Lausser, Gerhard.Lausser at consol.de
+#     Gregory Starck, g.starck at gmail.com
+#     Hartmut Goebel, h.goebel at goebel-consult.de
 #
-#This file is part of Shinken.
+# This file is part of Shinken.
 #
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 #
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
 #
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
+
 
 
-#Tis is a simple message class for communications between actionners and
-#workers
 
 
 class Message:
+    """This is a simple message class for communications between actionners and
+    workers
+    
+    """
+
     my_type = 'message'
     _type = None
     _data = None
     _from = None
+    
+    
     def __init__(self, id, type, data=None, source=None):
         self._type = type
         self._data = data

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list