def download_or_get_repo(self): git_url = self.app_info["githubUrl"] version = self.app_info.get("version", "master") already_downloaded = False path_cache = None if version != "master": path_cache = os.path.join( constants.APPS_STORAGE_DIR(), *Path(git_url.replace(".git", "")).parts[1:], version) already_downloaded = sly.fs.dir_exists(path_cache) if already_downloaded is False: self.logger.info("Git repo will be downloaded") api = Api(self.info['server_address'], self.info['api_token']) tar_path = os.path.join(self.dir_task_src, 'repo.tar.gz') api.app.download_git_archive(self.app_info["moduleId"], self.app_info["id"], version, tar_path, log_progress=True, ext_logger=self.logger) with tarfile.open(tar_path) as archive: archive.extractall(self.dir_task_src) subdirs = get_subdirs(self.dir_task_src) if len(subdirs) != 1: raise RuntimeError( "Repo is downloaded and extracted, but resulting directory not found" ) extracted_path = os.path.join(self.dir_task_src, subdirs[0]) for filename in os.listdir(extracted_path): shutil.move(os.path.join(extracted_path, filename), os.path.join(self.dir_task_src, filename)) remove_dir(extracted_path) silent_remove(tar_path) #git.download(git_url, self.dir_task_src, github_token, version) if path_cache is not None: shutil.copytree(self.dir_task_src, path_cache) else: self.logger.info("Git repo already exists") shutil.copytree(path_cache, self.dir_task_src)
def download(github_url, dest_dir, github_token=None, version="master", log_progress=True): tar_path = os.path.join(dest_dir, 'repo.tar.gz') download_tar(github_url, tar_path, github_token, version, log_progress) with tarfile.open(tar_path) as archive: archive.extractall(dest_dir) subdirs = get_subdirs(dest_dir) if len(subdirs) != 1: raise RuntimeError( "Repo is downloaded and extracted, but resulting directory not found" ) extracted_path = os.path.join(dest_dir, subdirs[0]) for filename in os.listdir(extracted_path): shutil.move(os.path.join(extracted_path, filename), os.path.join(dest_dir, filename)) remove_dir(extracted_path) silent_remove(tar_path)
def _copy_dir_recursively(cls, src_path, dst_path): if sly_fs.dir_exists(dst_path): sly_fs.remove_dir(dst_path) shutil.copytree(src_path, dst_path)
def _rm_obj_impl(self, st_path): sly_fs.remove_dir(st_path)