def clean_up(): """ Removes the temporary directory. """ if TMPDIR: try: shutil.rmtree(TMPDIR) except OSError, ex: if ex.errno != errno.ENOENT: error_msg(_("Can't remove '{0}': {1}").format(TMPDIR, ex))
def clean_up(tmp_dir, silent=False): """ Removes the temporary directory. """ if tmp_dir: try: shutil.rmtree(tmp_dir) except OSError as ex: if ex.errno != errno.ENOENT and silent == False: error_msg(_("Can't remove '{0}': {1}").format(tmp_dir, str(ex)))
def clean_up(tmp_dir): """ Removes the temporary directory. """ if tmp_dir: try: shutil.rmtree(tmp_dir) except OSError as ex: if ex.errno != errno.ENOENT: error_msg(_("Can't remove '{0}': {1}").format(tmp_dir, str(ex)))
def download(self, files, download_exact_files=False): """ Downloads rpms shipping given files into a temporary directory Arguments: file - a list of files to download download_exact_files - extract only specified files Returns: RETURN_OK if all goes well. RETURN_FAILURE in case it cannot set up either of the directories. """ # nothing to download? if not files: return RETURN_FAILURE # set up tmp and cache dirs so that we can check free space in both retval = self.setup_tmp_dirs() if retval != RETURN_OK: return retval if not self.find_packages_run: self.find_packages(files) if verbose != 0 or len(self.not_found) != 0: print( _("Can't find packages for {0} debuginfo files").format( len(self.not_found))) if verbose != 0 or len(self.package_files_dict) != 0: print( _("Packages to download: {0}").format( len(self.package_files_dict))) question = _( "Downloading {0:.2f}Mb, installed size: {1:.2f}Mb. Continue?") \ .format(self.todownload_size / (1024 * 1024), self.installed_size / (1024 * 1024)) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER # check if there is enough free space in both tmp and cache res = os.statvfs(self.tmpdir) tmp_space = float(res.f_bsize * res.f_bavail) / (1024 * 1024) if (self.todownload_size / (1024 * 1024)) > tmp_space: question = _("Warning: Not enough free space in tmp dir '{0}'" " ({1:.2f}Mb left). Continue?").format( self.tmpdir, tmp_space) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER res = os.statvfs(self.cachedir) cache_space = float(res.f_bsize * res.f_bavail) / (1024 * 1024) if (self.installed_size / (1024 * 1024)) > cache_space: question = _("Warning: Not enough free space in cache dir " "'{0}' ({1:.2f}Mb left). Continue?").format( self.cachedir, cache_space) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER progress_observer = DownloadProgress(len(self.package_files_dict)) self.initialize_progress(progress_observer) for pkg, files in self.package_files_dict.items(): # Download package_full_path, err = self.download_package(pkg) if err: # I observed a zero-length file left on error, # which prevents cleanup later. Fix it: try: if package_full_path is not None: os.unlink(package_full_path) except OSError: pass print(_("Downloading package {0} failed").format(pkg)) else: unpack_result = unpack_rpm(package_full_path, files, self.tmpdir, self.cachedir, exact_files=download_exact_files) if unpack_result == RETURN_FAILURE: # recursively delete the temp dir on failure print(_("Unpacking failed, aborting download...")) s = os.stat(self.cachedir) abrt = pwd.getpwnam("abrt") if (s.st_uid != abrt.pw_uid) or (s.st_gid != abrt.pw_gid): print( _("'{0}' must be owned by abrt. " "Please run '# chown -R abrt.abrt {0}' " "to fix the issue.").format(self.cachedir)) clean_up(self.tmpdir) return RETURN_FAILURE if not self.keeprpms: log1("keeprpms = False, removing %s", package_full_path) os.unlink(package_full_path) progress_observer.downloaded_pkgs += 1 if not self.keeprpms and os.path.exists(self.tmpdir): # Was: "All downloaded packages have been extracted, removing..." # but it was appearing even if no packages were in fact extracted # (say, when there was one package, and it has download error). print(_("Removing {0}").format(self.tmpdir)) try: os.rmdir(self.tmpdir) except OSError: error_msg( _("Can't remove {0}, probably contains an error log"). format(self.tmpdir)) return RETURN_OK
# recursively delete the temp dir on failure print _("Unpacking failed, aborting download...") clean_up() return RETURN_FAILURE downloaded_pkgs += 1 if not self.keeprpms and os.path.exists(self.tmpdir): # Was: "All downloaded packages have been extracted, removing..." # but it was appearing even if no packages were in fact extracted # (say, when there was one package, and it has download error). print (_("Removing {0}").format(self.tmpdir)) try: os.rmdir(self.tmpdir) except OSError: error_msg(_("Can't remove %s, probably contains an error log").format(self.tmpdir)) return RETURN_OK def build_ids_to_path(pfx, build_ids): """ Transforms build ids into a path. build_id1=${build_id:0:2} build_id2=${build_id:2} file="usr/lib/debug/.build-id/$build_id1/$build_id2.debug" """ return ["%s/usr/lib/debug/.build-id/%s/%s.debug" % (pfx, b_id[:2], b_id[2:]) for b_id in build_ids] # beware this finds only missing libraries, but not the executable itself ..
def download(self, files, download_exact_files=False): """ Downloads rpms shipping given files into a temporary directory Arguments: file - a list of files to download download_exact_files - extract only specified files Returns: RETURN_OK if all goes well. RETURN_FAILURE in case it cannot set up either of the directories. """ # nothing to download? if not files: return RETURN_FAILURE # set up tmp and cache dirs so that we can check free space in both retval = self.setup_tmp_dirs() if retval != RETURN_OK: return retval print(_("Initializing package manager")) self.prepare() #if verbose == 0: # # this suppress yum messages about setting up repositories # mute_stdout() # This takes some time, let user know what we are doing print(_("Setting up repositories")) self.initialize_repositories() #if verbose == 0: # # re-enable the output to stdout # unmute_stdout() print(_("Looking for needed packages in repositories")) package_files_dict, not_found, todownload_size, installed_size = self.triage(files) if verbose != 0 or len(not_found) != 0: print(_("Can't find packages for {0} debuginfo files").format(len(not_found))) if verbose != 0 or len(package_files_dict) != 0: print(_("Packages to download: {0}").format(len(package_files_dict))) question = _( "Downloading {0:.2f}Mb, installed size: {1:.2f}Mb. Continue?") \ .format(todownload_size / (1024 * 1024), installed_size / (1024 * 1024)) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER # check if there is enough free space in both tmp and cache res = os.statvfs(self.tmpdir) tmp_space = float(res.f_bsize * res.f_bavail) / (1024 * 1024) if (todownload_size / (1024 * 1024)) > tmp_space: question = _("Warning: Not enough free space in tmp dir '{0}'" " ({1:.2f}Mb left). Continue?").format( self.tmpdir, tmp_space) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER res = os.statvfs(self.cachedir) cache_space = float(res.f_bsize * res.f_bavail) / (1024 * 1024) if (installed_size / (1024 * 1024)) > cache_space: question = _("Warning: Not enough free space in cache dir " "'{0}' ({1:.2f}Mb left). Continue?").format( self.cachedir, cache_space) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER progress_observer = DownloadProgress(len(package_files_dict)) self.initialize_progress(progress_observer) for pkg, files in package_files_dict.items(): # Download package_full_path, err = self.download_package(pkg) if err: # I observed a zero-length file left on error, # which prevents cleanup later. Fix it: try: os.unlink(package_full_path) except OSError: pass print(_("Downloading package {0} failed").format(pkg)) else: unpack_result = unpack_rpm(package_full_path, files, self.tmpdir, self.cachedir, exact_files=download_exact_files) if unpack_result == RETURN_FAILURE: # recursively delete the temp dir on failure print(_("Unpacking failed, aborting download...")) s = os.stat(self.cachedir) abrt = pwd.getpwnam("abrt") if (s.st_uid != abrt.pw_uid) or (s.st_gid != abrt.pw_gid): print(_("'{0}' must be owned by abrt. " "Please run '# chown -R abrt.abrt {0}' " "to fix the issue.").format(self.cachedir)) clean_up(self.tmpdir) return RETURN_FAILURE if not self.keeprpms: log1("keeprpms = False, removing %s", package_full_path) os.unlink(package_full_path) progress_observer.downloaded_pkgs += 1 if not self.keeprpms and os.path.exists(self.tmpdir): # Was: "All downloaded packages have been extracted, removing..." # but it was appearing even if no packages were in fact extracted # (say, when there was one package, and it has download error). print(_("Removing {0}").format(self.tmpdir)) try: os.rmdir(self.tmpdir) except OSError: error_msg(_("Can't remove {0}, probably contains an error log").format(self.tmpdir)) return RETURN_OK
def download(self, files, download_exact_files=False): """ Downloads rpms shipping given files into a temporary directory Arguments: file - a list of files to download download_exact_files - extract only specified files Returns: RETURN_OK if all goes well. RETURN_FAILURE in case it cannot set up either of the directories. """ # nothing to download? if not files: return RETURN_FAILURE # set up tmp and cache dirs so that we can check free space in both retval = self.setup_tmp_dirs() if retval != RETURN_OK: return retval print(_("Initializing package manager")) self.prepare() #if verbose == 0: # # this suppress yum messages about setting up repositories # mute_stdout() # This takes some time, let user know what we are doing print(_("Setting up repositories")) self.initialize_repositories() #if verbose == 0: # # re-enable the output to stdout # unmute_stdout() print(_("Looking for needed packages in repositories")) package_files_dict, not_found, todownload_size, installed_size = self.triage(files) if verbose != 0 or len(not_found) != 0: print(_("Can't find packages for {0} debuginfo files").format(len(not_found))) if verbose != 0 or len(package_files_dict) != 0: print(_("Packages to download: {0}").format(len(package_files_dict))) question = _("Downloading {0:.2f}Mb, installed size: {1:.2f}Mb. Continue?").format( todownload_size / (1024*1024), installed_size / (1024*1024) ) if self.noninteractive == False and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER # check if there is enough free space in both tmp and cache res = os.statvfs(self.tmpdir) tmp_space = float(res.f_bsize * res.f_bavail) / (1024*1024) if (todownload_size / (1024*1024)) > tmp_space: question = _("Warning: Not enough free space in tmp dir '{0}'" " ({1:.2f}Mb left). Continue?").format( self.tmpdir, tmp_space) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER res = os.statvfs(self.cachedir) cache_space = float(res.f_bsize * res.f_bavail) / (1024*1024) if (installed_size / (1024*1024)) > cache_space: question = _("Warning: Not enough free space in cache dir " "'{0}' ({1:.2f}Mb left). Continue?").format( self.cachedir, cache_space) if not self.noninteractive and not ask_yes_no(question): print(_("Download cancelled by user")) return RETURN_CANCEL_BY_USER progress_observer = DownloadProgress(len(package_files_dict)) self.initialize_progress(progress_observer) for pkg, files in package_files_dict.items(): # Download package_full_path, err = self.download_package(pkg) if err: # I observed a zero-length file left on error, # which prevents cleanup later. Fix it: try: os.unlink(package_full_path) except OSError: pass print(_("Downloading package {0} failed").format(pkg)) else: unpack_result = unpack_rpm(package_full_path, files, self.tmpdir, self.cachedir, exact_files=download_exact_files) if unpack_result == RETURN_FAILURE: # recursively delete the temp dir on failure print(_("Unpacking failed, aborting download...")) clean_up(self.tmpdir) return RETURN_FAILURE if not self.keeprpms: log1("keeprpms = False, removing %s", package_full_path) os.unlink(package_full_path) progress_observer.downloaded_pkgs += 1 if not self.keeprpms and os.path.exists(self.tmpdir): # Was: "All downloaded packages have been extracted, removing..." # but it was appearing even if no packages were in fact extracted # (say, when there was one package, and it has download error). print(_("Removing {0}").format(self.tmpdir)) try: os.rmdir(self.tmpdir) except OSError: error_msg(_("Can't remove {0}, probably contains an error log").format(self.tmpdir)) return RETURN_OK