コード例 #1
0
ファイル: fixtures.py プロジェクト: ottodevs/ether-academy
    def get(auction_address):
        Distributor = chain.provider.get_contract_factory('Distributor')
        distributor_contract = create_contract(Distributor, [auction_address])

        if print_the_logs:
            print_logs(distributor_contract, 'Distributed', 'Distributor')
            print_logs(distributor_contract, 'ClaimTokensCalled',
                       'Distributor')

        return distributor_contract
コード例 #2
0
    def watch_auction_distributed(self):
        def set_distribution_end(event):
            self.distribution_ended = True
            self.filter_bids.stop()
            self.filter_auction_end.stop()
            print('set_distribution_end')

        # watch_logs(self.auction, 'TokensDistributed', set_distribution_end)
        print_logs(self.auction, 'TokensDistributed', 'DutchAuction')
        print_logs(self.auction, 'TradingStarted', 'DutchAuction')

        self.filter_distributed = self.handle_auction_logs(
            'TokensDistributed', set_distribution_end)
コード例 #3
0
def test_args_from_subprocess(live_server):
    # train one model in project
    with tempfile.NamedTemporaryFile(prefix='test_',
                                     suffix='.csv',
                                     delete=True) as fd:
        pass
    bscore_name = 'batch_scoring'
    if os.name is 'nt':
        exe = sys.executable
        head = os.path.split(exe)[0]
        bscore_name = os.path.normpath(
            os.path.join(head, 'scripts', 'batch_scoring.exe'))
        assert os.path.isfile(bscore_name) is True
        assert os.path.supports_unicode_filenames is True
    arguments = ('{bscore_name} --host={webhost}/api'
                 ' --user={username}'
                 ' --password={password}'
                 ' --verbose'
                 ' --n_samples=10'
                 ' --n_concurrent=1'
                 ' --out={out}'
                 ' --no'
                 ' {project_id}'
                 ' {model_id}'
                 ' tests/fixtures/temperatura_predict.csv').format(
                     webhost=live_server.url(),
                     bscore_name=bscore_name,
                     username='******',
                     password='******',
                     project_id='56dd9570018e213242dfa93c',
                     model_id='56dd9570018e213242dfa93d',
                     out=fd.name)
    try:
        spc = subprocess.check_call(arguments.split(' '))
    except subprocess.CalledProcessError as e:
        print(e)
        print_logs()

    #  newlines will be '\r\n on windows and \n on linux. using 'rU' should
    #  resolve differences on different platforms
    with open(fd.name, 'rU') as o:
        actual = o.read()
    with open('tests/fixtures/temperatura_output.csv', 'rU') as f:
        expected = f.read()
    assert str(actual) == str(expected), str(actual)
    assert spc is 0
コード例 #4
0
def test_args_from_subprocess(live_server):
    # train one model in project
    with tempfile.NamedTemporaryFile(prefix='test_',
                                     suffix='.csv',
                                     delete=True) as fd:
        pass
    bscore_name = 'batch_scoring'
    if os.name is 'nt':
        exe = sys.executable
        head = os.path.split(exe)[0]
        bscore_name = os.path.normpath(os.path.join(head, 'scripts',
                                       'batch_scoring.exe'))
        assert os.path.isfile(bscore_name) is True
        assert os.path.supports_unicode_filenames is True
    arguments = ('{bscore_name} --host={webhost}/api'
                 ' --user={username}'
                 ' --password={password}'
                 ' --verbose'
                 ' --n_samples=10'
                 ' --n_concurrent=1'
                 ' --out={out}'
                 ' --no'
                 ' {project_id}'
                 ' {model_id}'
                 ' tests/fixtures/temperatura_predict.csv').format(
                    webhost=live_server.url(),
                    bscore_name=bscore_name,
                    username='******',
                    password='******',
                    project_id='56dd9570018e213242dfa93c',
                    model_id='56dd9570018e213242dfa93d',
                    out=fd.name)
    try:
        spc = subprocess.check_call(arguments.split(' '))
    except subprocess.CalledProcessError as e:
        print(e)
        print_logs()

    #  newlines will be '\r\n on windows and \n on linux. using 'rU' should
    #  resolve differences on different platforms
    with open(fd.name, 'rU') as o:
        actual = o.read()
    with open('tests/fixtures/temperatura_output.csv', 'rU') as f:
        expected = f.read()
    assert str(actual) == str(expected), str(actual)
    assert spc is 0
