ppf/new: Update code according to PEP 8.
[cs-p2p-next.git] / ppf / new / config.py
index 5e08598..84f3a14 100644 (file)
@@ -26,7 +26,8 @@ ch = logging.StreamHandler()
 ch.setLevel(logging.DEBUG)
 
 # Create formatter.
-formatter = logging.Formatter('%(filename)s:%(lineno)s - %(levelname)s: %(message)s')
+formatter = logging.Formatter('%(filename)s:%(lineno)s - '
+                              '%(levelname)s: %(message)s')
 
 # Add formatter to console handler.
 ch.setFormatter(formatter)
@@ -34,15 +35,22 @@ ch.setFormatter(formatter)
 # Add console handler to logger.
 logger.addHandler(ch)
 
+
 class SwarmDescription(object):
+
+    """Swarm Description class based on ConfigParser."""
+
     def __init__(self):
+        """Initialize the data field as an instance of ConfigParser()."""
         self.data = ConfigParser.ConfigParser()
 
     def load(self, swarm_config_file):
-        """ Load configuration file and use ConfigParser.
-        Expect configuration file without first section for swarm information.
+        """Load configuration file.
 
+        Expect configuration file without first section for swarm information.
+        Ignore tabs in configuration file.
         """
+
         NOSECTION = 'swarm'
         try:
             text = open(swarm_config_file).read()
@@ -53,13 +61,13 @@ class SwarmDescription(object):
         self.data.readfp(f)
 
     def store(self, ini_file):
-        """ Write configuration information to file. """
+        """Write configuration information to file."""
         f = open(ini_file, 'w')
         self.data.write(f)
         f.close()
 
     def get_swarm(self):
-        """ Return Swarm object containing information from config file. """
+        """Return Swarm object containing information from config file."""
         swarm_data = dict(self.data.items('swarm'))
         swarm = storage.Swarm(swarm_data['torrent_filename'],
                               swarm_data['data_size'],
@@ -67,7 +75,7 @@ class SwarmDescription(object):
         return swarm
 
     def get_session_entries(self):
-        """ Return list of SessionEntry instances. """
+        """Return list of SessionEntry instances."""
         session_names = self.data.sections()
         session_names.remove('swarm')
         session_list = []
@@ -80,13 +88,13 @@ class SwarmDescription(object):
         return session_list
 
     def update_session_entry_id(self, session_entry, cs_id):
-        """ Add or modify client session id. """
+        """Add or modify client session id in self and session_entry."""
         session_name = session_entry.data.sections()[0]
         self.data.set(session_name, 'client_session_id', str(cs_id))
         session_entry.data.set(session_name, 'client_session_id', str(cs_id))
 
     def get_file_archives(self):
-        """ Return a list containing all archives from swarm. """
+        """Return a list containing all archives from swarm."""
         archives = []
         for section in self.data.sections():
             try:
@@ -95,13 +103,18 @@ class SwarmDescription(object):
                 pass
         return archives
 
+
 class SessionEntry(object):
+
+    """Session Description class based on ConfigParser."""
+
     def __init__(self, session):
+        """Initialize the data field as an instance of ConfigParser()."""
         self.data = ConfigParser.ConfigParser()
         self.data.add_section(session)
 
     def get_session(self):
-        """ Return name of the session. """
+        """Return name of the session."""
         session = self.data.sections()[0]
         cs_data = dict(self.data.items(session))
         cs = storage.ClientSession(
@@ -122,10 +135,11 @@ class SessionEntry(object):
         return cs
 
     def get_session_id(self):
-        """ Return client session id corresponding to the entry.
-        If the session entry hasn't been asigned a session id raise error.
+        """Return client session id corresponding to the entry.
 
+        If the session entry hasn't been asigned a session id raise error.
         """
+
         section = self.data.sections()[0]
         try:
             cs_id = self.data.get(section, 'client_session_id')
@@ -134,12 +148,17 @@ class SessionEntry(object):
             logger.debug("No client session id for entry: %s" %section)
             return None
 
+
 class AccessConfig(object):
+
+    """Access Configuration class based on ConfigParser."""
+
     def __init__(self):
+        """Initialize the data field as an instance of ConfigParser()."""
         self.data = ConfigParser.ConfigParser()
 
     def load(self, access_config_file):
-        """ Load configuration file and use ConfigParser. """
+        """Load configuration file."""
         try:
             text = open(access_config_file).read()
         except IOError:
@@ -149,17 +168,18 @@ class AccessConfig(object):
         self.data.readfp(f)
 
     def store(self, ini_file):
-        """ Write configuration information to file. """
+        """Write configuration information to file."""
         f = open(ini_file, 'w')
         self.data.write(f)
         f.close()
 
     def get_swarm_writer(self):
-        """ Return storage.SwarmWriter instance.
-        For each section create coresponding storage.*Access instance
-        and add to SwarmWriter.handlers list.
+        """Return storage.SwarmWriter instance.
 
+        For each section create coresponding storage.*Access instance
+        and add it to SwarmWriter.handlers list.
         """
+
         sw = storage.SwarmWriter()
         for section in self.data.sections():
             if section == 'mysql':