<commit_before>#!/usr/bin/env python3
#
# Program to run a command via netrepl on a destination host
#
# author: ulno
# create date: 2017-09-16
#

import time
from netrepl import Netrepl_Parser
import sys, select

_debug="netrepl command:"

def main():
    parser = Netrepl_Parser('Connect to netrepl and run'
                            'a command.',
                            debug=_debug)
    parser.parser.add_argument('-t','--timeout',
                               type=int, required=False, default = 60,
                               help='Seconds to wait for command '
                                    'to finish (default 60)')
    parser.parser.add_argument('-c','--command',
                               type=str, nargs="+", required=True,
                               help='A command to execute remotely.')

    con = parser.connect()
    data=con.repl_command(" ".join(parser.args.command),
                          timeoutms=parser.args.timeout*1000)
    if data==None:
        if _debug: print(_debug, 'Timeout occured.')
    else:
        try:
            sys.stdout.write(data.decode())
        except:
            if _debug:
                print("\r\n{} Got some weird data of len "
                      "{}: >>{}<<\r\n".format(_debug, len(data), data))
        sys.stdout.flush()

    if _debug: print("\r\n{} Closing connection.\r".format(_debug))
    con.repl_normal()  # normal repl
    con.close(report=True)
    if _debug: print("\r\n{} Connection closed.\n".format(_debug))


# main function
if __name__ == "__main__":
    main()<commit_msg>print output in end and detect timeout<commit_after>#!/usr/bin/env python3
#
# Program to run a command via netrepl on a destination host
#
# author: ulno
# create date: 2017-09-16
#

import time
from netrepl import Netrepl_Parser
import sys, select

_debug="netrepl command:"

def main():
    parser = Netrepl_Parser('Connect to netrepl and run'
                            'a command.',
                            debug=_debug)
    parser.parser.add_argument('-t','--timeout',
                               type=int, required=False, default = 60,
                               help='Seconds to wait for command '
                                    'to finish (default 60)')
    parser.parser.add_argument('-c','--command',
                               type=str, nargs="+", required=True,
                               help='A command to execute remotely.')

    con = parser.connect()
    data=con.repl_command(" ".join(parser.args.command),
                          timeoutms=parser.args.timeout*1000)
    if data is None:
        if _debug: print(_debug, 'Timeout occurred, data discarded.')
    else:
        if _debug: print(_debug, 'Data successfully received.')
    if _debug: print("{} Closing connection.".format(_debug))
    con.repl_normal()  # normal repl
    con.close(report=True)
    if _debug: print("{} Connection closed.".format(_debug))
    if data is None:
        sys.exit(1)  # not successful
    else:
        if _debug: print(_debug,"Output follows starting from next line.")
        try:
            sys.stdout.write(data.decode())
        except:
            if _debug:
                print("{} Got some weird data of len "
                      "{}: >>{}<<".format(_debug, len(data), data))
        sys.stdout.flush()


# main function
if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.12363529064620832, 'fraction_numerical': 0.010327530244910003, 'mean_word_length': 1.851135407905803, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6922464', 'n_tokens_mistral': 978, 'n_tokens_neox': 941, 'n_words': 255}