From 443068b9f6e5ed34e07a6d1e5c9cebf1527106a1 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Mon, 31 Aug 2015 23:27:06 +0300 Subject: [PATCH] Updated for repo-enable coomand --- ChangeLog.txt | 6 ++++- KNOWN_ISSUES | 9 +++++++ README.rst | 16 +++++++++++- man/slpkg.8 | 6 +++++ slpkg/arguments.py | 3 +++ slpkg/main.py | 15 ++++++++++-- slpkg/repoenable.py | 59 ++++++++++++++++++++++++++++++++++++--------- 7 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 KNOWN_ISSUES diff --git a/ChangeLog.txt b/ChangeLog.txt index 7499daf6..11dc810c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,9 +1,13 @@ -2.7.7 - 30/08/2015 +2.7.7 - 31/08/2015 Added: - NEW configuration file for repositories in /etc/slpkg/repositories.conf +- Enable and disable repositories with command via dialog utility Update: - Command line help logo - Flags for packages upgrade +- Clear screen after exit dialog utility +Fixed: +- Remove None type packages 2.7.6 - 28/08/2015 Fixed: diff --git a/KNOWN_ISSUES b/KNOWN_ISSUES new file mode 100644 index 00000000..9695f9f6 --- /dev/null +++ b/KNOWN_ISSUES @@ -0,0 +1,9 @@ +Known issues: + +- Dialog utility crash in option --buildlist when move with arrows + sometimes without yet that create big issues. + Issues reference here: + https://sourceforge.net/p/pythondialog/bugs/6/ + + Upgrade dialog utility from here if only necessary: + https://github.com/dslackw/slacks/tree/master/dialog diff --git a/README.rst b/README.rst index 2e09e682..4c122d48 100644 --- a/README.rst +++ b/README.rst @@ -196,7 +196,7 @@ choices such read, download, build, install etc. If you want to find packages from all repositories, this command will solve your hands '$ slpkg -F '. It will search in all enabled repositories will find the configuration file -'/etc/slpkg/slpkg.conf' will print all the packages that match the description that you enter. +'/etc/slpkg/repositories.conf' will print all the packages that match the description that you enter. If you want to see if any packages are installed on your system enter the command '$ slpkg -f '. The surprise in the end is the reporting of packages sum and size found. @@ -369,6 +369,8 @@ Command Line Tool Usage lists. repo-add [repository name] [URL] Add custom repository. repo-remove [repository] Remove custom repository. + repo-enable Enable or disable default + repositories via dialog utility. repo-list Print a list of all the repositories. repo-info [repository] Get information about a @@ -445,6 +447,18 @@ Command Line Tool Usage Slpkg Examples -------------- +Enable default repositories edit /etc/slpkg/repositories.conf file or with +command. +(require pythondialog, install with '# slpkg -s sbo python2-pythondialog'): + +.. code-block:: bash + + $ slpkg repo-enable + +.. image:: https://raw.githubusercontent.com/dslackw/images/master/slpkg/repo_enable.png + :target: https://raw.githubusercontent.com/dslackw/images/master/slpkg/deps2.png + + If you use slpkg for the first time will have to create and update the package list. This command must be executed to update the package lists: diff --git a/man/slpkg.8 b/man/slpkg.8 index 9d2dcbf1..bda46bfa 100644 --- a/man/slpkg.8 +++ b/man/slpkg.8 @@ -20,6 +20,7 @@ Usage: slpkg Commands: [upgrade, --only=[...]] [repo-add [repository name] [URL]] [repo-remove [repository]] + [repo-enable] [repo-list] [repo-info [repository]] [update [slpkg]] @@ -95,6 +96,11 @@ contain at least the files "PACKAGES.TXT" and "CHECKSUMS.md5" and optional file .PP Remove custom repository by name. +.SS repo-enable, enable or disable repositories +\fBslpkg\fP \fBrepo-enable\fP +.PP +Enable or disable repositories via dialog utility (require pythondialog) + .SS repo-list, repositories list \fBslpkg\fP \fBrepo-list\fP .PP diff --git a/slpkg/arguments.py b/slpkg/arguments.py index 4288e44b..4a6e359c 100644 --- a/slpkg/arguments.py +++ b/slpkg/arguments.py @@ -50,6 +50,8 @@ Commands: lists. repo-add [repository name] [URL] Add custom repository. repo-remove [repository] Remove custom repository. + repo-enable Enable or disable default + repositories via dialog utility. repo-list Print a list of all the repositories. repo-info [repository] Get information about a @@ -137,6 +139,7 @@ def usage(repo): [upgrade, --only=[...]] [repo-add [repository name] [URL]] [repo-remove [repository]] + [repo-enable] [repo-list] [repo-info [repository]] [update [slpkg]] diff --git a/slpkg/main.py b/slpkg/main.py index ed202da9..8a057903 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -41,6 +41,7 @@ from slpkg.version import prog_version from slpkg.health import PackageHealth from slpkg.new_config import NewConfig from slpkg.tracking import TrackingDeps +from slpkg.repoenable import RepoEnable from slpkg.pkg_find import find_from_repos from slpkg.arguments import options, usage from slpkg.slpkg_update import it_self_update @@ -76,6 +77,7 @@ class ArgParse(object): "upgrade", "repo-add", "repo-remove", + "repo-enable", "repo-list", "repo-info", "update-slpkg", @@ -86,8 +88,8 @@ class ArgParse(object): # checking if repositories exists if len(self.args) > 1 and self.args[0] not in [ - "-h", "--help", "-v", "--version", "upgrade", "repo-list", - "repo-add", "repo-remove", "update", "update-slpkg", + "-h", "--help", "-v", "--version", "upgrade", "repo-enable", + "repo-list", "repo-add", "repo-remove", "update", "update-slpkg", "health", "-g", "--config" ]: check_exists_repositories() @@ -127,6 +129,14 @@ class ArgParse(object): else: usage("") + def command_repo_enable(self): + """Repositories enable/disable + """ + if len(self.args) == 1 and self.args[0] == "repo-enable": + RepoEnable().choose() + else: + usage("") + def command_repo_list(self): """Repositories list """ @@ -581,6 +591,7 @@ def main(): "update": argparse.command_update, "upgrade": argparse.command_upgrade, "update-slpkg": argparse.command_update_slpkg, + "repo-enable": argparse.command_repo_enable, "repo-list": argparse.command_repo_list, "repo-add": argparse.command_repo_add, "repo-remove": argparse.command_repo_remove, diff --git a/slpkg/repoenable.py b/slpkg/repoenable.py index 75ecf627..8f0ebbbd 100644 --- a/slpkg/repoenable.py +++ b/slpkg/repoenable.py @@ -22,16 +22,21 @@ # along with this program. If not, see . +import os + from slpkg.utils import Utils from slpkg.dialog_box import DialogUtil from slpkg.__metadata__ import MetaData as _meta_ class RepoEnable(object): - + """Read repositories.conf file and update with new enabled or + disabled repositories + """ def __init__(self): self.meta = _meta_ self.tag = "[REPOSITORIES]" + self.tag_line = False self.repositories_conf = "repositories.conf" self.conf = Utils().read_file( self.meta.conf_path + self.repositories_conf) @@ -50,40 +55,70 @@ Keys: SPACE select or deselect the highlighted repositories, TAB move focus ENTER press the focused button - Disabled <----------------------> Enabled""" + Disabled <-------- REPOSITORIES -------> Enabled""" self.read_enabled() self.read_disabled() self.selected = DialogUtil(self.disabled, text=keys, title="Enable | Disable Repositories", backtitle="", status=False).buildlist(self.enabled) - self.update() + self.update_repos() + self.clear_screen() + self.reference() def read_enabled(self): """Read enable repositories """ - read_line = False for line in self.conf.splitlines(): line = line.lstrip() if self.tag in line: - read_line = True - if (line and read_line and not line.startswith("#") and + self.tag_line = True + if (line and self.tag_line and not line.startswith("#") and self.tag not in line): self.enabled.append(line) + self.tag_line = False def read_disabled(self): """Read disable repositories """ - read_line = False for line in self.conf.splitlines(): line = line.lstrip() if self.tag in line: - read_line = True - if read_line and line.startswith("#"): + self.tag_line = True + if self.tag_line and line.startswith("#"): line = "".join(line.split("#")).strip() self.disabled.append(line) + self.tag_line = False - def update(self): - print self.selected + def update_repos(self): + """Update repositories.conf file with enabled or disabled + repositories + """ + with open("{0}{1}".format(self.meta.conf_path, + self.repositories_conf), "w") as new_conf: + for line in self.conf.splitlines(): + line = line.lstrip() + if self.tag in line: + self.tag_line = True + if self.tag_line and line.startswith("#"): + repo = "".join(line.split("#")).strip() + if repo in self.selected: + new_conf.write(line.replace(line, repo + "\n")) + continue + if (self.tag_line and not line.startswith("#") and + line != self.tag): + repo = line.strip() + if repo not in self.selected: + new_conf.write(line.replace(line, "# " + line + "\n")) + continue + new_conf.write(line + "\n") -RepoEnable().choose() + def clear_screen(self): + """Clear screen + """ + os.system("clear") + + def reference(self): + """Reference enable repositories + """ + print("Enabled repositories: {0}".format(", ".join(self.selected)))