コード例 #5
0
def clock_in(config):
    try:
        flag = False

        while True:
            hour = utils.get_local_hour()

            if not flag and hour > 9:
                content = 'have not clock in yet!'
                utils.print_logs(content)

                if config['send_mail']:
                    utils.send_mail(config['mail_config'], 'Oh No', content)
                
            if flag and hour != 1:
                utils.wait_until_next_hour()
                continue

            flag = False

            try:
                headers = utils.sign_in(config['baidu_ocr'], config['sign_in_config'])

            except Exception as e:
                utils.handle_error(e)

            else:
                try:
                    clock_in_config = config['clock_in_config'][config['type_']]
                    utils.clock_in(clock_in_config, headers)

                except Exception as e:
                    utils.handle_error(e)
                    
                else:
                    flag = True
                    
                    content = 'Time to sleep!'

                    if config['send_mail']:
                        utils.send_mail(config['mail_config'], 'Clock In', content)
                        
                    utils.wait_until_next_hour()

    except KeyboardInterrupt:
        utils.print_logs('Stopped by Keyboard. Bye!')
コード例 #6
0
ファイル: stages.py プロジェクト: artur0us/raindeploy
    def local_shell_cmd(stage_name: str, stage_details: dict,
                        env_credentials: dict) -> Union[str, bool]:
        try:
            proc = subprocess.Popen(stage_details["cmd"],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    shell=True)
            proc_out, proc_err = proc.communicate()
            Data.logs.append(proc_out)
            Data.logs.append(proc_err)
            if Data.WORK_MODE == DEBUG_MODE:
                print_logs(proc_out, proc_err)

        except Exception as err:
            err_msg = "(local_shell_cmd) command execution failed:\n" + str(
                err)
            Data.fails.append(err_msg)
            return err_msg
        return True
コード例 #7
0
    def watch_auction_claim(self):
        print_logs(self.distributor, 'ClaimTokensCalled', 'Distributor')
        print_logs(self.distributor, 'Distributed', 'Distributor')
        print_logs(self.auction, 'ClaimedTokens', 'DutchAuction')
        # watch_logs(self.auction, 'ClaimedTokens', self.add_verified)

        self.filter_claims = self.handle_auction_logs('ClaimedTokens',
                                                      self.add_verified)
コード例 #8
0
ファイル: stages.py プロジェクト: artur0us/raindeploy
    def ssh_shell_cmd(stage_name: str, stage_details: dict,
                      env_credentials: dict) -> Union[str, bool]:
        try:
            ssh_credentials = Helpers.get_env_credentials(
                env_credentials, "ssh", stage_details["ssh_config"])
            if not ssh_credentials:
                err_msg = "ssh credentials reading error"
                Data.fails.append(err_msg)
                return err_msg

            ssh_client = paramiko.SSHClient()
            ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh_client.connect(hostname=ssh_credentials["host"],
                               port=ssh_credentials["port"],
                               username=ssh_credentials["username"],
                               password=ssh_credentials["password"])
            try:
                cmd_stdin, cmd_stdout, cmd_stderr = ssh_client.exec_command(
                    stage_details["cmd"], get_pty=True)
                # exit_status = cmd_stdout.channel.recv_exit_status()
                # if exit_status < 0:
                #   pass # TODO: return error message or not?
                data = cmd_stdout.read() + cmd_stderr.read()
                Data.logs.append(data)
                if Data.WORK_MODE == DEBUG_MODE:
                    print_logs(data)
                ssh_client.close()
            except Exception as err:
                err_msg = "(ssh_shell_cmd) command execution failed:\n" + str(
                    err)
                Data.fails.append(err_msg)
                return err_msg
        except Exception as err:
            err_msg = "(ssh_shell_cmd) SSH connection failed:\n" + str(err)
            Data.fails.append(err_msg)
            return err_msg
        return True
