Exemplo n.º 1
0
def main(args=None):
    if not os.path.exists(conf.app_data):
        conf.init_appdata(conf.app_data)
    
    if args is None:
        args = sys.argv[1:]
    
    parser = OptionParser(
        usage='pypentago [options] [servers]',
        version='pypentago ' + __version__
    )
    
    parser.add_option('--verbose', '-v', action='count', dest='verbose',
                      help="Increase verbosity. Use -vv for very verbose",
                      default=0)
    
    parser.add_option('--quiet', '-q', action='count', dest='quiet', 
                      help="Show only error messages", default=0)
    
    parser.add_option('--reset-config', action='store_true', dest='reset_conf',
                      default=False, help="Reset the config files.")
    
    options, args = parser.parse_args(args)
    verbosity = verbosity_levels[options.verbose - options.quiet]
    
    if options.reset_conf:
        conf.init_client_conf(conf.app_data)
        if verbosity <= 20:
            # -v or -vv
            print "Reset client configuration file."
        # We're done.
        return 0
    
    var = {'appdata': conf.app_data}
    
    config = ConfigParser()
    config.read(conf.possible_configs('client.ini'))
    
    logfile = config.get("client", "logfile", vars=var)
    
    servers = conf.parse_servers(config)
    connect = []
    for arg in args:
        if arg in servers:
            connect.append(servers[arg])
        else:
            connect.append(util.parse_connect(arg))
    connect.extend(server for server in servers.itervalues()
                   if server.autoconnect)
    
    pypentago.init_logging(logfile, verbosity)
    log = logging.getLogger("pypentago.client")
    interface.main(connect, servers.values())
Exemplo n.º 2
0
 def dump_config(self):
     config = conf.possible_configs('client.ini').next()
     parser = ConfigParser()
     parser.read(config)
     
     for section in parser.sections():
         if section not in ['client', 'servers']:
             parser.remove_section(section)
     
     for server in self.serverinfos:
         server.dump(parser)
     
     with open(config, 'w') as fp:
         parser.write(fp)
Exemplo n.º 3
0
                 )
        )
    
    def dump_config(self):
        config = conf.possible_configs('client.ini').next()
        parser = ConfigParser()
        parser.read(config)
        
        for section in parser.sections():
            if section not in ['client', 'servers']:
                parser.remove_section(section)
        
        for server in self.serverinfos:
            server.dump(parser)
        
        with open(config, 'w') as fp:
            parser.write(fp)


if __name__ == '__main__':
    config = ConfigParser()
    config.read(conf.possible_configs('client.ini'))
        
    servers = conf.parse_servers(config)
    
    app = QtGui.QApplication(sys.argv)
    s = ServerBrowser()
    s.set_servers(servers.values())
    s.show()
    app.exec_()
Exemplo n.º 4
0
def main(args=None):
    if not os.path.exists(conf.app_data):
        conf.init_appdata(conf.app_data)
    
    if args is None:
        args = sys.argv[1:]
    
    parser = OptionParser(version='pypentago ' + __version__)
    parser.add_option("-d", "--daemon", action="store_true", 
                      dest="daemon", default=None,
                      help="start server as daemon. POSIX only!")
    
    parser.add_option("-p", "--port", action="store", default=None,
                      type="int", dest="port", metavar="PORT",
                      help="start server on port PORT")
    
    parser.add_option('--verbose', '-v', action='count', dest='verbose',
                      help="Increase verbosity. Use -vv for very verbose",
                      default=0)
    
    parser.add_option('--quiet', '-q', action='count', dest='quiet', 
                      help="Show only error messages", default=0)
    
    parser.add_option('--reset-config', action='store_true', dest='reset_conf',
                      default=False, help="Reset the config files.")
    
    options, args = parser.parse_args(args)
    verbosity = verbosity_levels[options.verbose - options.quiet]
    
    if options.reset_conf:
        conf.init_server_conf(conf.app_data)
        if verbosity <= 20:
            # -v or -vv
            print "Reset server configuration file."
        # We're done.
        return 0
    
    config = ConfigParser()
    config.read(conf.possible_configs('server.ini'))
    
    if options.port is None:
        port = config.getint("server", "port")
    else:
        port = options.port
    
    var = {'appdata': conf.app_data, 'port': port}
    
    if options.daemon is None:
        daemonize = config.getboolean("server", "daemon")
    else:
        daemonize = options.daemon
    
    pid_filename = os.path.abspath(
        config.get("server", "pidfile", vars=var)
    )
    connect_string = config.get("server", 'database', vars=var)
    logfile = config.get("server", "logfile", vars=var)
    
    pypentago.init_logging(logfile, verbosity)
    log = logging.getLogger("pypentago.server")
    
    if daemonize:
        from pypentago.server import daemon
        daemon.daemonize(True, cwd='/')
        with open(pid_filename, "w") as pid_file:
            pid_file.write(str(os.getpid()))
    try:
        server.run_server(port, connect_string)
    finally:
        if daemonize:
            os.remove(pid_filename)