From 83a15cdf01637fa07f6585f020798fe6a6ad7785 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 10 Sep 2015 06:57:12 +0300 Subject: [PATCH] Add editor via configuration file --- README.rst | 6 +++--- conf/slpkg.conf | 4 ++++ man/slpkg.8 | 6 +++--- slpkg/__metadata__.py | 4 +++- slpkg/arguments.py | 6 +++--- slpkg/config.py | 8 +++++--- slpkg/main.py | 7 +++---- slpkg/sbo/network.py | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/README.rst b/README.rst index 389262f9..6f3fa8fd 100644 --- a/README.rst +++ b/README.rst @@ -300,7 +300,7 @@ For Slackware 'current' users must change the variable VERSION in '/etc/slpkg/sl .. code-block:: bash - $ slpkg -g edit=nano + $ slpkg -g edit Slackware ARM @@ -412,8 +412,8 @@ Command Line Tool Usage --remove, list, build, install, Add or remove and print the list build-install of packages. Build and then install the packages from the queue. - -g, --config, print, edit=[editor], Configuration file management. - reset Print, edit the configuration file + -g, --config, print, edit, reset Configuration file management. + Print, edit the configuration file or reset in the default values. -l, --list, [repository], --index, Print a list of all available --installed packages repository, index or print diff --git a/conf/slpkg.conf b/conf/slpkg.conf index 461003ea..da058a8f 100644 --- a/conf/slpkg.conf +++ b/conf/slpkg.conf @@ -109,3 +109,7 @@ ONLY_INSTALLED=off # Enable or disable the progress bar. Status bar progress delays the search # process in package lists. Choose "off" if you need speed. Deafult is "on". PRG_BAR=on + +# Register a text editor that uses the slpkg in a few options. +# Default is "nano". +EDITOR=nano diff --git a/man/slpkg.8 b/man/slpkg.8 index 9f19739f..87b4363e 100644 --- a/man/slpkg.8 +++ b/man/slpkg.8 @@ -34,7 +34,7 @@ Usage: slpkg Commands: [-b [package...] --add, --remove, list] [-q [package...] --add, --remove, list] [-q [build, install, build-install]] - [-g [print, edit=[editor], reset]] + [-g [print, edit, reset]] [-l [repository], --index, --installed] [-c [repository], --upgrade, --skip=[...], --resolve-off, --checklist] @@ -177,9 +177,9 @@ dependencies. If you want to remove all the packages from the list run "# slpkg Build or install or build and install packages are queued. .SS -g, --config, configuration file management -\fBslpkg\fP \fB-g\fP \fBprint\fP, \fBedit=[editor]\fP, \fBreset\fP +\fBslpkg\fP \fB-g\fP \fBprint\fP, \fBedit\fP, \fBreset\fP .PP -Print, reset or edit configuration file with your favorite editor. +Print, reset or edit configuration file. .SS -l, --list, list of installed packages \fBslpkg\fP \fB-l\fP <\fIrepository\fP>, \fB--index\fP, \fB--installed\fP diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index a72f844f..0654162f 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -129,7 +129,8 @@ class MetaData(object): "DOWNDER_OPTIONS": "-c -N", "SLACKPKG_LOG": "on", "ONLY_INSTALLED": "off", - "PRG_BAR": "on" + "PRG_BAR": "on", + "EDITOR": "nano" } default_repositories = ["slack", "sbo", "rlw", "alien", "slacky", "studio", @@ -171,6 +172,7 @@ class MetaData(object): slackpkg_log = _conf_slpkg["SLACKPKG_LOG"] only_installed = _conf_slpkg["ONLY_INSTALLED"] prg_bar = _conf_slpkg["PRG_BAR"] + editor = _conf_slpkg["EDITOR"] # Remove any gaps repositories = [repo.strip() for repo in repositories] diff --git a/slpkg/arguments.py b/slpkg/arguments.py index 7dde1da6..c4e76e59 100644 --- a/slpkg/arguments.py +++ b/slpkg/arguments.py @@ -81,8 +81,8 @@ Optional arguments: --remove, list, build, install, Add or remove and print the list build-install of packages. Build and then install the packages from the queue. - -g, --config, print, edit=[editor], Configuration file management. - reset Print, edit the configuration file + -g, --config, print, edit, reset Configuration file management. + Print, edit the configuration file or reset in the default values. -l, --list, [repository], --index, Print a list of all available --installed packages repository, index or print @@ -154,7 +154,7 @@ def usage(repo): [-b [package...] --add, --remove, list] [-q [package...] --add, --remove, list] [-q [build, install, build-install]] - [-g [print, edit=[editor], reset]] + [-g [print, edit, reset]] [-l [repository], --index, --installed] [-c [repository], --upgrade, --skip=[...], --resolve-off, --checklist] diff --git a/slpkg/config.py b/slpkg/config.py index 45923949..5cc64c52 100644 --- a/slpkg/config.py +++ b/slpkg/config.py @@ -62,7 +62,8 @@ class Config(object): "DOWNDER_OPTIONS", "SLACKPKG_LOG", "ONLY_INSTALLED", - "PRG_BAR" + "PRG_BAR", + "EDITOR" ] read_conf = Utils().read_file(self.config_file) try: @@ -77,11 +78,12 @@ class Config(object): raise SystemExit() print("") # new line at end - def edit(self, editor): + def edit(self): """ Edit configuration file """ - subprocess.call("{0} {1}".format(editor, self.config_file), shell=True) + subprocess.call("{0} {1}".format(self.meta.editor, + self.config_file), shell=True) def reset(self): """Reset slpkg.conf file with default values diff --git a/slpkg/main.py b/slpkg/main.py index a05e31c1..a655c656 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -535,11 +535,10 @@ class ArgParse(object): """Manage slpkg configuration file """ options = ["-g", "--config"] - command = ["print", "edit=", "reset"] + command = ["print", "edit", "reset"] if (len(self.args) == 2 and self.args[0] in options and - self.args[1].startswith(command[1])): - editor = self.args[1][len(command[1]):] - Config().edit(editor) + self.args[1] == command[1]): + Config().edit() elif (len(self.args) == 2 and self.args[0] in options and self.args[1] == (command[0])): Config().view() diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py index 14ebfcfd..812abcb8 100644 --- a/slpkg/sbo/network.py +++ b/slpkg/sbo/network.py @@ -202,7 +202,7 @@ class SBoNetwork(object): with open(self.customs_path + filename, "w") as sbo_file: sbo_file.write(contents) subprocess.call( - "{0} {1}".format("vim", self.customs_path + filename), + "{0} {1}".format(self.meta.editor, self.customs_path + filename), shell=True) def view_sbo(self):