config.py :  » Network » FtpCube » ftpcube-0.5.1 » libftpcube » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » FtpCube 
FtpCube » ftpcube 0.5.1 » libftpcube » config.py
"""
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.