def _format_yaml_symlink(yaml_file): """Return formatted string for yaml file :param str yaml_file: Yaml file path """ path = fmt.symlink_target(yaml_file) path = fmt.remove_prefix(path, ROOT_DIR) path = fmt.remove_prefix(path, '/') return '\n' + fmt.get_path('clowder.yaml') + ' -> ' + fmt.get_path( path) + '\n'
def _init_repo(self): """Initialize repository :raise OSError: """ if existing_git_repository(self.repo_path): return try: self._print(' - Initialize repo at ' + fmt.get_path(self.repo_path)) if not os.path.isdir(self.repo_path): try: os.makedirs(self.repo_path) except OSError as err: if err.errno != os.errno.EEXIST: raise self.repo = Repo.init(self.repo_path) except GitError as err: remove_directory(self.repo_path) message = colored(' - Failed to initialize repository', 'red') self._print(message) self._print(fmt.error(err)) self._exit(message) except (KeyboardInterrupt, SystemExit): remove_directory(self.repo_path) self._exit()
def _format_yaml_file(yaml_file): """Return formatted string for yaml file :param str yaml_file: Yaml file path """ path = fmt.remove_prefix(yaml_file, ROOT_DIR) path = fmt.remove_prefix(path, '/') return '\n' + fmt.get_path(path) + '\n'
def link_clowder_yaml(version=None): """Create symlink pointing to clowder.yaml file :param Optional[str] version: Version name of clowder.yaml to link :raise ClowderExit: """ if version is None: yaml_file = os.path.join(ROOT_DIR, '.clowder', 'clowder.yaml') path_output = fmt.get_path('.clowder/clowder.yaml') else: relative_path = os.path.join('.clowder', 'versions', version, 'clowder.yaml') path_output = fmt.get_path(relative_path) yaml_file = os.path.join(ROOT_DIR, relative_path) if not os.path.isfile(yaml_file): print('\n' + path_output + " doesn't seem to exist\n") raise ClowderExit(1) yaml_symlink = os.path.join(ROOT_DIR, 'clowder.yaml') print(' - Symlink ' + path_output) force_symlink(yaml_file, yaml_symlink)
def _repo(self): """Create Repo instance for self.repo_path :return: GitPython Repo instance :rtype: Repo """ try: repo = Repo(self.repo_path) except GitError as err: repo_path_output = fmt.get_path(self.repo_path) message = colored(" - Failed to create Repo instance for ", 'red') + repo_path_output self._print(message) self._print(fmt.error(err)) self._exit(message) except (KeyboardInterrupt, SystemExit): self._exit() else: return repo