def clone_git_repository(name: str, url: str, target_directory_name: str): """ Clones git repository by url and checks is it cloned correct :param name: name of project which will be cloned :param url: url of .git repository :param target_directory_name: a directory name for cloning :raises C3PMProject.BadValue: if cloning failed """ CLIMessage.info_message("cloning " + name + " (" + url + ") to " + target_directory_name) os.system("git clone " + url + " " + target_directory_name) clone_dir_ls = subprocess.check_output(["ls"]).split() if len(clone_dir_ls) == 0: raise C3PMProject.BadValue( "url", "cloning " + name + " (" + url + ") to " + target_directory_name + " failed: nothing cloned.") if len(clone_dir_ls) != 1: raise C3PMProject.BadValue( "url", "cloning " + name + " (" + url + ") to " + target_directory_name + " failed: to many directories in " "clone directory.") CLIMessage.success_message(name + " cloned")
def list_all_dependencies(self) -> OrderedDict: """ Loads all project's dependencies recursively to list all their own dependencies. In the result, a list of all projects which have to be loaded is listed. :raises C3PMProject.BadC3PMProject: :return: list of all dependencies """ # TODO clean clone dir def full_dependency_branch(dependency_name: str) -> str: """ Returns one of branches to dependency :param dependency_name: :return: full branch-path to dependency """ result = dependency_name next_dependency_name = dependency_name while next_dependency_name != C3PMProject.ROOT_NAME_FOR_DEPENDENCIES_LIST: next_dependency_name = dependency_parent_list[ next_dependency_name] result = next_dependency_name + "->" + result return result CLIMessage.info_message("Listing all dependencies for project " + self.name) # OrderedDict of all dependencies, will be returned all_dependencies = OrderedDict(self.__c3pm_dict["dependencies"]) # OrderedDict of dependencies, which are not yet checked unchecked_dependencies = OrderedDict(self.__c3pm_dict["dependencies"]) # dict of dependencies parent name (dependency_name: str -> parent_dependency_name: str) dependency_parent_list = dict() os.mkdir(C3PMProject.CLONE_DIR) os.chdir(C3PMProject.CLONE_DIR) for cloned_project_dependency_name in all_dependencies: dependency_parent_list[cloned_project_dependency_name] = \ C3PMProject.ROOT_NAME_FOR_DEPENDENCIES_LIST while len(unchecked_dependencies): unchecked_dependency = unchecked_dependencies.popitem(last=False) unchecked_dependency_name = unchecked_dependency[0] try: C3PMProject.clone_git_repository( full_dependency_branch(unchecked_dependency_name), unchecked_dependency[1]["url"], unchecked_dependency_name) except C3PMProject.BadValue as err: raise C3PMProject.BadC3PMProject(str(err)) else: os.chdir(unchecked_dependency_name) try: c3pm_cloned_project = C3PMProject() cloned_project_dependencies_dict = \ c3pm_cloned_project.__c3pm_dict["dependencies"] for cloned_project_dependency_name in cloned_project_dependencies_dict: if cloned_project_dependency_name in all_dependencies: if cloned_project_dependencies_dict[cloned_project_dependency_name] != \ all_dependencies[cloned_project_dependency_name]: raise C3PMProject.BadC3PMProject( "duplicated dependencies names:\n" # dependency 1 name = + full_dependency_branch( cloned_project_dependency_name) + ":\n" # dependency 1 info = + json.dumps(all_dependencies[ cloned_project_dependency_name], indent=4) + "\n" # dependency 2 name = + full_dependency_branch( c3pm_cloned_project.name) + "->" + cloned_project_dependency_name # dependency 2 info = + cloned_project_dependencies_dict[ cloned_project_dependency_name]) else: all_dependencies[ cloned_project_dependency_name] = OrderedDict( cloned_project_dependencies_dict[ cloned_project_dependency_name]) unchecked_dependencies[ cloned_project_dependency_name] = OrderedDict( cloned_project_dependencies_dict[ cloned_project_dependency_name]) dependency_parent_list[cloned_project_dependency_name] = \ c3pm_cloned_project.name except C3PMProject.BadC3PMProject as err: raise C3PMProject.BadC3PMProject( "in cloned project " + full_dependency_branch(unchecked_dependency_name) + ":bad project directory: " + err.problem) except Exception: raise C3PMProject.BadC3PMProject( "in cloned project " + full_dependency_branch(unchecked_dependency_name) + ":unknown error happen, please report that") os.chdir("..") shutil.rmtree(unchecked_dependency_name) os.chdir("..") shutil.rmtree(C3PMProject.CLONE_DIR) return all_dependencies