<commit_before>#!/usr/bin/python
#cmd_line.py
#
# <<<COPYRIGHT>>>
#
#
#
#

"""
.. module:: cmd_line

"""

import os
import sys

from twisted.internet import reactor
from twisted.web import xmlrpc

#------------------------------------------------------------------------------ 

def parser():
    """
    Create an ``optparse.OptionParser`` object to read command line arguments.
    """
    from optparse import OptionParser, OptionGroup
    from main.help import usage
    parser = OptionParser(usage=usage())
    group = OptionGroup(parser, "Logs")
    group.add_option('-d', '--debug',
                        dest='debug',
                        type='int',
                        help='set debug level',)
    group.add_option('-q', '--quite',
                        dest='quite',
                        action='store_true',
                        help='quite mode, do not print any messages to stdout',)
    group.add_option('-v', '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='verbose mode, print more messages',)
    group.add_option('-n', '--no-logs',
                        dest='no_logs',
                        action='store_true',
                        help='do not use logs',)
    group.add_option('-o', '--output',
                        dest='output',
                        type='string',
                        help='print log messages to the file',)
#    group.add_option('-t', '--tempdir',
#                        dest='tempdir',
#                        type='string',
#                        help='set location for temporary files, default is ~/.bitdust/temp',)
    group.add_option('--twisted',
                        dest='twisted',
                        action='store_true',
                        help='show twisted log messages too',)
#    group.add_option('--memdebug',
#                        dest='memdebug',
#                        action='store_true',
#                        help='start web server to debug memory usage, need cherrypy and dozer modules',)
    parser.add_option_group(group)
#    group = OptionGroup(parser, "Network")
#    group.add_option('--tcp-port',
#                        dest='tcp_port',
#                        type='int',
#                        help='set tcp port number for incoming connections',)
#    group.add_option('--no-upnp',
#                        dest='no_upnp',
#                        action='store_true',
#                        help='do not use UPnP',)
#    group.add_option('--memdebug-port',
#                        dest='memdebug_port',
#                        type='int',
#                        default=9996,
#                        help='set port number for memdebug web server, default is 9995',)    
#    parser.add_option_group(group)
    return parser


def override_options(opts, args):
    """
    The program can replace some user options by values passed via command line.
    This method return a dictionary where is stored a key-value pairs for new options.   
    """
    overDict = {}
    # if opts.tcp_port:
    #     overDict['transport.transport-tcp.transport-tcp-port'] = str(opts.tcp_port)
    # if opts.no_upnp:
    #     overDict['services/tcp-connections/upnp-enabled'] = 'false'
    # if opts.tempdir:
    #     overDict['folder.folder-temp'] = opts.tempdir
    if opts.debug or str(opts.debug) == '0':
        overDict['logs.debug-level'] = str(opts.debug)
#    if opts.memdebug:
#        overDict['logs.memdebug-enable'] = str(opts.memdebug)
#        if opts.memdebug_port:
#            overDict['logs.memdebug-port'] = str(opts.memdebug_port)
#        else:
#            overDict['logs.memdebug-port'] = '9996'
    return overDict

#------------------------------------------------------------------------------ 

def print_copyright():
    """
    Prints the copyright string.
    """
    print_text('Copyright BitDust, 2014. All rights reserved.')
    

def print_text(msg, nl='\n'):
    """
    """
    sys.stdout.write(msg+nl)


def print_exception():
    """
    This is second most common method in the project.
    Print detailed info about last exception to the logs.
    """
    import traceback
    cla, value, trbk = sys.exc_info()
    try:
        excArgs = value.__dict__["args"]
    except KeyError:
        excArgs = ''
    excTb = traceback.format_tb(trbk)    
    s = 'Exception: <' + str(value) + '>\n'
    if excArgs:
        s += '  args:' + excArgs + '\n'
    for l in excTb:
        s += l + '\n'
    sys.stdout.write(s)


def print_and_stop(result):
    """
    """
    print result
    import pprint
    pprint.pprint(result, indent=2,)
    # reactor.stop()
    
def fail_and_stop(err):
    try:
        print_text(err.getErrorMessage())
    except:
        print err
    # reactor.stop()

#------------------------------------------------------------------------------ 

def call_xmlrpc_method(method, *args):
    """
    Method to communicate with existing BitDust process.
    Reads port number of the local RPC server and do the request.
    """
    from system import bpio
    from main import settings<commit_msg>uncommented a couple lines in cmd_line.py<commit_after>#!/usr/bin/python
#cmd_line.py
#
# <<<COPYRIGHT>>>
#
#
#
#

"""
.. module:: cmd_line

"""

import os
import sys

from twisted.internet import reactor
from twisted.web import xmlrpc

#------------------------------------------------------------------------------ 

def parser():
    """
    Create an ``optparse.OptionParser`` object to read command line arguments.
    """
    from optparse import OptionParser, OptionGroup
    from main.help import usage
    parser = OptionParser(usage=usage())
    group = OptionGroup(parser, "Logs")
    group.add_option('-d', '--debug',
                        dest='debug',
                        type='int',
                        help='set debug level',)
    group.add_option('-q', '--quite',
                        dest='quite',
                        action='store_true',
                        help='quite mode, do not print any messages to stdout',)
    group.add_option('-v', '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='verbose mode, print more messages',)
    group.add_option('-n', '--no-logs',
                        dest='no_logs',
                        action='store_true',
                        help='do not use logs',)
    group.add_option('-o', '--output',
                        dest='output',
                        type='string',
                        help='print log messages to the file',)
#    group.add_option('-t', '--tempdir',
#                        dest='tempdir',
#                        type='string',
#                        help='set location for temporary files, default is ~/.bitdust/temp',)
    group.add_option('--twisted',
                        dest='twisted',
                        action='store_true',
                        help='show twisted log messages too',)
#    group.add_option('--memdebug',
#                        dest='memdebug',
#                        action='store_true',
#                        help='start web server to debug memory usage, need cherrypy and dozer modules',)
    parser.add_option_group(group)
#    group = OptionGroup(parser, "Network")
#    group.add_option('--tcp-port',
#                        dest='tcp_port',
#                        type='int',
#                        help='set tcp port number for incoming connections',)
#    group.add_option('--no-upnp',
#                        dest='no_upnp',
#                        action='store_true',
#                        help='do not use UPnP',)
#    group.add_option('--memdebug-port',
#                        dest='memdebug_port',
#                        type='int',
#                        default=9996,
#                        help='set port number for memdebug web server, default is 9995',)    
#    parser.add_option_group(group)
    return parser


def override_options(opts, args):
    """
    The program can replace some user options by values passed via command line.
    This method return a dictionary where is stored a key-value pairs for new options.   
    """
    overDict = {}
    # if opts.tcp_port:
    #     overDict['transport.transport-tcp.transport-tcp-port'] = str(opts.tcp_port)
    # if opts.no_upnp:
    #     overDict['services/tcp-connections/upnp-enabled'] = 'false'
    # if opts.tempdir:
    #     overDict['folder.folder-temp'] = opts.tempdir
    if opts.debug or str(opts.debug) == '0':
        overDict['logs.debug-level'] = str(opts.debug)
#    if opts.memdebug:
#        overDict['logs.memdebug-enable'] = str(opts.memdebug)
#        if opts.memdebug_port:
#            overDict['logs.memdebug-port'] = str(opts.memdebug_port)
#        else:
#            overDict['logs.memdebug-port'] = '9996'
    return overDict

#------------------------------------------------------------------------------ 

def print_copyright():
    """
    Prints the copyright string.
    """
    print_text('Copyright BitDust, 2014. All rights reserved.')
    

def print_text(msg, nl='\n'):
    """
    """
    sys.stdout.write(msg+nl)


def print_exception():
    """
    This is second most common method in the project.
    Print detailed info about last exception to the logs.
    """
    import traceback
    cla, value, trbk = sys.exc_info()
    try:
        excArgs = value.__dict__["args"]
    except KeyError:
        excArgs = ''
    excTb = traceback.format_tb(trbk)    
    s = 'Exception: <' + str(value) + '>\n'
    if excArgs:
        s += '  args:' + excArgs + '\n'
    for l in excTb:
        s += l + '\n'
    sys.stdout.write(s)


def print_and_stop(result):
    """
    """
    print result
    import pprint
    pprint.pprint(result, indent=2,)
    reactor.stop()
    
def fail_and_stop(err):
    try:
        print_text(err.getErrorMessage())
    except:
        print err
    reactor.stop()

#------------------------------------------------------------------------------ 

def call_xmlrpc_method(method, *args):
    """
    Method to communicate with existing BitDust process.
    Reads port number of the local RPC server and do the request.
    """
    from system import bpio
    from main import settings
{'fraction_non_alphanumeric': 0.16656999226604796, 'fraction_numerical': 0.0034802784222737818, 'mean_word_length': 1.5727430987316589, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6052752', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2783, 'n_words': 684}