예제 #1
0
파일: test_config.py 프로젝트: loum/itt
 def test_call_missing_section(self):
     """Test call to a missing configuration section.
     """
     c = itt.ServerConfig()
     c.server = 'bogus'
     with self.assertRaises(KeyError):
         c.lookup
예제 #2
0
def main():
    parser = argparse.ArgumentParser(description='ittserverd')
    parser.add_argument('server_type',
                        choices=['ftp', 'tftp', 'http'],
                        help='The type of server to control')
    parser.add_argument('action',
                        choices=['start', 'stop', 'restart', 'status'],
                        help='The action to be performed on the server')
    args = parser.parse_args()

    # Select the correct server type with appropriate kwargs.
    server = itt.ServerConfig(server=args.server_type)
    try:
        daemon = getattr(*server.lookup)(**server.kwargs)
    except KeyError:
        err_msg = ('Server "%s" config section does not exist.' %
                   args.server_type)
        sys.stderr.write('ERROR: %s' % err_msg)
        sys.exit(1)

    # Take appropriate action.
    if args.action == "start":
        daemon.start()
    elif args.action == "stop":
        daemon.stop()
    elif args.action == "restart":
        daemon.restart()
    elif args.action == "status":
        if daemon.status():
            print '%s is running with PID: %d' % (args.server_type, daemon.pid)
        else:
            print '%s is not running' % args.server_type
예제 #3
0
파일: test_config.py 프로젝트: loum/itt
    def test_parse_config(self):
        """Test initial parsing of the configuration settings.
        """
        c = itt.ServerConfig(server='ftp')

        # Override the settings attribute with some bogus data.
        c.settings = """
[bogus]
item01 = item01 value
item02 = item02 value
"""

        # First call to config property attribute will parse settings.
        msg = 'Bogus config section value for "item01" incorrect'
        received = c.config.get('bogus', 'item01')
        expected = 'item01 value'
        self.assertEqual(received, expected, msg)
예제 #4
0
def list():
    """Display parsed configuraton items to stdout.

    For example:

        >>> from itt.server.config import list
        >>> itt.server.config.list()
        Section: ftp
        Options: ['root', 'port', 'pidfile']
        root = /tmp
        port = 2121
        pidfile = /tmp/ittserverd.ftp.pid
        ...

    """
    c = itt.ServerConfig()
    for section_name in c.config.sections():
        print('Section: %s' % section_name)
        print('\tOptions: %s' % c.config.options(section_name))
        for name, value in c.config.items(section_name):
            print('\t%s = %s' % (name, value))
        print
예제 #5
0
    def status(self):
        server = itt.ServerConfig(server=self.protocol)
        daemon = getattr(*server.lookup)(**server.kwargs)

        return daemon.status()