Some docstrings.

portnov [2009-02-27 08:02:18]
Some docstrings.
Filename
configs.py
configsets.py
discovery.py
machines.py
diff --git a/configs.py b/configs.py
index ba58d95..b1af638 100644
--- a/configs.py
+++ b/configs.py
@@ -4,12 +4,21 @@ from lxml import etree
 import templates
 import xmlserialize as xml

+# Dictionary: Template -> List of configs with that template
 bytemplate = {}
+
+# Dictionary: Config ID -> Config
 byid = {}
+
+# Dictionary: Template name -> Template
 config_templates = {}
+
+# Last allocated config ID
 lastid = 0

 def add_config(template_name, cfg):
+    "Register config in `bytemplate'"
+
     global bytemplate
     if template_name in bytemplate:
         bytemplate[template_name].append(cfg)
@@ -17,6 +26,9 @@ def add_config(template_name, cfg):
         bytemplate[template_name] = [cfg]

 def read_template(path):
+    """Read config template from XML file.
+    Returns python class. Instances of that class are configs."""
+
     global config_templates

     class ConfigTemplate(object):
@@ -33,6 +45,8 @@ def read_template(path):
             if not hasattr(self,'id'):
                 lastid += 1
                 self.id = lastid
+            else:
+                lastid = self.id
             byid[self.id] = self

         def __call__(self,**kwargs):
@@ -92,6 +106,9 @@ def read_template(path):
     return ConfigTemplate

 def read_config(path):
+    """Read config from XML file.
+    Returns config object."""
+
     global config_templates
     xmldata = open(path).read()
     xmlcfg = xml.deserialize(xmldata)
diff --git a/configsets.py b/configsets.py
index 0f6f685..3954d50 100644
--- a/configsets.py
+++ b/configsets.py
@@ -4,6 +4,7 @@ from lxml import etree
 import configs

 class ConfigSet(dict):
+    """Set of configs, maximum 1 per program"""
     def __init__(self,name):
         dict.__init__(self)
         self.name = name
@@ -39,6 +40,7 @@ class ConfigSet(dict):
         f.close()

 def read_configset(dir,filename):
+    "Read configset (and all it's configs) from XML file"
     cset = ConfigSet('')
     spath = join(dir,'configsets',filename)
     xml = etree.parse(spath).getroot()
diff --git a/discovery.py b/discovery.py
index 2f91ff7..1e53732 100644
--- a/discovery.py
+++ b/discovery.py
@@ -15,6 +15,7 @@ services = {}
 def err(str):
     print "Error:", str

+# Shorter names of services
 servicenames = {'_ssh._tcp':  'ssh',
                 '_http._tcp': 'web',
                 '_ftp._tcp':  'ftp',
@@ -23,6 +24,8 @@ servicenames = {'_ssh._tcp':  'ssh',
                 '_nameserver._udp': 'dns'}

 class Browser(threading.Thread):
+    "Browse network for services, using zeroconf/avahi"
+
     def __init__(self,group=None,target=None,name=None,args=(), kwargs=None,verbose=None):
         threading.Thread.__init__(self)
         self.types = args
diff --git a/machines.py b/machines.py
index 5378f0b..92996ff 100644
--- a/machines.py
+++ b/machines.py
@@ -11,6 +11,8 @@ class Host(object):
         return "<Host %s>" % self.hostname

 class PriorityList(list):
+    """Something like python list,
+    but automatically exntends when assigning non-existing items."""
     def __setitem__(self,idx,val):
         if idx >= len(self):
             self.extend([None]*(idx-len(self)))
@@ -31,6 +33,7 @@ class PriorityList(list):
 bypriority = PriorityList()

 class MachinesGroup(object):
+    "Group of machines"
     def __init__(self,name,load=False,*args):
         global lastpriority
         global groups
ViewGit