コード例 #1
0
ファイル: cleos.py プロジェクト: tyler2018/eosfactory
    def __init__(self, args, first, second, is_verbose=True):
        self.out_msg = None
        self.out_msg_details = None
        self.err_msg = None
        self.json = {}
        self.is_verbose = is_verbose

        cl = [config.cli_exe()]
        set_local_nodeos_address_if_none()
        cl.extend(["--url", setup.nodeos_address()])

        if setup.is_print_request:
            cl.append("--print-request")
        if setup.is_print_response:
            cl.append("--print-response")

        cl.append(first)
        cl.extend(re.sub(re.compile(r'\s+'), ' ', second.strip()).split(" "))
        cl.extend(args)
        self.args = args

        if setup.is_print_command_line:
            print("command line sent to cleos:")
            print(" ".join(cl))
            print("")

        while True:
            process = subprocess.run(
                cl,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=str(pathlib.Path(config.cli_exe()).parent)) 

            self.out_msg = process.stdout.decode("ISO-8859-1")
            self.out_msg_details = process.stderr.decode("ISO-8859-1")
            self.err_msg = None
            error_key_words = ["ERROR", "Error", "error", "Failed"]
            for word in error_key_words:
                if word in self.out_msg_details:
                    self.err_msg = self.out_msg_details
                    self.out_msg_details = None
                    break

            if not self.err_msg or self.err_msg and \
                    not "Transaction took too long" in self.err_msg:
                break

        errors.validate(self)
            
        try:
            self.json = json.loads(self.out_msg)
        except:
            pass

        try:
            self.json = json.loads(self.out_msg_details)
        except:
            pass        
コード例 #2
0
    def __init__(self, args, first, second, is_verbose=True):
        self.out_msg = None
        self.out_msg_details = None
        self.err_msg = None
        self.json = {}
        self.is_verbose = is_verbose

        cl = [config.cli_exe()]
        set_local_nodeos_address_if_none()
        cl.extend(["--url", setup.nodeos_address()])

        if setup.is_print_request:
            cl.append("--print-request")
        if setup.is_print_response:
            cl.append("--print-response")

        cl.extend([first, second])
        cl.extend(args)
        self.args = args

        if setup.is_print_command_line:
            print("command line sent to cleos:")
            print(" ".join(cl))
            print("")

        process = subprocess.run(cl,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 cwd=str(
                                     pathlib.Path(config.cli_exe()).parent))

        self.out_msg = process.stdout.decode("utf-8")
        self.out_msg_details = process.stderr.decode("utf-8")
        error_key_words = ["ERROR", "Error", "error", "Failed"]
        for word in error_key_words:
            if word in self.out_msg_details:
                self.err_msg = self.out_msg_details
                self.out_msg_details = None
                break

        errors.validate(self)

        try:
            self.json = json.loads(self.out_msg)
        except:
            pass

        try:
            self.json = json.loads(self.out_msg_details)
        except:
            pass
コード例 #3
0
def cli_exe():
    '''Return a cleos executable.
    '''
    return config.cli_exe()