Example #1
0
    def __initialize_project(project: str, score_class: str, contents_func):
        """Initialize the tbears project

        :param project: name of tbears project.
        :param score_class: class name of SCORE.
        :param contents_func contents generator
        """
        # make package.json data
        package_json_dict = get_package_json_dict(project, score_class)
        package_json_contents = json.dumps(package_json_dict, indent=4)

        # when command is init, make score templete.
        # when command is samples, make standard_crowd_sale or standard_token
        py_contents = contents_func(score_class)

        # contentes for tbears_server_config.json

        server_config_json = make_server_config(tbears_server_config)

        write_file(project, f"{project}.py", py_contents)
        write_file(project, "package.json", package_json_contents)
        write_file(project, '__init__.py', '')
        write_file(f'{project}/tests', f'test_{project}.py', '')
        write_file(f'{project}/tests', f'__init__.py', '')
        write_file('./', f"{FN_SERVER_CONF}",
                   json.dumps(server_config_json, indent=4))
        write_file('./', f"{FN_CLI_CONF}",
                   json.dumps(tbears_cli_config, indent=4))
Example #2
0
    def __gen_conf_file() -> list:
        result = []

        if os.path.exists(FN_CLI_CONF) is False:
            result.append(FN_CLI_CONF[2:])
            write_file('./', FN_CLI_CONF, json.dumps(tbears_cli_config, indent=4))

        if os.path.exists(FN_SERVER_CONF) is False:
            result.append(FN_SERVER_CONF[2:])
            server_config_json = make_server_config(tbears_server_config)
            write_file('./', FN_SERVER_CONF, json.dumps(server_config_json, indent=4))

        # mkdir keystore
        keystore_dir = "./keystore"
        if os.path.exists(keystore_dir) is False:
            os.mkdir(keystore_dir)

        # gen keystore files
        write_file(keystore_dir, FN_KEYSTORE_TEST1, json.dumps(keystore_test1, indent=4))

        # keystore file for main P-Rep
        main_prep_count = tbears_server_config.get(TConfigKey.PREP_MAIN_PREPS, 0)
        for i, prep in enumerate(TEST_ACCOUNTS[:main_prep_count]):
            wallet = KeyWallet.load(prep)
            wallet.store(file_path=os.path.join(keystore_dir, f"prep{i}_keystore"),
                         password=f"prep{i}_Account")

        result.append(keystore_dir + "/*")

        return result
Example #3
0
    def genconf(self, _conf: dict):
        """Generate tbears config files. (tbears_server_config.json, tbears_cli_config.json)"""
        result = []

        if os.path.exists(FN_CLI_CONF) is False:
            result.append(FN_CLI_CONF[2:])
            write_file('./', FN_CLI_CONF,
                       json.dumps(tbears_cli_config, indent=4))
        if os.path.exists(FN_SERVER_CONF) is False:
            result.append(FN_SERVER_CONF[2:])
            server_config_json = make_server_config(tbears_server_config)
            write_file('./', FN_SERVER_CONF,
                       json.dumps(server_config_json, indent=4))

        if result:
            print(f"Made {', '.join(result)} successfully")
        else:
            print(f"There were configuration files already.")
Example #4
0
    def __gen_conf_file() -> list:
        result = []

        if os.path.exists(FN_CLI_CONF) is False:
            result.append(FN_CLI_CONF[2:])
            write_file('./', FN_CLI_CONF,
                       json.dumps(tbears_cli_config, indent=4))

        if os.path.exists(FN_SERVER_CONF) is False:
            result.append(FN_SERVER_CONF[2:])
            server_config_json = make_server_config(tbears_server_config)
            write_file('./', FN_SERVER_CONF,
                       json.dumps(server_config_json, indent=4))

        if os.path.exists(FN_KEYSTORE_TEST1) is False:
            result.append(FN_KEYSTORE_TEST1[2:])
            write_file('./', FN_KEYSTORE_TEST1,
                       json.dumps(keystore_test1, indent=4))

        return result