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)
# 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()
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'],
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 = []
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:
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(
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')
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:
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':