<commit_before># -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.

# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.GPL" in the source distribution for more information.

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

"""flumotion-admin-text entry point, command line parsing and invokation"""

import curses

from twisted.internet import reactor

from flumotion.admin.text import connection
from flumotion.admin.text.greeter import AdminTextGreeter
from flumotion.common import messages # make Message proxyable
from flumotion.common.options import OptionParser

__version__ = "$Rev$"


def cleanup_curses(stdscr):
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()


def _runInterface(options):
    # initialise curses

    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.nodelay(1)
    stdscr.keypad(1)

    reactor.addSystemEventTrigger('after',
                                  'shutdown', cleanup_curses, stdscr)


    # first lets sort out logging in
    username = 'user'
    password = '<PASSWORD>'
    hostname = 'localhost'
    insecure = False
    port = 7531
    if options.username and options.password and options.hostname:
        username = options.username
        password = options.password
        hostname = options.hostname
        if options.port:
            try:
                port = int(options.port)
            except ValueError:
                pass
        if options.insecure:
            insecure = True
        connection.connect_to_manager(stdscr, hostname, port,
                                      insecure, username, password)

    else:
        # do greeter
        # get recent connections
        greeter = AdminTextGreeter(stdscr)
        reactor.addReader(greeter)
        greeter.show()


def main(args):
    parser = OptionParser(domain="flumotion-admin-text")
    parser.add_option('-u', '--username',
                      action="store", type="string", dest="username",
                      help="set username to connect to manager")
    parser.add_option('-P', '--password',
                      action="store", type="string", dest="password",
                      help="set password to connect to manager")
    parser.add_option('-H', '--hostname',<commit_msg>Use PBConnectionInfo when logging in to a manager from the command line.<commit_after># -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.

# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.GPL" in the source distribution for more information.

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

"""flumotion-admin-text entry point, command line parsing and invokation"""

import curses

from twisted.internet import reactor

from flumotion.admin.text import connection
from flumotion.admin.text.greeter import AdminTextGreeter
from flumotion.common import messages # make Message proxyable
from flumotion.common.options import OptionParser
from flumotion.common.connection import PBConnectionInfo
from flumotion.twisted import pb as fpb

__version__ = "$Rev$"


def cleanup_curses(stdscr):
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()


def _runInterface(options):
    # initialise curses

    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.nodelay(1)
    stdscr.keypad(1)

    reactor.addSystemEventTrigger('after',
                                  'shutdown', cleanup_curses, stdscr)


    # first lets sort out logging in
    username = 'user'
    password = '<PASSWORD>'
    hostname = 'localhost'
    insecure = False
    port = 7531
    if options.username and options.password and options.hostname:
        username = options.username
        password = options.password
        hostname = options.hostname
        if options.port:
            try:
                port = int(options.port)
            except ValueError:
                pass
        if options.insecure:
            insecure = True
        authenticator = fpb.Authenticator(username=username, password=password)
        info = PBConnectionInfo(hostname, port, not insecure, authenticator)
        connection.connect_to_manager(stdscr, info)

    else:
        # do greeter
        # get recent connections
        greeter = AdminTextGreeter(stdscr)
        reactor.addReader(greeter)
        greeter.show()


def main(args):
    parser = OptionParser(domain="flumotion-admin-text")
    parser.add_option('-u', '--username',
                      action="store", type="string", dest="username",
                      help="set username to connect to manager")
    parser.add_option('-P', '--password',
                      action="store", type="string", dest="password",
                      help="set password to connect to manager")
    parser.add_option('-H', '--hostname',
{'fraction_non_alphanumeric': 0.08818255908720457, 'fraction_numerical': 0.008801955990220049, 'mean_word_length': 2.8786346396965867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6787312', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1644, 'n_words': 533}