예제 #1
0
def node_start(clear=False, nodeos_stdout=None, verbosity=None):
    args_ = args(clear)

    if setup.is_print_command_line:
        print("nodeos command line:")
        print(config.node_exe() + " " + " ".join(args_))

    if config.is_nodeos_in_window():
        if is_windows_ubuntu():
            args_.insert(0, config.node_exe())
            subprocess.call([
                "cmd.exe", "/c", "start", "/MIN", "bash.exe", "-c",
                " ".join(args_)
            ])
        elif uname() == "Darwin":
            subprocess.Popen("open -a " + config.node_exe() + " --args " +
                             " ".join(args_),
                             shell=True)
        else:
            args_.insert(0, config.node_exe())
            subprocess.Popen("gnome-terminal -- " + " ".join(args_),
                             shell=True)
    else:
        if not nodeos_stdout:
            nodeos_stdout = config.nodeos_stdout()

        std_out_handle = subprocess.DEVNULL
        if nodeos_stdout:
            try:
                std_out_handle = open(nodeos_stdout, 'w')
            except Exception as e:
                raise errors.Error('''
Error when preparing to start the local EOS node, opening the given stdout
log file that is 
{}
Error message is
{}
                '''.format(nodeos_stdout, str(e)))

        def onExit():
            if not std_out_handle == subprocess.DEVNULL:
                try:
                    std_out_handle.close()
                except:
                    pass

        args_.insert(0, config.node_exe())

        def runInThread():
            proc = subprocess.Popen(" ".join(args_),
                                    stdin=subprocess.DEVNULL,
                                    stdout=std_out_handle,
                                    stderr=subprocess.DEVNULL,
                                    shell=True)
            proc.wait()
            onExit()
            return

        thread = threading.Thread(target=runInThread)
        thread.start()
예제 #2
0
파일: teos.py 프로젝트: kdmukai/eosfactory
def node_start(clear=False, nodeos_stdout=None):
    '''Start the local EOSIO node.

    Args:
        clear (bool): If set, the blockchain is deleted and then re-created.
        nodeos_stdout (str): If set, a file where *stdout* stream of
            the local *nodeos* is send. Note that the file can be included to 
            the configuration of EOSFactory, see :func:`.core.config.nodeos_stdout`.
            If the file is set with the configuration, and in the same time 
            it is set with this argument, the argument setting prevails. 
    '''

    args_ = args(clear)

    if not nodeos_stdout:
        nodeos_stdout = config.nodeos_stdout()

    global std_out_handle
    std_out_handle = subprocess.DEVNULL
    if nodeos_stdout:
        try:
            std_out_handle = open(nodeos_stdout, 'w')
        except Exception as e:
            raise errors.Error('''
Error when preparing to start the local EOS node, 
opening the given stdout log file that is 
{}
Error message is
{}
            '''.format(nodeos_stdout, str(e)))

    def onExit():
        global std_out_handle
        if not std_out_handle == subprocess.DEVNULL:
            try:
                std_out_handle.close()
            except:
                pass

    if setup.is_save_command_lines:
        setup.add_to__command_line_file(config.node_exe() + " " +
                                        " ".join(args_))
    if setup.is_print_command_lines:
        print("######## nodeos command line:")
        print(config.node_exe() + " " + " ".join(args_))

    args_.insert(0, config.node_exe())

    def runInThread():
        proc = subprocess.Popen(" ".join(args_),
                                stdin=subprocess.DEVNULL,
                                stdout=std_out_handle,
                                stderr=subprocess.DEVNULL,
                                shell=True)
        proc.wait()
        onExit()
        return

    thread = threading.Thread(target=runInThread)
    thread.start()