コード例 #1
0
ファイル: todo_server.py プロジェクト: philarin/Todo
    settings_group.add_argument('-P', '--port', type=int, dest='port',
            help='Port for the server to bind to.')
    settings_group.add_argument('-t', '--default-tag', dest='default_tag',
            help='Tag to default to when a task is created without a tag.')
    settings_group.add_argument('-n', '--hostname', dest='hostname',
            help='MySQL hostname to use. Defaults to "todo".')
    settings_group.add_argument('-u', '--username', dest='username',
            help='MySQL username to use. Defaults to "todo".')
    settings_group.add_argument('-p', '--password', dest='password',
            help='MySQL password to use. Defaults to "todo".')
    settings_group.add_argument('-d', '--database', dest='database',
            help='MySQL database to use. Defaults to "todo".')
    args = vars(parser.parse_args())

    config_structure = {'Todo' : ['port', 'default_tag'], 'MySQL' : ['hostname',
            'username', 'password', 'database']}
    config = todo_config.get_config(args, config_structure)

    # Start the Server with the port or the default
    server = Server()
    if 'port' in config:
        server.start(config['port'])
        del config['port']
    else:
        server.start(Server.DEFAULT_PORT)

    # Accept incoming connections and run them in separate threads
    while True:
        connection = ServerThread(server.accept(), config)
        connection.start()