<commit_before>#!/usr/bin/env python
# Copyright(C) 2012 <EMAIL>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# 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.  See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see
# <http://www.gnu.org/licenses/agpl.html>.

import time, sys, traceback, threading
import ConfigParser

import logging
logging.basicConfig()

if sys.maxsize <= 2**32:
    print "Warning: it looks like you are using a 32bit system. You may experience crashes caused by mmap"


def attempt_read_config(config, filename):
    try:
        with open(filename, 'r') as f:
            config.readfp(f)
    except IOError:
        pass

def create_config():
    config = ConfigParser.ConfigParser()
    # set some defaults, which will be overwritten by the config file
    config.add_section('server')
    config.set('server', 'banner', 'Welcome to Electrum!')
    config.set('server', 'host', 'localhost')
    config.set('server', 'stratum_tcp_port', '50001')
    config.set('server', 'stratum_http_port', '8081')
    config.set('server', 'stratum_tcp_ssl_port', '50002')
    config.set('server', 'stratum_http_ssl_port', '8082')
    config.set('server', 'password', '')
    config.set('server', 'irc', 'yes')
    config.set('server', 'irc_nick', '')
    config.set('server', 'coin', '')
    config.set('server', 'datadir', '')
    config.add_section('database')
    config.set('database', 'type', 'psycopg2')
    config.set('database', 'database', 'abe')
    config.set('database', 'limit', '1000')
    config.set('server', 'backend', 'abe')

    for path in ('/etc/', ''):
        filename = path + 'electrum.conf'
        attempt_read_config(config, filename)

    try:
        with open('/etc/electrum.banner', 'r') as f:
            config.set('server','banner', f.read())
    except IOError:
        pass

    return config

def run_rpc_command(command, stratum_tcp_port):
    import socket, json
    try:
        s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
        s.connect(( host, int(stratum_tcp_port )))
    except:
        print "cannot connect to server."
        return

    method = 'server.' + command
    request = json.dumps( { 'id':0, 'method':method, 'params':[password] } )
    s.send(request + '\n')
    msg = ''
    while True:
        o = s.recv(1024)
        msg += o
        if msg.find('\n') != -1: break
    s.close()
    r = json.loads(msg).get('result')

    if command == 'info': 
        now = time.time()
        print 'type           address   sub  version  time' 
        for item in r:
            print '%4s   %15s   %3s  %7s  %.2f'%( item.get('name'), 
                                                  item.get('address'), 
                                                  item.get('subscriptions'), 
                                                  item.get('version'), 
                                                  (now - item.get('time')) )
    else:
        print r

if __name__ == '__main__':
    config = create_config()
    password = config.get('server', 'password')
    host = config.get('server', 'host')
    stratum_tcp_port = config.get('server', 'stratum_tcp_port')
    stratum_http_port = config.get('server', 'stratum_http_port')
    stratum_tcp_ssl_port = config.get('server', 'stratum_tcp_ssl_port')
    stratum_http_ssl_port = config.get('server', 'stratum_http_ssl_port')
    ssl_certfile = config.get('server', 'ssl_certfile')
    ssl_keyfile = config.get('server', 'ssl_keyfile')

    if stratum_tcp_ssl_port or stratum_http_ssl_port: assert ssl_certfile and ssl_keyfile 

    if len(sys.argv) > 1:
        run_rpc_command(sys.argv[1], stratum_tcp_port)
        sys.exit(0)

    from processor import Dispatcher, print_log
    from backends.irc import ServerProcessor

    backend_name = config.get('server', 'backend')
    if backend_name == 'abe':
        from backends.abe import BlockchainProcessor
    elif backend_name == 'libbitcoin':
        from backends.libbitcoin import BlockchainProcessor
    elif backend_name == 'bitcoind':
        from backends.bitcoind import BlockchainProcessor
    else:
        print "Unknown backend '%s' specified\n" % backend_name
        sys.exit(1)

    for i in range(5): print ""
    print_log( "Starting Electrum server on", host)

    # Create hub
    dispatcher = Dispatcher()
    shared = dispatcher.shared
<commit_msg>change name for config file<commit_after>#!/usr/bin/env python
# Copyright(C) 2012 <EMAIL>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# 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.  See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see
# <http://www.gnu.org/licenses/agpl.html>.

