Example #1
0
 def write_server_conf(conf: dict):
     write_conf = {
         "hostAddress": conf['hostAddress'],
         "port": conf['port'],
         "scoreRootPath": conf['scoreRootPath'],
         "stateDbRootPath": conf['stateDbRootPath'],
         TConfigKey.CHANNEL: conf.get(TConfigKey.CHANNEL,
                                      None),  # to stop iconservice
         TConfigKey.AMQP_TARGET: conf.get(TConfigKey.AMQP_TARGET,
                                          None),  # to stop iconservice
         TConfigKey.AMQP_KEY: conf.get(TConfigKey.AMQP_KEY,
                                       None)  # to stop iconservice
     }
     Logger.debug(f"Write server Info.({conf}) to {TBEARS_CLI_ENV}",
                  TBEARS_CLI_TAG)
     file_path = TBEARS_CLI_ENV
     file_name = file_path[file_path.rfind('/') + 1:]
     parent_directory = file_path[:file_path.rfind('/')]
     try:
         write_file(parent_directory=parent_directory,
                    file_name=file_name,
                    contents=json.dumps(write_conf),
                    overwrite=True)
     except Exception as e:
         print(f"Can't write conf to file. {e}")
     except TBearsWriteFileException as e:
         print(f"{e}")
Example #2
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 #3
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 template.
        # when command is samples, make standard_crowd_sale or standard_token
        py_contents, test_contents = contents_func(score_class)

        write_file(project, f"{project}.py", py_contents)
        write_file(project, "package.json", package_json_contents)
        write_file(project, '__init__.py', '')
        if len(test_contents):
            write_file(f'{project}/tests', f'test_{project}.py', test_contents)
            write_file(f'{project}/tests', f'__init__.py', '')
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))

        # 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 #5
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
Example #6
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))