From 7ae0a7eb07e1613271e77814afde372bcb0a8079 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Wed, 5 May 2010 17:01:16 +0200 Subject: [PATCH] [equo] add "equo repo add/remove" tools --- client/equo.py | 6 ++++ client/text_repositories.py | 63 +++++++++++++++++++++++++++++++++++++ docs/man/equo.pod | 8 +++++ docs/man/man1/activator.1 | 2 +- docs/man/man1/equo.1 | 12 +++++-- docs/man/man1/reagent.1 | 2 +- 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/client/equo.py b/client/equo.py index cf1233f60..045ea047a 100644 --- a/client/equo.py +++ b/client/equo.py @@ -69,6 +69,8 @@ help_opts = [ (1, 'repo', 1, _('manage your repositories')), (2, 'enable', 2, _('enable given repository')), (2, 'disable', 1, _('disable given repository')), + (2, 'add ', 1, _('add repository (pass repository string)')), + (2, 'remove ', 1, _('remove repository')), (1, 'notice [repos]', 1, _('repository notice board reader')), (1, 'status', 2, _('show respositories status')), None, @@ -685,6 +687,10 @@ def _repo_enable_disable_bashcomp(cmdline): return sorted(sys_settings['repositories']['excluded'].keys()) elif action == "disable": return sorted(sys_settings['repositories']['available'].keys()) + elif action == "remove": + avail = list(sys_settings['repositories']['available'].keys()) + excl = list(sys_settings['repositories']['excluded'].keys()) + return sorted(set(avail+excl)) return [] BASHCOMP_MAP = { diff --git a/client/text_repositories.py b/client/text_repositories.py index 68a3e8ef9..653a81044 100644 --- a/client/text_repositories.py +++ b/client/text_repositories.py @@ -22,6 +22,7 @@ from entropy.output import red, darkred, blue, brown, bold, darkgreen, green, \ print_info, print_warning, print_error, purple, teal from entropy.core.settings.base import SystemSettings as SysSet from entropy.i18n import _ +from text_tools import print_table import entropy.tools SystemSettings = SysSet() @@ -78,6 +79,10 @@ def repositories(options): rc = _enable_repositories(entropy_client, myopts) elif repo_opt == "disable": rc = _disable_repositories(entropy_client, myopts) + elif repo_opt == "add": + rc = _add_repository(entropy_client, myopts) + elif repo_opt == "remove": + rc = _remove_repository(entropy_client, myopts) else: rc = -10 @@ -98,6 +103,64 @@ def repositories(options): return rc +def _add_repository(entropy_client, repo_strings): + + current_branch = SystemSettings['repositories']['branch'] + current_product = SystemSettings['repositories']['product'] + available_repos = SystemSettings['repositories']['available'] + + for repo_string in repo_strings: + if not repo_string: + print_warning("[%s] %s" % ( + purple(repo_string), blue(_("invalid data, skipping")),)) + continue + if not ((repo_string.startswith("repository|")) and \ + (len(repo_string.split("|")) == 5)): + print_warning("[%s] %s" % ( + purple(repo_string), + blue(_("invalid repository string, skipping")),) + ) + continue + + print_info("%s: %s" % ( + teal(_("Adding repository string")), blue(repo_string),)) + + repoid, repodata = SystemSettings._analyze_client_repo_string( + repo_string, current_branch, current_product) + + # print some info + toc = [] + toc.append((purple(_("Repository id:")), teal(repoid))) + toc.append((darkgreen(_("Description:")), teal(repodata['description']))) + toc.append((purple(_("Repository format:")), darkgreen(repodata['dbcformat']))) + toc.append((brown(_("Service port:")), teal(str(repodata['service_port'])))) + toc.append((brown(_("Service port (SSL):")), teal(str(repodata['ssl_service_port'])))) + for pkg_url in repodata['plain_packages']: + toc.append((purple(_("Packages URL:")), pkg_url)) + db_url = repodata['plain_database'] + if not db_url: + db_url = _("None given") + toc.append((purple(_("Repository URL:")), darkgreen(db_url))) + toc.append(" ") + print_table(toc) + entropy_client.add_repository(repodata) + print_info("[%s] %s" % ( + purple(repoid), blue(_("repository added succesfully")),)) + +def _remove_repository(entropy_client, repo_ids): + + excluded_repos = SystemSettings['repositories']['excluded'] + available_repos = SystemSettings['repositories']['available'] + repos = set(list(excluded_repos.keys()) + list(available_repos.keys())) + for repo_id in repo_ids: + if repo_id not in repos: + print_warning("[%s] %s" % ( + purple(repo_id), blue(_("repository id not available")),)) + continue + + entropy_client.remove_repository(repo_id) + print_info("[%s] %s" % ( + purple(repo_id), blue(_("repository removed succesfully")),)) def _enable_repositories(entropy_client, repos): excluded_repos = SystemSettings['repositories']['excluded'] diff --git a/docs/man/equo.pod b/docs/man/equo.pod index 287b61916..4738499cf 100644 --- a/docs/man/equo.pod +++ b/docs/man/equo.pod @@ -78,6 +78,14 @@ enable given repository disable given repository +=item B> + +add repository (pass repository string) + +=item B> + +remove repository + =back =item B diff --git a/docs/man/man1/activator.1 b/docs/man/man1/activator.1 index 18baa4d49..13eee5238 100644 --- a/docs/man/man1/activator.1 +++ b/docs/man/man1/activator.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "ACTIVATOR 1" -.TH ACTIVATOR 1 "2010-03-29" "perl v5.10.1" "Entropy" +.TH ACTIVATOR 1 "2010-03-25" "perl v5.10.1" "Entropy" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/docs/man/man1/equo.1 b/docs/man/man1/equo.1 index e80a4deaf..f72881f76 100644 --- a/docs/man/man1/equo.1 +++ b/docs/man/man1/equo.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "EQUO 1" -.TH EQUO 1 "2010-05-02" "perl v5.10.1" "Entropy" +.TH EQUO 1 "2010-05-05" "perl v5.10.1" "Entropy" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -190,6 +190,12 @@ enable given repository .IP "\fBdisable\fR" 4 .IX Item "disable" disable given repository +.IP "\fBadd " 4 +.IX Item "add " +add repository (pass repository string) +.IP "\fBremove " 4 +.IX Item "remove " +remove repository .RE .RS 4 .RE @@ -1170,6 +1176,6 @@ Fabio Erculiani .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR -.IP "Around line 1332:" 4 -.IX Item "Around line 1332:" +.IP "Around line 1340:" 4 +.IX Item "Around line 1340:" You forgot a '=back' before '=head1' diff --git a/docs/man/man1/reagent.1 b/docs/man/man1/reagent.1 index 1daab760d..61964ebab 100644 --- a/docs/man/man1/reagent.1 +++ b/docs/man/man1/reagent.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "REAGENT 1" -.TH REAGENT 1 "2010-03-30" "perl v5.10.1" "Entropy" +.TH REAGENT 1 "2010-04-01" "perl v5.10.1" "Entropy" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l