import time, sys, traceback, threading
import ConfigParser

import logging
logging.basicConfig()

if sys.maxsize <= 2**32:
    print "Warning: it looks like you are using a 32bit system. You may experience crashes caused by mmap"


def attempt_read_config(config, filename):
    try:
        with open(filename, 'r') as f:
            config.readfp(f)
    except IOError:
        pass

def create_config():
    config = ConfigParser.ConfigParser()
    # set some defaults, which will be overwritten by the config file
    config.add_section('server')
    config.set('server', 'banner', 'Welcome to Electrum!')
    config.set('server', 'host', 'localhost')
    config.set('server', 'stratum_tcp_port', '50001')
    config.set('server', 'stratum_http_port', '8081')
    config.set('server', 'stratum_tcp_ssl_port', '50002')
    config.set('server', 'stratum_http_ssl_port', '8082')
    config.set('server', 'password', '')
    config.set('server', 'irc', 'yes')
    config.set('server', 'irc_nick', '')
    config.set('server', 'coin', '')
    config.set('server', 'datadir', '')
    config.add_section('database')
    config.set('database', 'type', 'psycopg2')
    config.set('database', 'database', 'abe')
    config.set('database', 'limit', '1000')
    config.set('server', 'backend', 'abe')

    for path in ('/etc/', ''):
        filename = path + 'electrum.conf'
        attempt_read_config(config, filename)

    try:
        with open('/etc/electrum.banner', 'r') as f:
            config.set('server','banner', f.read())
    except IOError:
        pass

    return config

def run_rpc_command(command, stratum_tcp_port):
    import socket, json
    try:
        s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
        s.connect(( host, int(stratum_tcp_port )))
    except:
        print "cannot connect to server."
        return

    method = 'server.' + command
    request = json.dumps( { 'id':0, 'method':method, 'params':[password] } )
    s.send(request + '\n')
    msg = ''
    while True:
        o = s.recv(1024)
        msg += o
        if msg.find('\n') != -1: break
    s.close()
    r = json.loads(msg).get('result')

    if command == 'info': 
        now = time.time()
        print 'type           address   sub  version  time' 
        for item in r:
            print '%4s   %15s   %3s  %7s  %.2f'%( item.get('name'), 
                                                  item.get('address'), 
                                                  item.get('subscriptions'), 
                                                  item.get('version'), 
                                                  (now - item.get('time')) )
    else:
        print r

if __name__ == '__main__':
    config = create_config()
    password = config.get('server', 'password')
    host = config.get('server', 'host')
    stratum_tcp_port = config.get('server', 'stratum_tcp_port')
    stratum_http_port = config.get('server', 'stratum_http_port')
    stratum_tcp_ssl_port = config.get('server', 'stratum_tcp_ssl_port')
    stratum_http_ssl_port = config.get('server', 'stratum_http_ssl_port')
    ssl_certfile = config.get('server', 'ssl_certfile')
    ssl_keyfile = config.get('server', 'ssl_keyfile')

    if stratum_tcp_ssl_port or stratum_http_ssl_port: assert ssl_certfile and ssl_keyfile 

    if len(sys.argv) > 1:
        run_rpc_command(sys.argv[1], stratum_tcp_port)
        sys.exit(0)

    from processor import Dispatcher, print_log
    from backends.irc import ServerProcessor

    backend_name = config.get('server', 'backend')
    if backend_name == 'abe':
        from backends.abe import BlockchainProcessor
    elif backend_name == 'libbitcoin':
        from backends.libbitcoin import BlockchainProcessor
    elif backend_name == 'leveldb':
        from backends.bitcoind import BlockchainProcessor
    else:
        print "Unknown backend '%s' specified\n" % backend_name
        sys.exit(1)

    for i in range(5): print ""
    print_log( "Starting Electrum server on", host)

    # Create hub
    dispatcher = Dispatcher()
    shared = dispatcher.shared

{'fraction_non_alphanumeric': 0.1249095233171337, 'fraction_numerical': 0.010340192327577293, 'mean_word_length': 2.76196032672112, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1001300', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2849, 'n_words': 824}