pisi.api.add_repo and pisi.api.update_repo should not remove any repository by force.
These are two seperate calls that just adds a repository and just updates a repository, respectively. Checking distribution or architecture of a repository should be done by the pisi clients. RepoDB has two methods for this (check_architecture, check_distribution) that return False when failed. And any action desired should be taken after by the clients themselves. Removing a repository after a pisi up is insane after a repository is added anyhow. So for pisi-cli, from now on pisi add-repo will add, update and check the repository by default without asking if you want to update the repository or not. If fetching the repository index from the given url fails, pisi cli will remove the repository as before. Two options added to pisi add-repo: --ignore-check and --no-fetch If --ignore-check is given, pisi ignores the arch/distro check after a _successful_ add and update phase. --no-fetch is for not fetching the repository index. If this option is given, pisi will be unable to check the arch and distro of the repository (because we have no index to check) and will warn about this to continue. Summary: If a repository is added to pisi database, this means either it is checked or forced. Either way pisi will use these repositories.
This commit is contained in:
+28
-3
@@ -36,17 +36,31 @@ NB: We support only local files (e.g., /a/b/c) and http:// URIs at the moment
|
||||
|
||||
def __init__(self, args):
|
||||
super(AddRepo, self).__init__(args)
|
||||
self.repodb = pisi.db.repodb.RepoDB()
|
||||
|
||||
name = ("add-repo", "ar")
|
||||
|
||||
def options(self):
|
||||
|
||||
group = optparse.OptionGroup(self.parser, _("add-repo options"))
|
||||
group.add_option("--ignore-check", action="store_true", default=False, help=_("Ignore repository distribution and architecture check"))
|
||||
group.add_option("--no-fetch", action="store_true", default=False, help=_("Does not fetch repository index and does not check distribution and architecture match"))
|
||||
group.add_option("--at", action="store",
|
||||
type="int", default=None,
|
||||
help=_("Add repository at given position (0 is first)"))
|
||||
self.parser.add_option_group(group)
|
||||
|
||||
def warn_and_remove(self, message, repo):
|
||||
ctx.ui.warning(message)
|
||||
pisi.api.remove_repo(repo)
|
||||
|
||||
def check_arch_and_distro(self, repo):
|
||||
warning = _("Repository %s does not match. Removing %s from system.")
|
||||
if not self.repodb.check_architecture(repo):
|
||||
self.warn_and_remove(warning % ("architecture", repo), repo)
|
||||
if not self.repodb.check_distribution(repo):
|
||||
self.warn_and_remove(warning % ("distribution", repo), repo)
|
||||
|
||||
def run(self):
|
||||
|
||||
if len(self.args)==2 or len(self.args)==0:
|
||||
@@ -57,13 +71,24 @@ NB: We support only local files (e.g., /a/b/c) and http:// URIs at the moment
|
||||
else:
|
||||
name = 'pardus-2009'
|
||||
indexuri = 'http://paketler.pardus.org.tr/pardus-2009/pisi-index.xml.bz2'
|
||||
|
||||
if ctx.get_option('no_fetch'):
|
||||
if not ctx.ui.confirm(_('Add %s repository without updating the database?\nBy confirming '
|
||||
'this you are also adding the repository to your system without '
|
||||
'checking the distribution and the architecture of the repository.\n'
|
||||
'Do you want to continue?') % name):
|
||||
return
|
||||
|
||||
pisi.api.add_repo(name, indexuri, ctx.get_option('at'))
|
||||
if ctx.ui.confirm(_('Update PiSi database for repository %s?') % name):
|
||||
|
||||
if not ctx.get_option('no_fetch'):
|
||||
try:
|
||||
pisi.api.update_repo(name)
|
||||
if not ctx.get_option('ignore_check'):
|
||||
self.check_arch_and_distro(name)
|
||||
except (pisi.fetcher.FetchError, IOError):
|
||||
ctx.ui.warning(_("%s repository could not be reached. Removing %s from system.") % (name, name))
|
||||
pisi.api.remove_repo(name)
|
||||
warning = _("%s repository could not be reached. Removing %s from system.") % (name, name)
|
||||
self.warn_and_remove(warning, name)
|
||||
else:
|
||||
self.help()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user