def get_users() -> Dict[str, Account]: result = OrderedDict() for pem_file in sorted(utils.list_files(_get_users_folder(), ".pem")): nickname = Path(pem_file).stem account = Account(pem_file=pem_file) result[nickname] = account return result
def _patch_mandos_tests(self): test_dir_path = path.join(self.directory, "mandos") if not path.isdir(test_dir_path): return test_paths = [ e for e in utils.list_files(test_dir_path, suffix=".json") ] self._replace_in_files( test_paths, [(f"{self.template_name}.wasm", f"{self.project_name}.wasm")])
def _replace_placeholders(self): rust_module = dependencies.get_module_by_key("rust") self.rust_directory = rust_module.get_directory() self.rust_bin_directory = path.join(self.rust_directory, "bin") cargo_path = path.join(self.directory, "Cargo.toml") cargo_debug_path = path.join(self.directory, "debug", "Cargo.toml") launch_path = path.join(self.directory, ".vscode", "launch.json") tasks_path = path.join(self.directory, ".vscode", "tasks.json") debug_main_path = path.join(self.directory, "debug", "src", "main.rs") test_paths = utils.list_files(path.join(self.directory, "test")) logger.info("Updating cargo files...") cargo_file = CargoFile(cargo_path) cargo_file.package_name = self.project_name cargo_file.bin_name = self.project_name cargo_file.version = "0.0.1" cargo_file.authors = ["you"] cargo_file.edition = "2018" cargo_file.save() cargo_file_debug = CargoFile(cargo_debug_path) cargo_file_debug.package_name = f"{self.project_name}-debug" cargo_file_debug.version = "0.0.1" cargo_file_debug.authors = ["you"] cargo_file_debug.edition = "2018" cargo_file_debug.save() logger.info("Applying replacements...") self._replace_in_files([launch_path, tasks_path], [("{{PROJECT_NAME}}", self.project_name), ("{{PATH_RUST_BIN}}", self.rust_bin_directory), ("{{RUSTUP_HOME}}", self.rust_directory), ("{{CARGO_HOME}}", self.rust_directory)]) self._replace_in_files( [debug_main_path], [ # Example "use simple_coin::*" to "use my_project::*" (f"use {self.template_name.replace('-', '_')}::*", f"use {self.project_name.replace('-', '_')}::*") ]) self._replace_in_files([cargo_debug_path], [(f"[dependencies.{self.template_name}]", f"[dependencies.{self.project_name}]")]) self._replace_in_files(test_paths, [(f"adder.wasm", f"myadder.wasm")])
def _patch_source_code_tests(self): test_dir_path = path.join(self.directory, "tests") if not path.isdir(test_dir_path): return test_paths = utils.list_files(test_dir_path) self._replace_in_files( test_paths, [ # Example: replace "use simple-erc20::*" to "use my_token::*" (f"use {self.template_name.replace('-', '_')}::*", f"use {self.project_name.replace('-', '_')}::*"), # Example: replace "extern crate adder;" to "extern crate myadder" (f"extern crate {self.template_name.replace('-', '_')};", f"extern create {self.project_name.replace('-', '_')};") ] )
def _patch_mandos_tests(self): test_dir_path = path.join(self.directory, "mandos") if not path.isdir(test_dir_path): return test_paths = [e for e in utils.list_files(test_dir_path, suffix=".json")] self._replace_in_files( test_paths, [ (f"{self.template_name}.wasm", f"{self.project_name}.wasm") ] ) for file in test_paths: data = utils.read_json_file(file) # Patch fields data["name"] = data.get("name", "").replace(self.template_name, self.project_name) utils.write_json_file(file, data)