diff --git a/pisi/cli/addrepo.py b/pisi/cli/addrepo.py index c9425bae..90bcf3b2 100644 --- a/pisi/cli/addrepo.py +++ b/pisi/cli/addrepo.py @@ -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