コード例 #9
0
ファイル: stages.py プロジェクト: artur0us/raindeploy
    def build_golang_project(stage_name: str, stage_details: dict,
                             env_credentials: dict) -> Union[str, bool]:
        # Old built file removal
        try:
            os.remove(stage_details["paths"]["target_build_file"])
        except:
            pass

        # Compilation
        try:
            # Compile command preparation
            compile_command = ""
            for one_var in stage_details["build"]["variables"]:
                compile_command = compile_command + one_var + " "
            compile_command = (compile_command + "go build -o " +
                               stage_details["paths"]["target_build_file"] +
                               " " + stage_details["paths"]["main_src_file"])
            if Data.WORK_MODE == DEBUG_MODE:
                print(compile_command)

            # Changing working directory to go sources path
            os.chdir(stage_details["paths"]["main_src"])

            # Compilation
            proc = subprocess.Popen(compile_command,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    shell=True)
            proc_out, proc_err = proc.communicate()
            Data.logs.append(proc_out)
            Data.logs.append(proc_err)
            if Data.WORK_MODE == DEBUG_MODE:
                print_logs(proc_out, proc_err)
            if (("error" in str(proc_out).lower())
                    or ("error" in str(proc_err).lower())
                    or ("undefined:" in str(proc_out).lower())
                    or ("undefined:" in str(proc_err).lower())
                    or ("cannot use" in str(proc_out).lower())
                    or ("cannot use" in str(proc_err).lower())
                    or ("not enough arguments" in str(proc_out).lower())
                    or ("not enough arguments" in str(proc_err).lower())
                    or ("is not in goroot" in str(proc_out).lower())
                    or ("is not in goroot" in str(proc_err).lower())
                    or ("invalid operation" in str(proc_out).lower())
                    or ("invalid operation" in str(proc_err).lower())
                    or ("does not support indexing" in str(proc_out).lower())
                    or ("does not support indexing" in str(proc_err).lower())
                    or ("invalid operation" in str(proc_out).lower())
                    or ("invalid operation" in str(proc_err).lower())
                    or ("query redeclared in" in str(proc_out).lower())
                    or ("query redeclared in" in str(proc_err).lower())
                    or ("want" in str(proc_out).lower())
                    or ("want" in str(proc_err).lower())
                    or ("has no field or" in str(proc_out).lower())
                    or ("has no field or" in str(proc_err).lower())
                    or ("declared but not used" in str(proc_out).lower())
                    or ("declared but not used" in str(proc_err).lower())
                    or ("entry for module providing" in str(proc_out).lower())
                    or ("entry for module providing" in str(proc_err).lower())
                    or ("missing go.sum entry" in str(proc_out).lower())
                    or ("missing go.sum entry" in str(proc_err).lower())
                    or ("assignment mismatch:" in str(proc_out).lower())
                    or ("assignment mismatch:" in str(proc_err).lower())):
                err_msg = "(build_golang_project) golang project source code compilation failed:\n" + str(
                    proc_out) + "\n" + str(proc_err)
                Data.fails.append(err_msg)
                return err_msg

            # chmod +x built_go_executable_file
            if stage_details["build"]["chmod_x_built_file"]:
                proc = None
                proc_out = None
                proc_err = None
                chmod_command = "chmod +x " + stage_details["paths"][
                    "target_build_file"]
                proc = subprocess.Popen(chmod_command,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        shell=True)
                proc_out, proc_err = proc.communicate()
                Data.logs.append(proc_out)
                Data.logs.append(proc_err)
                if Data.WORK_MODE == DEBUG_MODE:
                    print_logs(proc_out, proc_err)

            # Restore default working directory
            os.chdir(Data.default_cwd)
        except Exception as err:
            err_msg = "(build_golang_project) compiler command execution failed:\n" + str(
                err)
            Data.fails.append(err_msg)
            return err_msg
        return True
コード例 #10
0
ファイル: fixtures.py プロジェクト: ottodevs/ether-academy
    def get(arguments,
            transaction=None,
            token_type='RaidenToken',
            decimals=18):
        if not decimals == 18:
            token_type = 'RaidenToken2'
            arguments.insert(0, decimals)

        RaidenToken = chain.provider.get_contract_factory(token_type)
        token_contract = create_contract(RaidenToken, arguments, transaction,
                                         ['Deployed'])

        if print_the_logs:
            print_logs(token_contract, 'Transfer', token_type)
            print_logs(token_contract, 'Transfer2', token_type)
            print_logs(token_contract, 'Transfer3', token_type)
            print_logs(token_contract, 'Approval', token_type)
            print_logs(token_contract, 'Deployed', token_type)
            print_logs(token_contract, 'Burnt', token_type)

        return token_contract
コード例 #11
0
ファイル: fixtures.py プロジェクト: ottodevs/ether-academy
def auction_contract_fast_decline(request, contract_params, chain, web3,
                                  wallet_address, create_contract):
    auction_contract_type = request.param
    Auction = chain.provider.get_contract_factory(auction_contract_type)
    params = [wallet_address] + contract_params['args']
    auction_contract = create_contract(Auction, params, {}, ['Deployed'])

    if print_the_logs:
        print_logs(auction_contract, 'Deployed', auction_contract_type)
        print_logs(auction_contract, 'Setup', auction_contract_type)
        print_logs(auction_contract, 'AuctionStarted', auction_contract_type)
        print_logs(auction_contract, 'BidSubmission', auction_contract_type)
        print_logs(auction_contract, 'AuctionEnded', auction_contract_type)
        print_logs(auction_contract, 'ClaimedTokens', auction_contract_type)
        print_logs(auction_contract, 'TokensDistributed',
                   auction_contract_type)

    return auction_contract