def set_repo_priority(self, repoid, priority): """Assign the given priority to the repository identified by repoid, and save the updated config TODO: For RHSM-based repos, it is probably better to set options via the ReposCommand object - e.g. reposcommand.main(args=['repos', '--enable=REPOID']) - or to just shell out to subscription-manager The current technique will break in the next version of subscription-manager """ repo = self._resolve_repoid(repoid) if self.repo_is_rhn(repo): self._rhn_set_repo_priority(repo, priority) else: # repo is a yum/rhsm repo! try: repo.priority = priority except AttributeError: # Not sure if this is needed or if it would even work... repo.setConfigOption('priority', priority) self.backup_config(repo.repofile) config.writeRawRepoFile(repo, only=['priority'])
def set_save_repo_attr(self, repo, attribute, value): """Set the priority for the given RHN repo Arguments: repo -- rhnplugin.RhnRepo object representing the repository to be updated attribute -- str representing repository configuration attribute to be updated (e.g. 'priority') value -- updated value for specified attribute """ repo = self._resolve_repoid(repo) repo.setAttribute(attribute, value) if self.repo_is_rhn(repo): if hasattr(value, '__iter__'): value = ' '.join(value) self.backup_config(RHNPLUGINCONF) cfg = INIConfig(file(RHNPLUGINCONF)) repocfg = getattr(cfg, repo.id) setattr(repocfg, attribute, value) cfg_file = open(RHNPLUGINCONF, 'w') print >> cfg_file, cfg cfg_file.close() else: self.backup_config(repo.repofile) config.writeRawRepoFile(repo, only=[attribute])