"""
FtpCube
Copyright (C) Michael Gilfix
This file is part of FtpCube.
You should have received a file COPYING containing license terms
along with this program; if not, write to Michael Gilfix
(mgilfix@eecs.tufts.edu) for a copy.
This version of FtpCube is open source; you can redistribute it and/or
modify it under the terms listed in the file COPYING.
This program 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.
"""
from libftpcube.transports.loader import FTP_TRANSPORT
from libftpcube import parser# Avoids conflict with python library
fromprotocolProtocolInterface
import os
import exceptions
import ConfigParser
# Copy the parser error into the module space
ParserError = parser.ParserError
class Configuration(parser.SimpleConfigParser):
"""Class for initializing, managing, reading, and writing configuration data.
This class is initialized with a path to the application configuration. If
no directory containing the file exists, then the directory is created. If
the file does not exist, then it is initialized with a default configuration.
The configuration file is read during initialization. Changes are held in
memory until explicitly saved.
This class uses the INI file style to store configuration attributes to make
them easier to read by a human. To simplify serialization, some string
coercing is performed on write and then the content evaluated at read.
This object should be used like a dictionary to get/set configuration
options."""
# Section header name
SECTION = 'ftpcube'
def __init__(self, file):
"""Loads the application configuration from the specified configuration
file.
If the specified file does not exist, it is created and initialized with
application defaults."""
if __debug__:
print "Initializing configuration from file: %s" %file
parser.SimpleConfigParser.__init__(self, file, self.SECTION)
if __debug__:
print "Loaded configuration:"
options = self.getOptions()
for key in options:
print "\t'%s' : %s" %(key, str(self[key]))
def getDefaults(self):
"""Gets a dictionary containing default configuration values."""
defaults = {
'host' : None,
'port' : 21,
'username' : 'anonymous',
'password' : 'guest@anon.com',
'timeout' : 120,
'localdir' : None,
'limit' : None,
'thread_idle' : 30,
'main_idle' : 300,
'delay' : 5,
'retries' : 5,
'passive' : True,
'transport' : FTP_TRANSPORT,
'remotedir' : None,
'logging' : False,
'cmd_log' : 'commands.txt',
'download_log' : 'download.txt',
'upload_log' : 'upload.txt',
'local_color' : (55, 24, 112),
'remote_color' : (43, 95, 48),
'error_color' : (115, 24, 39),
'transfer_type' : ProtocolInterface.BINARY,
'win_size' : (0, 0),
'max_threads' : 3
}
return defaults
|