def write_file_out(filename, content): if not file_system.is_zip_alike_url(filename): dest_folder = os.path.dirname(filename) if dest_folder: file_system.mkdir_p(dest_folder) file_system.write_bytes(filename, content)
def git_clone(requires): from git import Repo if sys.platform != "win32": # Unfortunately for windows user, the following function # needs shell=True, which expose security risk. I would # rather not to trade it with its marginal benefit make_sure_git_is_available() moban_home = get_moban_home() file_system.mkdir_p(moban_home) for require in requires: repo_name = get_repo_name(require.git_url) local_repo_folder = file_system.path_join(moban_home, repo_name) if file_system.exists(local_repo_folder): reporter.report_git_pull(repo_name) repo = Repo(local_repo_folder) repo.git.pull() if require.reference: repo.git.checkout(require.reference) elif require.branch: repo.git.checkout(require.branch) if require.submodule: reporter.report_info_message("updating submodule") repo.git.submodule("update") else: reporter.report_git_clone(require.git_url) repo = Repo.clone_from(require.git_url, local_repo_folder, **require.clone_params()) if require.submodule: reporter.report_info_message("checking out submodule") repo.git.submodule("update", "--init")
def test_mkdir_p(): test_path = "a/b/c/d" file_system.mkdir_p(test_path) assert os.path.exists(test_path) rmtree(test_path)