def _push_pkg(upf): log.info("\nPushing update {t.bold}{upf}{t.normal}".format( t=log.term, upf=upf)) update = self._load_update_file(upf) pushed_rpms = [] try: _updated_repos = set() _updated_repo_bases = set() _pushed_build_tmp_paths = [] for build in update.builds: src_path = self._build_tmp_path(upf, build) if src_path in _pushed_build_tmp_paths: continue build_rpms = helpers.find_files(src_path, ext='.rpm') dest_repo_base_path = self._dest_repo_base_path(build.repo) if not os.path.isdir(dest_repo_base_path): raise exception.NotADirectory(path=dest_repo_base_path) dest_path = self._build_dest_path(build) for rpm in build_rpms: pushed_path = copy_package(rpm, dest_path, overwrite=self.overwrite) pushed_rpms.append(pushed_path) _pushed_build_tmp_paths.append(src_path) _updated_repo_bases.add(dest_repo_base_path) _updated_repos.add( self._dest_repo_path(build.repo, build.dist)) with helpers.cdir(self.update_repo_path): helpers.ensure_dir(self.pushed_dir) upf_base = os.path.basename(upf) pushed_upf = os.path.join(self.pushed_dir, upf_base) pushed_files_fn = pushed_upf + self.pushed_files_ext git('mv', upf, pushed_upf) pushed_files_f = open(pushed_files_fn, 'w') pushed_files_f.writelines( map(lambda x: "%s\n" % x, pushed_rpms)) pushed_files_f.close() git('add', pushed_files_fn) try: git('commit', '-m', "Push %s" % rdoupdate.core.pp_update(upf)) except Exception: git('git', 'reset', '--hard') raise updated_repos.update(_updated_repos) updated_repo_bases.update(_updated_repo_bases) except Exception as ex: if pushed_rpms: log.warn("Final push failed for %s, cleaning copied " "packages" % upf) for rpm in pushed_rpms: log.info("{t.warn}remove{t.normal} {rpm}".format( t=log.term, rpm=rpm)) os.remove(rpm) raise
def copy_package(pkg_path, dest_dir, overwrite=False): helpers.ensure_dir(dest_dir) pkg_name = os.path.basename(pkg_path) dst_path = os.path.join(dest_dir, pkg_name) if not overwrite and os.path.exists(dst_path): raise exception.NewPackageAlreadyPresent(path=dst_path) log.info("{t.bold}copy{t.normal} {src} {t.bold}->{t.normal} {dst}".format( src=pkg_path, dst=dst_path, t=log.term)) shutil.copyfile(pkg_path, dst_path) return dst_path
def _push_pkg(upf): log.info("\nPushing update {t.bold}{upf}{t.normal}".format( t=log.term, upf=upf)) update = self._load_update_file(upf) pushed_rpms = [] try: _updated_repos = set() _updated_repo_bases = set() _pushed_build_tmp_paths = [] for build in update.builds: src_path = self._build_tmp_path(upf, build) if src_path in _pushed_build_tmp_paths: continue build_rpms = helpers.find_files(src_path, ext='.rpm') dest_repo_base_path = self._dest_repo_base_path(build.repo) if not os.path.isdir(dest_repo_base_path): raise exception.NotADirectory(path=dest_repo_base_path) dest_path = self._build_dest_path(build) for rpm in build_rpms: pushed_path = copy_package(rpm, dest_path, overwrite=self.overwrite) pushed_rpms.append(pushed_path) _pushed_build_tmp_paths.append(src_path) _updated_repo_bases.add(dest_repo_base_path) _updated_repos.add(self._dest_repo_path(build.repo, build.dist)) with helpers.cdir(self.update_repo_path): helpers.ensure_dir(self.pushed_dir) upf_base = os.path.basename(upf) pushed_upf = os.path.join(self.pushed_dir, upf_base) pushed_files_fn = pushed_upf + self.pushed_files_ext git('mv', upf, pushed_upf) pushed_files_f = open(pushed_files_fn, 'w') pushed_files_f.writelines( map(lambda x: "%s\n" % x, pushed_rpms)) pushed_files_f.close() git('add', pushed_files_fn) try: git('commit', '-m', "Push %s" % rdoupdate.core.pp_update(upf)) except Exception: git('git', 'reset', '--hard') raise updated_repos.update(_updated_repos) updated_repo_bases.update(_updated_repo_bases) except Exception as ex: if pushed_rpms: log.warn("Final push failed for %s, cleaning copied " "packages" % upf) for rpm in pushed_rpms: log.info("{t.warn}remove{t.normal} {rpm}".format( t=log.term, rpm=rpm)) os.remove(rpm) raise
def submit_existing_update(self, upfile_path, check_availability=True): update = ensure_update_notes(upfile_path) update_rdoinfo_check(update) if check_availability: log.info("Checking availability of updated builds...") for b in update.builds: r = b.is_available(verbose=True) if not r: raise rdoupdate.exception.BuildNotAvailable( build_id=b.id, source=b.source, detail=r.err) update_id, tmp_upfile_path = self._get_new_update_id() tmp_updir_path, _ = os.path.split(tmp_upfile_path) helpers.ensure_dir(tmp_updir_path) shutil.copyfile(upfile_path, tmp_upfile_path) print("\nUpdate:\n%s\n" % update) self.submit_update_file(update_id, msg=str(update))
def new_update(self, update, check_availability=True): update_id, upfile_path = self._get_new_update_id() updir_path, _ = os.path.split(upfile_path) helpers.ensure_dir(updir_path) upfile = file(upfile_path, 'wt') upfile.write(update.update_file()) upfile.close() helpers.edit(upfile_path) cmd.run('/bin/sed', '-i', '-e', '/^#/d', upfile_path, shell=False) parsed_update = None while not parsed_update: try: parsed_update = rdoupdate.actions.check_file(upfile_path) except Exception as ex: print("\n{t.important}Error parsing update file: {t.normal}" "{t.warn}{ex}{t.normal}".format(t=log.term, ex=ex)) again = raw_input("Do you want to edit? [Yn] ") if again and again.lower() != 'y': os.remove(upfile_path) raise exception.UserAbort() helpers.edit(upfile_path) continue if check_availability: log.info("Checking availability of updated builds...") bad_builds = [x for x in parsed_update.builds if not x.is_available(verbose=True)] if bad_builds: builds_str = "\n".join(map(str, bad_builds)) print("\n{t.important}Builds below doesn't seem to be " "available:{t.normal}\n{builds}\n".format( t=log.term, builds=builds_str)) print("Options:") print(" e: Edit update") print(" u: Update anyway") print(" a: Abort") resp = raw_input("What do you want to do? [euA] ").lower() if resp == 'e': parsed_update = None helpers.edit(upfile_path) elif resp == 'u': pass else: raise exception.UserAbort() print("\nUpdate:\n%s\n" % parsed_update) self.submit_update_file(update_id, msg=str(parsed_update))
def _init_env(upf): update_dir_path = self._update_dir_path(upf) helpers.ensure_dir(update_dir_path)