From 80be208729dc9a9d6e6807b6e6a7d28553dfb64d Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 28 Dec 2019 18:34:33 +0100
Subject: [PATCH 01/40] Added html doc
---
man/slpkg.html | 743 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 743 insertions(+)
create mode 100644 man/slpkg.html
diff --git a/man/slpkg.html b/man/slpkg.html
new file mode 100644
index 00000000..15571370
--- /dev/null
+++ b/man/slpkg.html
@@ -0,0 +1,743 @@
+
+
+
+
+
+
+
+
+
+Slpkg
+
+
+
+
+Slpkg
+
+NAME
+SYNOPSIS
+DESCRIPTION
+GLOBAL OPTIONS
+COMMANDS
+OPTIONS
+HELP OPTION
+DEFAULT REPOSITORIES
+COLORS
+REGEX
+PASS VARIABLES TO THE SCRIPT
+FILES
+AUTHOR
+HOMEPAGE
+COPYRIGHT
+SEE ALSO
+
+
+
+
+NAME
+
+
+
+
+Slpkg is a
+user-friendly package manager for Slackware
+installations
+
+SYNOPSIS
+
+
+
+
+slpkg
+[COMMANDS|OPTIONS] {repository|package...}
+
+DESCRIPTION
+
+
+
+
+Slpkg is a
+powerful software package manager that installs, updates,
+and removes packages on Slackware based systems. It
+automatically computes dependencies and figures out what
+things should occur to install packages. Slpkg makes it
+easier to maintain groups of machines without having to
+manually update.
+
+GLOBAL OPTIONS
+
+
+
+
+
+−v,
+−−version
+
+Print the
+version of program and exit.
+
+COMMANDS
+
+
+
+
+The following
+commands are available.
+
+update,
+create and update packages list
+slpkg update,
+--repositories=[repositories...]
+
+Used to
+re-synchronize the package lists and create some important
+files. This command must run every new repository is added
+or new updates is available.
+
+Additional
+options:
+
+
+--repositories=[repositories...]
+: Update at specifically repositories separate by comma.
+
+upgrade,
+recreate packages list
+slpkg upgrade,
+--repositories=[repositories...]
+
+It is sometimes
+useful to create all of the base file from the beginning so
+this command delete all the package lists and recreated.
+
+Additional
+options:
+
+
+--repositories=[repositories...]
+: Update at specifically repositories separate by comma.
+
+repo-add,
+add custom repository
+slpkg repo-add <repository name>
+<URL>
+
+Add custom
+binary repository. The repositories will be added to this
+command should contain at least the files
+"PACKAGES.TXT" and "CHECKSUMS.md5" and
+optional file "ChangeLog.txt" used to control
+changes.
+
+
+repo-remove,
+remove custom repository
+slpkg repo-remove <repository>
+
+Remove custom
+repository by name.
+
+
+repo-enable,
+enable or disable repositories
+slpkg repo-enable
+
+Enable or
+disable repositories via dialog utility (require
+python3-pythondialog)
+
+repo-list,
+repositories list
+slpkg repo-list
+
+Lists all
+enabled or disabled repositories.
+
+repo-info,
+repository information
+slpkg repo-info <repository>
+
+View repository
+information.
+
+update
+slpkg, update slpkg itself
+slpkg update slpkg
+
+You can check
+for new versions and update slpkg itself.
+
+health,
+health check installed packages
+slpkg health, --silent
+
+Check file list
+from packages of files installed.
+
+Additional
+options:
+
+
+--silent
+: Print only errors.
+
+
+deps-status,
+print dependencies status
+slpkg deps-status --graph=[type]
+
+Print
+dependencies status used by packages. Prerequisite packages
+have been installed with the option "# slpkg -s
+<repository> <packages>".
+
+Additional
+options:
+
+
+--graph=[type]
+: Drawing dependencies diagram. (example for type: ascii,
+image.x11, image.png etc. Require pygraphviz)
+
+--tree :
+Switch to tree view.
+
+new-config,
+manage .new configuration files
+slpkg new-config
+
+This command
+searches for .new configuration files in /etc/ path and ask
+the user what todo with those files.
+
+clean-tmp,
+clean the tmp/ directory
+slpkg clean-tmp
+
+Clean the
+/tmp/slpkg/ directory from downloaded packages and
+sources.
+
+OPTIONS
+
+
+
+
+The following
+arguments are available.
+
+-a,
+--autobuild, auto build packages
+slpkg -a <script.tar.gz>
+<sources>
+
+If you already
+have download the script and source with this argument you
+can build Slackware package from source quickly and easy.
+Slpkg will grab checksum from the .info file to make control
+if he does not agree with the versions you will get the
+wrong message. If you want switch off checksum from the
+configuration file.
+
+-b,
+--blacklist, add, remove, view packages in blacklist
+slpkg -b <name of packages> --add,
+--remove, list
+
+Add, remove or
+listed packages from blacklist file. The settings here
+affect all repositories. Remove all packages from blacklist
+use argument like "# slpkg -b --remove". Use
+asterisk "*" to match pagkages like "# slpkg
+-b py* --add", this add all installed packages with
+starts string "py" or "# slpkg -b
+multi:*multilib* --add", this add all multilib packages
+from repository "multi".
+
+-q, --queue,
+add, remove, view packages in queue
+slpkg -q <names of packages> --add,
+--remove
+slpkg -q list, build, install,
+build-install
+
+Add, remove and
+listed sbo packages from queue. This argument is very useful
+if you want to build and install multiple packages together.
+Note the correct order if there are dependencies. If you
+want to remove all the packages from the list run "#
+slpkg -q --remove". (these arguments only working for
+the sbo repository) Build or install or build and install
+packages are queued.
+
+-g,
+--config, configuration file management
+slpkg -g print, edit, reset
+
+Print, reset or
+edit configuration file.
+
+-l, --list,
+list of installed packages
+slpkg -l <repository>, --index,
+--installed, --name
+
+Print a list of
+all available packages from repository, index or print only
+packages installed on the system. Support command
+"grep" like "# slpkg -l sbo | grep
+python".
+
+Additional
+options:
+
+--index
+: Count packages per page.
+
+
+--installed
+: Highlight installed packages.
+
+--name :
+Print package name only.
+
+-c, --check,
+check if your packages is up to date
+slpkg -c <repository> --upgrade
+--rebuild --skip=[packages...], --resolve-off,
+--checklist
+
+Check your
+packages if up to date. Slackware patches repository works
+independently of the others i.e not need before updating the
+list of packages by choosing "# slpkg update",
+works directly with the official repository and so always
+you can have updated your system.
+
+Additional
+options:
+
+-c :
+Check ChangeLog.txt files for changes.
+
+
+--upgrade
+: Check and install packages for upgrade.
+
+
+--rebuild
+: Rebuild packages from sbo repository.
+
+
+--resolve-off
+: Switch off automatic resolve dependencies.
+
+
+--skip=[packages...]
+: Skip packages from upgrade separate by comma like "#
+slpkg -c sbo --skip=jdk,pep8,pip" (See REGEX).
+
+
+--checklist
+: Enable dialog utility and checklist option. (Require
+python2-pythondialog)
+
+-s, --sync,
+synchronize packages, download, build and install package
+with all dependencies
+slpkg -s <repository> <names of
+packages>, --resolve-off, --case-ins,
+--patches
+
+Installs or
+upgrade packages from the repositories with automatically
+resolving all dependencies of the package.
+
+Additional
+options:
+
+
+--rebuild
+: Rebuild packages from sbo repository.
+
+
+--reinstall
+: Reinstall binary packages from repositories.
+
+
+--resolve-off
+: Switch off automatic resolve dependencies.
+
+
+--download-only
+: Download packages without install.
+
+
+--directory-prefix=[path/to/dir/]
+: Download packages in specific directory.
+
+
+--case-ins
+: Search package name in repository with case
+insensitive.
+
+
+--patches
+: Switch to patches directory, only for slack
+repository.
+
+-t,
+--tracking, tracking dependencies
+slpkg -t <repository> <name of
+package>, --check-deps, --graph=[type]
+--case-ins
+
+Tracking all
+dependencies of that package. The sequence shown is that you
+must follow to correctly install package. Also you can check
+if the installed package has all the required
+dependencies.
+
+Additional
+options:
+
+
+--check-deps
+: Check if installed packages used by other packages.
+
+
+--graph=[type]
+: Drawing dependencies graph. (example for type: ascii,
+image.x11, image.png etc. Require pygraphviz)
+
+
+--case-ins
+: Search package name in repository with case
+insensitive.
+
+-p, --desc,
+print packages description
+slpkg -p <repository> <name of
+package>, --color=[]
+
+Print package
+description from remote repository with color. Available
+colors: red, green, yellow, cyan, grey
+
+Additional
+options:
+
+
+--color=[]
+: Change color print.
+
+-F, --FIND,
+find packages from repositories
+slpkg -F <names of packages>,
+--case-ins
+
+Find packages
+from all repositories are enabled. Useful command to find
+all available packages per repository.
+
+Additional
+options:
+
+
+--case-ins
+: Search package name in repository with case
+insensitive.
+
+-f, --find,
+find installed packages
+slpkg -f <names of packages>,
+--case-ins, --third-party
+
+Find installed
+packages with view total file size. Example you can view all
+installed sbo packages like "# slpkg -f _SBo".
+
+Additional
+options:
+
+
+--case-ins
+: Search package name with case insensitive.
+
+
+--third-party
+: View all the third-party packages.
+
+-n,
+--network, view SBo packages
+slpkg -n <name of package>,
+<[pattern], --checklist>, --case-ins
+
+View complete
+slackbuilds.org site in your terminal. Read file, download,
+build or install etc. Use "--checklist" additional
+option to load all repository, example: "# slpkg -n
+--checklist".
+
+Additional
+options:
+
+
+--checklist
+: Enable dialog utility and checklist option. (Require
+python3-pythondialog)
+
+
+--case-ins
+: Search package name in repository with case
+insensitive.
+
+-i,
+--installpkg, install Slackware binary packages
+slpkg -i [--warn, --md5sum, --root /otherroot, --infobox,
+--menu, --terse, --ask, --priority ADD|REC|OPT|SKP,
+--tagfile /somedir/tagfile]
+<packages.t?z>
+
+Installs single
+binary packages designed for use with the Slackware Linux
+distribution into your system. More information please read
+"man installpkg".
+
+-u,
+--upgradepkg, install-upgrade Slackware binary packages with
+new
+slpkg -u [--dry-run, --install-new, --reinstall,
+--verbose] <packages.t?z>
+
+Normally
+upgrade only upgrades packages that are already installed on
+the system, and will skip any packages that do not already
+have a version installed. More information please read
+"man upgradepkg".
+
+-r,
+--removepkg, remove previously installed Slackware binary
+packages
+slpkg -r [-copy, -keep, -preserve, -warn] <names
+of packages>, --deps, --check-deps,
+--tag, --checklist, --third-party
+
+Removes a
+previously installed Slackware package, while writing a
+progress report to the standard output. A package may be
+specified either by the full package name (as you’d
+see listed in /var/log/packages/), or by the base package
+name. If installed packages with command "# slpkg -s
+<repo> <packages>" then write a file in
+/var/log/slpkg/dep/ with all dependencies and it allows you
+can remove them all together. More information please read
+"man removepkg".
+
+Additional
+options:
+
+--deps :
+Remove packages with dependencies.
+
+
+--check-deps
+: Check if installed packages used by other packages.
+
+--tag :
+Remove packages with by TAG.
+
+
+--checklist
+: Enable dialog utility and checklist option. (Require
+python3-pythondialog)
+
+
+--third-party
+: Remove all the third-party packages. (Be sure update the
+package lists before)
+
+-d,
+--display, display the installed packages contents and file
+list
+slpkg -d <names of packages>
+
+Display the
+installed Slackware packages contents and file list with all
+descriptions.
+
+HELP OPTION
+
+
+
+
+Specifying the
+help option displays help for slpkg itself, or a command.
+
+For example:
+slpkg −−help - display help for slpkg
+
+DEFAULT REPOSITORIES
+
+
+
+
+slackware.com =
+"slack"
+SlackBuilds.org = "sbo"
+Alien’s = "alien"
+slacky.eu = "slacky"
+rworkman’s = "rlw"
+Conraid’s = "conrad"
+slackonly.com = "slonly"
+Alien’s ktown = "ktown{latest}"
+Alien’s multilib = "multi"
+Slacke E17 and E18 = "slacke{18}"
+SalixOS = "salix"
+Slackel.gr = "slackel"
+Alien’s restricted = "rested"
+MATE Desktop Environment = "msb{1.18}"
+Cinnamon Desktop Environment = "csb"
+Connochaetos slack-n-free = "connos"
+Microlinux mles = "mles"
+
+Default enable
+repository is "slack" and "sbo".
+Add or remove default repository in configuration file
+"/etc/slpkg/repositories.conf".
+Read REPOSITORIES file for particularities.
+
+COLORS
+
+
+
+
+red, green,
+yellow, cyan, grey
+
+REGEX
+
+
+
+
+For options
+"--skip=" and blacklist file.
+
+All packages
+starts with: "string*"
+All packages ends with: "*string"
+All packages include: "*string*"
+
+PASS VARIABLES TO THE SCRIPT
+
+
+
+
+If you want to
+pass variables to the script exported as:
+Usage: <NAME_VARIABLE=value>
+
+Example:
+"# export FFMPEG_X264=yes FFMPEG_LAME=yes"
+
+FILES
+
+
+
+
+
+/etc/slpkg/slpkg.conf
+
+General configuration of slpkg
+
+
+/etc/slpkg/repositories.conf
+
+Configuration file for repositories
+
+
+/etc/slpkg/blacklist
+
+List of packages to skip
+
+
+/etc/slpkg/slackware-mirrors
+
+List of Slackware Mirrors
+
+
+/etc/slpkg/default-repositories
+
+List of default repositories
+
+
+/etc/slpkg/custom-repositories
+
+List of custom repositories
+
+
+/etc/slpkg/rlworkman.deps
+
+Rworkman’s repository dependencies
+
+
+/etc/slpkg/pkg_security
+
+List of packages for security reasons
+
+/var/log/slpkg
+
+ChangeLog.txt repositories files
+SlackBuilds logs and dependencies files
+
+/var/lib/slpkg
+
+PACKAGES.TXT files
+SLACKBUILDS.TXT files
+CHECKSUMS.md5 files
+FILELIST.TXT files
+
+/tmp/slpkg
+Slpkg temporary downloaded files and build packages
+
+AUTHOR
+
+
+
+
+Dimitris
+Zlatanidis <d.zlatanidis@gmail.com>
+
+HOMEPAGE
+
+
+
+
+
+https://dslackw.gitlab.io/slpkg/
+
+COPYRIGHT
+
+
+
+
+Copyright
+© 2014-2019 Dimitris Zlatanidis
+
+SEE ALSO
+
+
+
+
+installpkg(8),
+upgradepkg(8), removepkg(8), pkgtool(8), slackpkg(8),
+explodepkg(8), makepkg(8).
+
+
+
From a3605544f6953c324825aa9629ded9cecb7a91b7 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sun, 5 Jan 2020 23:51:59 +0100
Subject: [PATCH 02/40] Added some pytest
Signed-off-by: Dimitris Zlatanidis
---
slpkg/md5sum.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/slpkg/md5sum.py b/slpkg/md5sum.py
index 3d2c71ab..f8d3bf48 100644
--- a/slpkg/md5sum.py
+++ b/slpkg/md5sum.py
@@ -33,3 +33,11 @@ def md5(source):
with open(source, "rb") as file_to_check:
data = file_to_check.read()
return hashlib.md5(data).hexdigest()
+
+
+def test_md5(source="superuser.py"):
+ """Testing hashing with pytest"""
+ source = source.replace("%2B", "+")
+ with open(source, "rb") as file_to_check:
+ data = file_to_check.read()
+ assert hashlib.md5(data).hexdigest() == "e6cebdf37fbc1b8e9d3c5e3e53b300c1"
From be3025797e06c3776fd83cd20396566d3d2a94dd Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Fri, 10 Jan 2020 23:56:56 +0100
Subject: [PATCH 03/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/__metadata__.py | 14 +++++++-------
slpkg/arguments.py | 11 +++++------
slpkg/auto_pkg.py | 15 ++++++---------
slpkg/blacklist.py | 13 ++++++-------
4 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py
index 0b0bb668..fd8d3d71 100644
--- a/slpkg/__metadata__.py
+++ b/slpkg/__metadata__.py
@@ -40,7 +40,7 @@ def update_repositories(repositories, conf_path):
"""
Upadate with user custom repositories
"""
- repo_file = "{0}custom-repositories".format(conf_path)
+ repo_file = f"{conf_path}custom-repositories"
if os.path.isfile(repo_file):
f = open(repo_file, "r")
repositories_list = f.read()
@@ -90,11 +90,11 @@ class MetaData:
slack_rel = "stable"
# Configuration path
- conf_path = "/etc/{0}/".format(__all__)
+ conf_path = f"/etc/{__all__}/"
# tmp paths
tmp = "/tmp/"
- tmp_path = "{0}{1}/".format(tmp, __all__)
+ tmp_path = f"{tmp}{__all__}/"
# Default configuration values
_conf_slpkg = {
@@ -138,8 +138,8 @@ class MetaData:
# read value from configuration file
repositories = []
for files in ["slpkg.conf", "repositories.conf"]:
- if os.path.isfile("%s%s" % (conf_path, files)):
- f = open("%s%s" % (conf_path, files), "r")
+ if os.path.isfile(f"{conf_path}{files}"):
+ f = open(f"{conf_path}{files}", "r")
conf = f.read()
f.close()
for line in conf.splitlines():
@@ -217,8 +217,8 @@ class MetaData:
"ENDC": ""
}
- CHECKSUMS_link = ("https://gitlab.com/{0}/{1}/raw/"
- "master/CHECKSUMS.md5".format(__author__, __all__))
+ CHECKSUMS_link = (f"https://gitlab.com/{__author__}/{__all__}/raw/"
+ "master/CHECKSUMS.md5")
# file spacer
sp = "-"
diff --git a/slpkg/arguments.py b/slpkg/arguments.py
index c88907bf..75e972fd 100644
--- a/slpkg/arguments.py
+++ b/slpkg/arguments.py
@@ -30,8 +30,7 @@ from slpkg.slack.slack_version import slack_ver
def header():
"""help header message"""
- print("\nslpkg - version {0} | Slackware release: {1} - {2}\n".format(
- _meta_.__version__, _meta_.slack_rel, slack_ver()))
+ print(f"\nslpkg - version {_meta_.__version__} | Slackware release: {_meta_.slack_rel} - {slack_ver()}\n")
def options():
@@ -220,11 +219,11 @@ def usage(repo):
all_repos = RepoList().all_repos.keys()
del RepoList().all_repos
if repo in all_repos:
- error_repo = ("slpkg: Error: Repository '{0}' is not activated"
- "\n".format(repo))
+ error_repo = (f"slpkg: Error: Repository '{repo}' is not activated"
+ "\n")
else:
- error_repo = ("slpkg: Error: Repository '{0}' does not exist"
- "\n".format(repo))
+ error_repo = (f"slpkg: Error: Repository '{repo}' does not exist"
+ "\n")
print("\n" + error_repo)
raise SystemExit(1)
print(usage.__doc__)
diff --git a/slpkg/auto_pkg.py b/slpkg/auto_pkg.py
index 8aba4190..698dad61 100644
--- a/slpkg/auto_pkg.py
+++ b/slpkg/auto_pkg.py
@@ -22,8 +22,6 @@
# along with this program. If not, see .
-import sys
-
from slpkg.messages import Msg
from slpkg.__metadata__ import MetaData as _meta_
@@ -36,6 +34,10 @@ class Auto:
def __init__(self, packages):
self.packages = packages
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.cyan = _meta_.color["CYAN"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.commands = {
"i": "installpkg",
@@ -54,10 +56,7 @@ class Auto:
print("| Choose a Slackware command:")
self.msg.template(78)
for com in sorted(self.commands):
- print("| {0}{1}{2}) {3}{4}{5}".format(
- self.meta.color["RED"], com, self.meta.color["ENDC"],
- self.meta.color["GREEN"], self.commands[com],
- self.meta.color["ENDC"]))
+ print(f"| {self.red}{com}{self.endc}) {self.green}{self.commands[com]}{self.endc}")
self.msg.template(78)
try:
self.choice = input(" > ")
@@ -65,9 +64,7 @@ class Auto:
print()
raise SystemExit()
if self.choice in self.commands.keys():
- print(" \x1b[1A{0}{1}{2}\n\n".format(
- self.meta.color["CYAN"], self.commands[self.choice],
- self.meta.color["ENDC"]), end="")
+ print(f" \x1b[1A{self.cyan}{self.commands[self.choice]}{self.endc}", end="\n\n")
print(end="", flush=True)
self.execute()
diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py
index f6c6ff5b..59eb4058 100644
--- a/slpkg/blacklist.py
+++ b/slpkg/blacklist.py
@@ -33,8 +33,10 @@ class BlackList:
"""Blacklist class to add, remove or listed packages
in blacklist file."""
def __init__(self):
- self.meta = _meta_
self.quit = False
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.endc = _meta_.color["ENDC"]
self.blackfile = "/etc/slpkg/blacklist"
self.black_conf = ""
if os.path.isfile(self.blackfile):
@@ -56,8 +58,7 @@ class BlackList:
print("\nPackages in the blacklist:\n")
for black in self.get_black():
if black:
- print("{0}{1}{2}".format(self.meta.color["GREEN"], black,
- self.meta.color["ENDC"]))
+ print(f"{self.green}{black}{self.endc}")
self.quit = True
if self.quit:
print() # new line at exit
@@ -71,8 +72,7 @@ class BlackList:
with open(self.blackfile, "a") as black_conf:
for pkg in pkgs:
if pkg not in blacklist:
- print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
- self.meta.color["ENDC"]))
+ print(f"{self.green}{pkg}{self.endc}")
black_conf.write(pkg + "\n")
self.quit = True
black_conf.close()
@@ -88,8 +88,7 @@ class BlackList:
if line not in pkgs:
remove.write(line + "\n")
else:
- print("{0}{1}{2}".format(self.meta.color["RED"], line,
- self.meta.color["ENDC"]))
+ print(f"{self.red}{line}{self.endc}")
self.quit = True
remove.close()
if self.quit:
From 763d6ef50b05c145837e5bb0c68016600d461d8a Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 11 Jan 2020 00:21:19 +0100
Subject: [PATCH 04/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/auto_pkg.py | 1 -
slpkg/checks.py | 11 +++++------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/slpkg/auto_pkg.py b/slpkg/auto_pkg.py
index 698dad61..5b81daa3 100644
--- a/slpkg/auto_pkg.py
+++ b/slpkg/auto_pkg.py
@@ -33,7 +33,6 @@ class Auto:
"""
def __init__(self, packages):
self.packages = packages
- self.meta = _meta_
self.green = _meta_.color["GREEN"]
self.red = _meta_.color["RED"]
self.cyan = _meta_.color["CYAN"]
diff --git a/slpkg/checks.py b/slpkg/checks.py
index 4ec49bc9..14949e82 100644
--- a/slpkg/checks.py
+++ b/slpkg/checks.py
@@ -33,7 +33,9 @@ class Updates:
"""
def __init__(self, repo):
self.repo = repo
- self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.grey = _meta_.color["GREY"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.check = 2
self.st = ""
@@ -111,8 +113,7 @@ class Updates:
self.count_repo += 1
if self.check == 1:
self.count_news += 1
- self.st = "{0}News in ChangeLog.txt{1}".format(
- self.meta.color["GREEN"], self.meta.color["ENDC"])
+ self.st = f"{self.green}News in ChangeLog.txt{self.endc}"
elif self.check == 0:
self.st = "No changes in ChangeLog.txt"
@@ -131,6 +132,4 @@ class Updates:
cmd = "Repository is updated."
if self.count_news > 0:
cmd = "Run the command 'slpkg update'."
- print("{0}From {1} repositories need {2} updating. {3}{4}\n".format(
- self.meta.color["GREY"], self.count_repo, self.count_news, cmd,
- self.meta.color["ENDC"]))
+ print(f"{self.grey}From {self.count_repo} repositories need {self.count_news} updating. {cmd}{self.endc}", end="\n")
\ No newline at end of file
From 8e341f918c586e0b1729ae0813949c178ca53715 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 11 Jan 2020 00:26:43 +0100
Subject: [PATCH 05/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/checks.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/slpkg/checks.py b/slpkg/checks.py
index 14949e82..58ec3435 100644
--- a/slpkg/checks.py
+++ b/slpkg/checks.py
@@ -33,6 +33,7 @@ class Updates:
"""
def __init__(self, repo):
self.repo = repo
+ self.meta = _meta_
self.green = _meta_.color["GREEN"]
self.grey = _meta_.color["GREY"]
self.endc = _meta_.color["ENDC"]
@@ -120,7 +121,7 @@ class Updates:
def print_status(self, repo):
"""Print status
"""
- print(" {0}{1}{2}".format(repo, " " * (19 - len(repo)), self.st))
+ print(f" {repo}{' ' * (19 - len(repo))}{self.st}")
def summary(self):
"""Print summary
From 72a7a772509591198d07a8242f1e68b215797818 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 11 Jan 2020 14:12:21 +0100
Subject: [PATCH 06/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/config.py | 19 +++++++++----------
slpkg/desc.py | 12 ++++--------
slpkg/downloader.py | 31 ++++++++++---------------------
slpkg/graph.py | 23 +++++++++++++----------
slpkg/grep_md5.py | 4 ++--
slpkg/health.py | 28 +++++++++++++---------------
6 files changed, 51 insertions(+), 66 deletions(-)
diff --git a/slpkg/config.py b/slpkg/config.py
index e761cc2e..db9d9286 100644
--- a/slpkg/config.py
+++ b/slpkg/config.py
@@ -36,6 +36,10 @@ class Config:
def __init__(self):
self.config_file = "/etc/slpkg/slpkg.conf"
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.cyan = _meta_.color["CYAN"]
+ self.endc = _meta_.color["ENDC"]
def view(self):
"""View slpkg config file
@@ -70,25 +74,20 @@ class Config:
read_conf = Utils().read_file(self.config_file)
for line in read_conf.splitlines():
if not line.startswith("#") and line.split("=")[0] in conf_args:
- print("{0}".format(line))
+ print(line)
else:
- print("{0}{1}{2}".format(self.meta.color["CYAN"], line,
- self.meta.color["ENDC"]))
- print() # new line at end
+ print(f"{self.cyan}{line}{self.endc}", end="\n")
def edit(self):
"""Edit configuration file
"""
- subprocess.call("{0} {1}".format(self.meta.editor,
- self.config_file), shell=True)
+ subprocess.call(f"{self.meta.editor} {self.config_file}", shell=True)
def reset(self):
"""Reset slpkg.conf file with default values
"""
shutil.copy2(self.config_file + ".orig", self.config_file)
if filecmp.cmp(self.config_file + ".orig", self.config_file):
- print("{0}The reset was done{1}".format(
- self.meta.color["GREEN"], self.meta.color["ENDC"]))
+ print(f"{self.green}The reset was done{self.endc}")
else:
- print("{0}Reset failed{1}".format(self.meta.color["RED"],
- self.meta.color["ENDC"]))
+ print(f"{self.red}Reset failed{self.endc}")
diff --git a/slpkg/desc.py b/slpkg/desc.py
index f555915b..8ec8aa9c 100644
--- a/slpkg/desc.py
+++ b/slpkg/desc.py
@@ -38,20 +38,17 @@ class PkgDesc:
self.paint = paint
self.meta = _meta_
self.msg = Msg()
- self.COLOR = ""
self.lib = ""
- color_text = {
+ self.color = {
"red": self.meta.color["RED"],
"green": self.meta.color["GREEN"],
"yellow": self.meta.color["YELLOW"],
"cyan": self.meta.color["CYAN"],
"grey": self.meta.color["GREY"],
"": ""
- }
- self.COLOR = color_text[self.paint]
+ }[self.paint]
if self.repo in self.meta.repositories and self.repo != "sbo":
- self.lib = self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(
- self.repo)
+ self.lib = f"{self.meta.lib_path}{self.repo}_repo/PACKAGES.TXT"
def view(self):
"""Print package description by repository
@@ -69,8 +66,7 @@ class PkgDesc:
if count == 11:
break
if description:
- print("{0}{1}{2}".format(self.COLOR, description,
- self.meta.color["ENDC"]))
+ print(f"{self.color}{description}{self.meta.color['ENDC']}")
else:
self.msg.pkg_not_found("", self.name, "No matching", "\n")
raise SystemExit(1)
diff --git a/slpkg/downloader.py b/slpkg/downloader.py
index d93cd3d1..6c5efb49 100644
--- a/slpkg/downloader.py
+++ b/slpkg/downloader.py
@@ -42,6 +42,9 @@ class Download:
self.repo = repo
self.file_name = ""
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.dir_prefix = ""
self.downder = self.meta.downder
@@ -61,24 +64,13 @@ class Download:
self._make_tarfile(self.file_name, source_dir)
self._check_certificate()
- print("\n[{0}/{1}][ {2}Download{3} ] --> {4}\n".format(
- dwn_count, len(self.url), self.meta.color["GREEN"],
- self.meta.color["ENDC"],
- self.file_name))
+ print(f"\n[{dwn_count}/{len(self.url)}][ {self.green}Download{self.endc} ] --> {self.file_name}\n")
if self.downder in ["wget"]:
- subprocess.call("{0} {1} {2}{3} {4}".format(
- self.downder, self.downder_options,
- self.dir_prefix, self.path, dwn),
- shell=True)
+ subprocess.call(f"{self.downder} {self.downder_options} {self.dir_prefix}{self.path} {dwn}", shell=True)
if self.downder in ["aria2c"]:
- subprocess.call("{0} {1} {2}{3} {4}".format(
- self.downder, self.downder_options,
- self.dir_prefix, self.path[:-1], dwn),
- shell=True)
+ subprocess.call(f"{self.downder} {self.downder_options} {self.dir_prefix}{self.path[:-1]} {dwn}", shell=True)
elif self.downder in ["curl", "http"]:
- subprocess.call("{0} {1} {2}{3} {4}".format(
- self.downder, self.downder_options,
- self.path, self.file_name, dwn), shell=True)
+ subprocess.call(f"{self.downder} {self.downder_options} {self.path}{self.file_name} {dwn}", shell=True)
self._check_if_downloaded()
dwn_count += 1
@@ -102,9 +94,7 @@ class Download:
if not os.path.isfile(self.path + self.file_name):
print()
self.msg.template(78)
- print("| Download '{0}' file [ {1}FAILED{2} ]".format(
- self.file_name, self.meta.color["RED"],
- self.meta.color["ENDC"]))
+ print(f"| Download '{self.file_name}' file [ {self.red}FAILED{self.endc} ]")
self.msg.template(78)
print()
if not self.msg.answer() in ["y", "Y"]:
@@ -118,10 +108,9 @@ class Download:
certificate = (' --no-check-certificate --header="Cookie: '
'oraclelicense=accept-securebackup-cookie"')
self.msg.template(78)
- print("| '{0}' need to go ahead downloading".format(
- certificate[:23].strip()))
+ print(f"| '{certificate[:23].strip()}' need to go ahead downloading")
self.msg.template(78)
print()
self.downder_options += certificate
if not self.msg.answer() in ["y", "Y"]:
- raise SystemExit()
+ raise SystemExit()
\ No newline at end of file
diff --git a/slpkg/graph.py b/slpkg/graph.py
index 561ddfd0..aa3b2606 100644
--- a/slpkg/graph.py
+++ b/slpkg/graph.py
@@ -26,6 +26,12 @@ import os
import subprocess
+# class ImportErrorGraphEasy(Exception):
+# def __init__(self, GraphEasyImportError):
+# Exception.__init__(self, "graph-easy required")
+# self.GraphEasyImportError = GraphEasyImportError
+
+
class Graph:
"""Drawing dependencies diagram
"""
@@ -46,13 +52,10 @@ class Graph:
try:
import pygraphviz as pgv
except ImportError:
- graph_easy, comma = "", ""
- if (self.image == "ascii" and
- not os.path.isfile("/usr/bin/graph-easy")):
- comma = ","
- graph_easy = " graph-easy"
- print("Require 'pygraphviz{0}{1}': Install with 'slpkg -s sbo "
- "pygraphviz{1}'".format(comma, graph_easy))
+ if self.image == "ascii" and not os.path.isfile("/usr/bin/graph-easy"):
+ print("Require 'grap_easy': Install with 'slpkg -s sbo graph-easy'")
+ else:
+ print("Require 'pygraphviz: Install with 'slpkg -s sbo pygraphviz'")
raise SystemExit()
if self.image != "ascii":
self.check_file()
@@ -91,12 +94,12 @@ class Graph:
"graph-easy'")
self.remove_dot()
raise SystemExit()
- subprocess.call("graph-easy {0}.dot".format(self.image), shell=True)
+ subprocess.call(f"graph-easy {self.image}.dot", shell=True)
self.remove_dot()
raise SystemExit()
def remove_dot(self):
"""Remove .dot files
"""
- if os.path.isfile("{0}.dot".format(self.image)):
- os.remove("{0}.dot".format(self.image))
+ if os.path.isfile(f"{self.image}.dot"):
+ os.remove(f"{self.image}.dot")
\ No newline at end of file
diff --git a/slpkg/grep_md5.py b/slpkg/grep_md5.py
index 6168dd8b..7ce9563a 100644
--- a/slpkg/grep_md5.py
+++ b/slpkg/grep_md5.py
@@ -39,11 +39,11 @@ def pkg_checksum(binary, repo):
elif repo == "slpkg":
CHECKSUMS_md5 = URL(_meta_.CHECKSUMS_link).reading()
else:
- lib = "{0}{1}_repo/CHECKSUMS.md5".format(_meta_.lib_path, repo)
+ lib = f"{_meta_.lib_path}{repo}_repo/CHECKSUMS.md5"
f = open(lib, "r")
CHECKSUMS_md5 = f.read()
f.close()
for line in CHECKSUMS_md5.splitlines():
- if line.endswith("/{0}".format(binary)):
+ if line.endswith(f"/{binary}"):
md5 = line.split()[0]
return md5
diff --git a/slpkg/health.py b/slpkg/health.py
index 2fad4187..e067fb97 100644
--- a/slpkg/health.py
+++ b/slpkg/health.py
@@ -36,6 +36,10 @@ class PackageHealth:
def __init__(self, mode):
self.mode = mode
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.yellow = _meta_.color["YELLOW"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.pkg_path = _meta_.pkg_path
self.installed = []
@@ -56,9 +60,7 @@ class PackageHealth:
"/incoming/" not in line):
if not os.path.isfile(r"/" + line):
self.cn += 1
- print("Not installed: {0}/{1}{2} --> {3}".format(
- self.meta.color["RED"], line, self.meta.color["ENDC"],
- pkg))
+ print(f"Not installed: {self.red}/{line}{self.endc} --> {pkg}")
elif not self.mode:
print(line)
except IOError:
@@ -76,7 +78,7 @@ class PackageHealth:
with open(self.pkg_path + pkg, "r") as fopen:
for line in fopen:
if "\0" in line:
- print("Null: {0}").format(line)
+ print(f"Null: {line}")
break
self.cf += 1 # count all files
self.lf += 1 # count each package files
@@ -90,18 +92,14 @@ class PackageHealth:
print()
per = int(round((float(self.cf) / (self.cf + self.cn)) * 100))
if per > 90:
- color = self.meta.color["GREEN"]
+ color = self.green
elif per < 90 and per > 60:
- color = self.meta.color["YELLOW"]
+ color = self.yellow
elif per < 60:
- color = self.meta.color["RED"]
- health = "{0}{1}%{2}".format(color, str(per), self.meta.color["ENDC"])
+ color = self.red
+ health = f"{color}{str(per)}%{self.endc}"
self.msg.template(78)
- print("| {0}{1}{2}{3}{4}".format(
- "Total files", " " * 7, "Not installed", " " * 40, "Health"))
- self.msg.template(78)
- print("| {0}{1}{2}{3}{4:>4}".format(
- self.cf, " " * (18-len(str(self.cf))),
- self.cn, " " * (55-len(str(self.cn))),
- health))
+ print(f"| Total files{' ' * 7}Not installed{' ' * 40}Health")
self.msg.template(78)
+ print(f"| {self.cf}{' ' * (18-len(str(self.cf)))}{self.cn}{' ' * (55-len(str(self.cn)))}{health:>4}")
+ self.msg.template(78)
\ No newline at end of file
From c7f550d343b79d26ba5eef754b003f81a7160321 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 13 Jan 2020 14:35:05 +0100
Subject: [PATCH 07/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/init.py | 159 ++++++++++++++++++++++----------------------------
1 file changed, 69 insertions(+), 90 deletions(-)
diff --git a/slpkg/init.py b/slpkg/init.py
index 9ae00f93..2984d3a0 100644
--- a/slpkg/init.py
+++ b/slpkg/init.py
@@ -73,7 +73,7 @@ class Initialization:
"""
repo = Repo().custom_repository()[name]
log = self.log_path + name + "/"
- lib = self.lib_path + "{0}_repo/".format(name)
+ lib = self.lib_path + f"{name}_repo/"
repo_name = log[:-1].split("/")[-1]
lib_file = "PACKAGES.TXT"
# lst_file = ""
@@ -83,10 +83,10 @@ class Initialization:
os.mkdir(log)
if not os.path.exists(lib):
os.mkdir(lib)
- PACKAGES_TXT = "{0}{1}".format(repo, lib_file)
+ PACKAGES_TXT = f"{name}{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}".format(repo, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -161,10 +161,10 @@ class Initialization:
os.mkdir(log)
if not os.path.exists(lib):
os.mkdir(lib)
- SLACKBUILDS_TXT = "{0}{1}/{2}".format(repo, slack_ver(), lib_file)
+ SLACKBUILDS_TXT = f"{repo}{slack_ver()}/{lib_file}"
FILELIST_TXT = ""
CHECKSUMS_MD5 = ""
- ChangeLog_txt = "{0}{1}/{2}".format(repo, slack_ver(), log_file)
+ ChangeLog_txt = f"{repo}{slack_ver()}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, SLACKBUILDS_TXT, repo_name)
@@ -187,10 +187,10 @@ class Initialization:
os.mkdir(log)
if not os.path.exists(lib):
os.mkdir(lib)
- PACKAGES_TXT = "{0}{1}/{2}".format(repo, slack_ver(), lib_file)
+ PACKAGES_TXT = f"{repo}{slack_ver()}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/{2}".format(repo, slack_ver(), md5_file)
- ChangeLog_txt = "{0}{1}/{2}".format(repo, slack_ver(), log_file)
+ CHECKSUMS_MD5 = f"{repo}{slack_ver()}/{md5_file}"
+ ChangeLog_txt = f"{repo}{slack_ver()}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -221,10 +221,10 @@ class Initialization:
ar = arch
if self.meta.slack_rel == "current":
ver = self.meta.slack_rel
- PACKAGES_TXT = "{0}/{1}/{2}/{3}".format(repo, ver, ar, lib_file)
+ PACKAGES_TXT = f"{repo}/{ver}/{ar}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}/{1}/{2}/{3}".format(repo, ver, ar, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}/{ver}/{ar}/{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -252,14 +252,11 @@ class Initialization:
os.mkdir(lib)
if arch == "x86_64":
ar = "64"
- PACKAGES_TXT = "{0}slackware{1}-{2}/{3}".format(repo, ar, slack_ver(),
- lib_file)
+ PACKAGES_TXT = f"{repo}slackware{ar}-{slack_ver()}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}slackware{1}-{2}/{3}".format(repo, ar, slack_ver(),
- md5_file)
+ CHECKSUMS_MD5 = f"{repo}slackware{ar}-{slack_ver()}/{md5_file}"
- ChangeLog_txt = "{0}slackware{1}-{2}/{3}".format(repo, ar, slack_ver(),
- log_file)
+ ChangeLog_txt = f"{repo}slackware{ar}-{slack_ver()}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -283,10 +280,10 @@ class Initialization:
os.mkdir(log)
if not os.path.exists(lib):
os.mkdir(lib)
- PACKAGES_TXT = "{0}{1}".format(repo, lib_file)
+ PACKAGES_TXT = f"{repo}{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}".format(repo, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -299,7 +296,7 @@ class Initialization:
"""Creating slackers local library
"""
ver = slack_ver()
- ar = "{0}-x86".format(ver)
+ ar = f"{ver}-x86"
arch = self.meta.arch
repo = self.def_repos_dict["slonly"]
log = self.log_path + "slonly/"
@@ -314,15 +311,15 @@ class Initialization:
if not os.path.exists(lib):
os.mkdir(lib)
if arch == "x86_64":
- ar = "{0}-x86_64".format(ver)
+ ar = f"{ver}-x86_64"
if self.meta.slack_rel == "current":
- ar = "{0}-x86".format(self.meta.slack_rel)
+ ar = f"{self.meta.slack_rel}-x86"
if self.meta.slack_rel == "current" and arch == "x86_64":
- ar = "{0}-x86_64".format(self.meta.slack_rel)
- PACKAGES_TXT = "{0}{1}/{2}".format(repo, ar, lib_file)
+ ar = f"{self.meta.slack_rel}-x86_64"
+ PACKAGES_TXT = f"{repo}{ar}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/{2}".format(repo, ar, md5_file)
- ChangeLog_txt = "{0}{1}/{2}".format(repo, ar, log_file)
+ CHECKSUMS_MD5 = f"{repo}{ar}/{md5_file}"
+ ChangeLog_txt = f"{repo}{ar}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -346,10 +343,10 @@ class Initialization:
os.mkdir(log)
if not os.path.exists(lib):
os.mkdir(lib)
- PACKAGES_TXT = "{0}{1}".format(repo, lib_file)
+ PACKAGES_TXT = f"{repo}{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}".format(repo, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -376,10 +373,10 @@ class Initialization:
os.mkdir(lib)
if self.meta.slack_rel == "current":
ver = self.meta.slack_rel
- PACKAGES_TXT = "{0}{1}/{2}".format(repo, ver, lib_file)
+ PACKAGES_TXT = f"{repo}{ver}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/{2}".format(repo, ver, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{ver}/{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -408,13 +405,10 @@ class Initialization:
if arch == "x86_64":
ar = "64"
version = self.meta.slacke_sub_repo[1:-1]
- PACKAGES_TXT = "{0}slacke{1}/slackware{2}-{3}/{4}".format(
- repo, version, ar, slack_ver(), lib_file)
+ PACKAGES_TXT = f"{repo}slacke{version}/slackware{ar}-{slack_ver()}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}slacke{1}/slackware{2}-{3}/{4}".format(
- repo, version, ar, slack_ver(), md5_file)
- ChangeLog_txt = "{0}slacke{1}/slackware{2}-{3}/{4}".format(
- repo, version, ar, slack_ver(), log_file)
+ CHECKSUMS_MD5 = f"{repo}slacke{version}/slackware{ar}-{slack_ver()}/{md5_file}"
+ ChangeLog_txt = f"{repo}slacke{version}/slackware{ar}-{slack_ver()}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -442,10 +436,10 @@ class Initialization:
os.mkdir(lib)
if arch == "x86_64":
ar = "x86_64"
- PACKAGES_TXT = "{0}{1}/{2}/{3}".format(repo, ar, slack_ver(), lib_file)
+ PACKAGES_TXT = f"{repo}{ar}/{slack_ver()}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/{2}/{3}".format(repo, ar, slack_ver(), md5_file)
- ChangeLog_txt = "{0}{1}/{2}/{3}".format(repo, ar, slack_ver(), log_file)
+ CHECKSUMS_MD5 = f"{repo}{ar}/{slack_ver()}/{md5_file}"
+ ChangeLog_txt = f"{repo}{ar}/{slack_ver()}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -473,10 +467,10 @@ class Initialization:
os.mkdir(lib)
if arch == "x86_64":
ar = "x86_64"
- PACKAGES_TXT = "{0}{1}/current/{2}".format(repo, ar, lib_file)
+ PACKAGES_TXT = f"{repo}{ar}/current/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/current/{2}".format(repo, ar, md5_file)
- ChangeLog_txt = "{0}{1}/current/{2}".format(repo, ar, log_file)
+ CHECKSUMS_MD5 = f"{repo}{ar}/current/{md5_file}"
+ ChangeLog_txt = f"{repo}{ar}/current/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -500,10 +494,10 @@ class Initialization:
os.mkdir(log)
if not os.path.exists(lib):
os.mkdir(lib)
- PACKAGES_TXT = "{0}{1}".format(repo, lib_file)
+ PACKAGES_TXT = f"{repo}{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}".format(repo, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -535,12 +529,10 @@ class Initialization:
version = self.meta.msb_sub_repo[1:-1]
if self.meta.slack_rel == "current":
ver_slack = self.meta.slack_rel
- PACKAGES_TXT = "{0}{1}/{2}/{3}/{4}".format(
- repo, ver_slack, version, ar, lib_file)
+ PACKAGES_TXT = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/{2}/{3}/{4}".format(
- repo, ver_slack, version, ar, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -571,12 +563,10 @@ class Initialization:
ar = "x86_64"
if self.meta.slack_rel == "current":
ver_slack = self.meta.slack_rel
- PACKAGES_TXT = "{0}{1}/{2}/{3}".format(
- repo, ver_slack, ar, lib_file)
+ PACKAGES_TXT = f"{repo}{ver_slack}/{ar}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}/{2}/{3}".format(
- repo, ver_slack, ar, md5_file)
- ChangeLog_txt = "{0}{1}".format(repo, log_file)
+ CHECKSUMS_MD5 = f"{repo}{ver_slack}/{ar}/{md5_file}"
+ ChangeLog_txt = f"{repo}{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -605,14 +595,10 @@ class Initialization:
os.mkdir(lib)
if arch == "x86_64":
ar = "64"
- PACKAGES_TXT = "{0}{1}{2}-{3}/{4}".format(repo, nickname, ar,
- slack_ver(), lib_file)
+ PACKAGES_TXT = f"{repo}{nickname}{ar}-{slack_ver()}/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}{2}-{3}/{4}".format(repo, nickname, ar,
- slack_ver(), md5_file)
-
- ChangeLog_txt = "{0}{1}{2}-{3}/{4}".format(repo, nickname, ar,
- slack_ver(), log_file)
+ CHECKSUMS_MD5 = f"{repo}{nickname}{ar}-{slack_ver()}/{md5_file}"
+ ChangeLog_txt = f"{repo}{nickname}{ar}-{slack_ver()}/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -641,13 +627,10 @@ class Initialization:
if arch == "x86_64":
ar = "64"
version = self.meta.mles_sub_repo[1:-1]
- PACKAGES_TXT = "{0}{1}-{2}-{3}bit/{4}".format(
- repo, version, slack_ver(), ar, lib_file)
+ PACKAGES_TXT = f"{repo}{version}-{slack_ver()}-{ar}bit/{lib_file}"
FILELIST_TXT = ""
- CHECKSUMS_MD5 = "{0}{1}-{2}-{3}bit/{4}".format(
- repo, version, slack_ver(), ar, md5_file)
- ChangeLog_txt = "{0}{1}-{2}-{3}bit/{4}".format(
- repo, version, slack_ver(), ar, log_file)
+ CHECKSUMS_MD5 = f"{repo}{version}-{slack_ver()}-{ar}bit/{md5_file}"
+ ChangeLog_txt = f"{repo}{version}-{slack_ver()}-{ar}bit/{log_file}"
if self.check:
return self.checks_logs(log, ChangeLog_txt)
self.down(lib, PACKAGES_TXT, repo_name)
@@ -705,7 +688,7 @@ class Initialization:
code = "utf-8"
with open(path + outfile, 'w', encoding=code) as out_f:
for f in infiles:
- if os.path.isfile("{0}{1}".format(path, f)):
+ if os.path.isfile("f{path}{f}"):
# checking the encoding before read the file
code = Utils.check_encoding(path, f)
with open(path + f, "r", encoding=code) as in_f:
@@ -737,14 +720,12 @@ class Initialization:
if only:
repositories = only
for repo in repositories:
- changelogs = "{0}{1}{2}".format(self.log_path, repo,
- "/ChangeLog.txt")
+ changelogs = f"{self.log_path}{repo}/ChangeLog.txt"
if os.path.isfile(changelogs):
os.remove(changelogs)
- if os.path.isdir(self.lib_path + "{0}_repo/".format(repo)):
- for f in (os.listdir(self.lib_path + "{0}_repo/".format(
- repo))):
- files = "{0}{1}_repo/{2}".format(self.lib_path, repo, f)
+ if os.path.isdir(self.lib_path + f"{repo}_repo/"):
+ for f in (os.listdir(self.lib_path + f"{repo}_repo/")):
+ files = f"{self.lib_path}{repo}_repo/{f}"
if os.path.isfile(files):
os.remove(files)
elif os.path.isdir(files):
@@ -757,10 +738,12 @@ class Update:
def __init__(self):
self.initialization = globals()['Initialization'](False)
self.meta = _meta_
- self.done = "{0}Done{1}\n".format(self.meta.color["GREY"],
- self.meta.color["ENDC"])
- self.error = "{0}Error{1}\n".format(self.meta.color["RED"],
- self.meta.color["ENDC"])
+ self.grey = _meta_.color["GREY"]
+ self.red = _meta_.color["RED"]
+ self.cyan = _meta_.color["CYAN"]
+ self.endc = _meta_.color["ENDC"]
+ self.done = f"{self.grey}Done{self.endc}\n"
+ self.error = f"{self.red}Error{self.endc}\n"
def repository(self, only):
"""Update repositories lists
@@ -773,11 +756,7 @@ class Update:
for repo in enabled:
if check_for_local_repos(repo) is True:
continue
- print("{0}Check repository [{1}{2}{3}] ... "
- "{4}".format(self.meta.color["GREY"],
- self.meta.color["CYAN"], repo,
- self.meta.color["GREY"],
- self.meta.color["ENDC"]), end="", flush=True)
+ print(f"{self.grey}Check repository [{self.cyan}{repo}{self.grey}] ... {self.endc}", end="", flush=True)
if repo in default:
update = getattr(self.initialization, repo)
update()
@@ -800,8 +779,8 @@ def check_exists_repositories(repo):
if check_for_local_repos(repo) is True:
pkg_list = "PACKAGES.TXT"
return ""
- if not os.path.isfile("{0}{1}{2}".format(
- _meta_.lib_path, repo, "_repo/{0}".format(pkg_list))):
+ if not os.path.isfile(f"{_meta_.lib_path}{repo}_repo/{pkg_list}"
+ # .format(_meta_.lib_path, repo, "_repo/{0}".format(pkg_list))):
return repo
return ""
From 7f3c597488a55ae89057fd387fd48255cacd3fcf Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 13 Jan 2020 15:39:26 +0100
Subject: [PATCH 08/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/init.py | 4 ++--
slpkg/load.py | 10 ++++----
slpkg/main.py | 3 +--
slpkg/messages.py | 58 +++++++++++++++++++--------------------------
slpkg/new_config.py | 33 +++++++++++---------------
slpkg/pkg_find.py | 18 +++++---------
6 files changed, 51 insertions(+), 75 deletions(-)
diff --git a/slpkg/init.py b/slpkg/init.py
index 2984d3a0..2f0e1afa 100644
--- a/slpkg/init.py
+++ b/slpkg/init.py
@@ -779,8 +779,8 @@ def check_exists_repositories(repo):
if check_for_local_repos(repo) is True:
pkg_list = "PACKAGES.TXT"
return ""
- if not os.path.isfile(f"{_meta_.lib_path}{repo}_repo/{pkg_list}"
- # .format(_meta_.lib_path, repo, "_repo/{0}".format(pkg_list))):
+ if not os.path.isfile(f"{_meta_.lib_path}{repo}_repo/{pkg_list}"):
+ # .format(_meta_.lib_path, repo, "_repo/{0}".format(pkg_list))):
return repo
return ""
diff --git a/slpkg/load.py b/slpkg/load.py
index ee88c308..3b4b664e 100644
--- a/slpkg/load.py
+++ b/slpkg/load.py
@@ -37,14 +37,12 @@ def library(repo):
pkg_list, packages = [], ""
if repo == "sbo":
if (os.path.isfile(
- _meta_.lib_path + "{0}_repo/SLACKBUILDS.TXT".format(repo))):
- packages = Utils().read_file(_meta_.lib_path + "{0}_repo/"
- "SLACKBUILDS.TXT".format(repo))
+ _meta_.lib_path + f"{repo}_repo/SLACKBUILDS.TXT")):
+ packages = Utils().read_file(_meta_.lib_path + f"{repo}_repo/SLACKBUILDS.TXT")
else:
if (os.path.isfile(
- _meta_.lib_path + "{0}_repo/PACKAGES.TXT".format(repo))):
- packages = Utils().read_file(_meta_.lib_path + "{0}_repo/"
- "PACKAGES.TXT".format(repo))
+ _meta_.lib_path + f"{repo}_repo/PACKAGES.TXT")):
+ packages = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT")
for line in packages.splitlines():
if repo == "sbo":
if line.startswith("SLACKBUILD NAME: "):
diff --git a/slpkg/main.py b/slpkg/main.py
index f334e4f1..39285798 100644
--- a/slpkg/main.py
+++ b/slpkg/main.py
@@ -677,8 +677,7 @@ class ArgParse:
self.args.remove(arg)
break
if tag and tag not in colors:
- print("\nslpkg: Error: Available colors {0}\n".format(
- colors))
+ print(f"\nslpkg: Error: Available colors {colors}\n")
raise SystemExit()
if (len(self.args) == 3 and self.args[0] in options and
self.args[1] in self.meta.repositories and tag in colors):
diff --git a/slpkg/messages.py b/slpkg/messages.py
index 93d75bb4..de36ba3b 100644
--- a/slpkg/messages.py
+++ b/slpkg/messages.py
@@ -32,32 +32,34 @@ class Msg:
"""
def __init__(self):
self.meta = _meta_
+ self.grey = _meta_.color["GREY"]
+ self.red = _meta_.color["RED"]
+ self.cyan = _meta_.color["CYAN"]
+ self.endc = _meta_.color["ENDC"]
def pkg_not_found(self, bol, pkg, message, eol):
"""Print message when package not found
"""
- print("{0}No such package {1}: {2}{3}".format(bol, pkg, message, eol))
+ print(f"{bol}No such package {pkg}: {message}{eol}")
def pkg_found(self, prgnam):
"""Print message when package found
"""
- print("| Package {0} is already installed".format(prgnam))
+ print(f"| Package {prgnam} is already installed")
def pkg_installed(self, pkg):
"""Print message when package installed
"""
- print("| Package {0} installed".format(pkg))
+ print(f"| Package {pkg} installed")
def build_FAILED(self, prgnam):
"""Print error message if build failed
"""
self.template(78)
- print("| Some error on the package {0} [ {1}FAILED{2} ]".format(
- prgnam, self.meta.color["RED"], self.meta.color["ENDC"]))
+ print(f"| Some error on the package {prgnam} [ {self.red}FAILED{self.endc} ]")
self.template(78)
- print("| See the log file in '{0}/var/log/slpkg/sbo/build_logs{1}' "
- "directory or read the README file".format(
- self.meta.color["CYAN"], self.meta.color["ENDC"]))
+ print(f"| See the log file in '{self.cyan}/var/log/slpkg/sbo/build_logs{self.endc}' "
+ f"directory or read the README file")
self.template(78)
print() # new line at end
@@ -69,29 +71,22 @@ class Msg:
def checking(self):
"""Message checking
"""
- print("{0}Checking...{1} ".format(self.meta.color["GREY"],
- self.meta.color["ENDC"]), end="",
- flush=True)
+ print(f"{self.grey}Checking...{self.endc} ", end="", flush=True)
def reading(self):
"""Message reading
"""
- print("{0}Reading package lists...{1} ".format(
- self.meta.color["GREY"], self.meta.color["ENDC"]), end="",
- flush=True)
+ print(f"{self.grey}Reading package lists...{self.endc} ", end="", flush=True)
def resolving(self):
"""Message resolving
"""
- print("{0}Resolving dependencies...{1} ".format(
- self.meta.color["GREY"], self.meta.color["ENDC"]), end="",
- flush=True)
+ print(f"{self.grey}Resolving dependencies...{self.endc} ", end="", flush=True)
def done(self):
"""Message done
"""
- print("\b{0}Done{1}\n".format(self.meta.color["GREY"],
- self.meta.color["ENDC"]), end="")
+ print(f"\b{self.grey}Done{self.endc}\n", end="")
def pkg(self, count):
"""Print singular plural
@@ -135,12 +130,11 @@ class Msg:
"""
print()
self.template(78)
- print("| {0}{1}*** WARNING ***{2}").format(
- " " * 27, self.meta.color["RED"], self.meta.color["ENDC"])
+ print(f"| {' ' * 27}{self.red}*** WARNING ***{self.endc}")
self.template(78)
- print("| Before proceed with the package '{0}' will you must read\n"
- "| the README file. You can use the command "
- "'slpkg -n {1}'").format(pkg, pkg)
+ print(f"| Before proceed with the package '{pkg}' will you must read\n"
+ f"| the README file. You can use the command "
+ f"'slpkg -n {pkg}'")
self.template(78)
print()
@@ -149,23 +143,19 @@ class Msg:
and upgraded
"""
self.template(78)
- print("| Total {0} {1} installed and {2} {3} upgraded".format(
- len(install), self.pkg(len(install)),
- len(upgrade), self.pkg(len(upgrade))))
+ print(f"| Total {len(install)} {self.pkg(len(install))} installed and "
+ f"{len(upgrade)} {self.pkg(len(upgrade))} upgraded")
self.template(78)
for installed, upgraded in itertools.zip_longest(install, upgrade):
if upgraded:
- print("| Package {0} upgraded successfully".format(upgraded))
+ print(f"| Package {upgraded} upgraded successfully")
if installed:
- print("| Package {0} installed successfully".format(installed))
+ print(f"| Package {installed} installed successfully")
self.template(78)
print()
def matching(self, packages):
"""Message for matching packages
"""
- print("\nNot found package with the name [ {0}{1}{2} ]. "
- "Matching packages:\nNOTE: Not dependenc"
- "ies are resolved\n".format(self.meta.color["CYAN"],
- "".join(packages),
- self.meta.color["ENDC"]))
+ print(f"\nNot found package with the name [ {self.cyan}{''.join(packages)}{self.endc} ]. "
+ f"Matching packages:\nNOTE: Not dependencies are resolved\n")
\ No newline at end of file
diff --git a/slpkg/new_config.py b/slpkg/new_config.py
index 610c8a5e..ece01a3a 100644
--- a/slpkg/new_config.py
+++ b/slpkg/new_config.py
@@ -51,11 +51,10 @@ class NewConfig:
"""
self.find_new()
for n in self.news:
- print("{0}".format(n))
+ print(f"{n}")
print()
self.msg.template(78)
- print("| Installed {0} new configuration files:".format(
- len(self.news)))
+ print(f"| Installed {len(self.news)} new configuration files:")
self.msg.template(78)
self.choices()
@@ -76,16 +75,12 @@ class NewConfig:
def choices(self):
"""Menu options for new configuration files
"""
- print("| {0}K{1}{2}eep the old and .new files, no changes".format(
- self.red, self.endc, self.br))
- print("| {0}O{1}{2}verwrite all old configuration files with new "
- "ones".format(self.red, self.endc, self.br))
+ print(f"| {self.red}K{self.endc}{self.br}eep the old and .new files, no changes")
+ print(f"| {self.red}O{self.endc}{self.br}verwrite all old configuration files with new ones")
print("| The old files will be saved with suffix .old")
- print("| {0}R{1}{2}emove all .new files".format(
- self.red, self.endc, self.br))
- print("| {0}P{1}{2}rompt K, O, R, D, M option for each single "
- "file".format(self.red, self.endc, self.br))
- print("| {0}Q{1}{2}uit from menu".format(self.red, self.endc, self.br))
+ print(f"| {self.red}R{self.endc}{self.br}emove all .new files")
+ print(f"| {self.red}P{self.endc}{self.br}rompt K, O, R, D, M option for each single file")
+ print(f"| {self.red}Q{self.endc}{self.br}uit from menu")
self.msg.template(78)
try:
choose = input("\nWhat would you like to do [K/O/R/P/Q]? ")
@@ -141,7 +136,7 @@ class NewConfig:
"""Choose what do to file by file
"""
print()
- prompt_ask = input("{0} [K/O/R/D/M/Q]? ".format(n))
+ prompt_ask = input(f"{n} [K/O/R/D/M/Q]? ")
print()
if prompt_ask in ("K", "k"):
self.keep()
@@ -163,7 +158,7 @@ class NewConfig:
if os.path.isfile(n):
os.remove(n)
if not os.path.isfile(n):
- print("File '{0}' removed".format(n))
+ print(f"File '{n}' removed")
def _overwrite(self, n):
"""Overwrite old file with new and keep file with suffix .old
@@ -195,15 +190,15 @@ class NewConfig:
c += 1
if s1 != s2:
break
- print("@@ -{0},{1} +{2},{3} @@\n".format(ln, c, ln, c))
+ print(f"@@ -{ln},{c} +{ln},{c} @@\n")
for line in lines[-3:]:
- print("{0}".format(line))
+ print(f"{line}")
if a is None:
a = ""
- print("{0}{1}{2}{3}".format(self.red, "-", self.endc, a))
+ print(f"{self.red}-{self.endc}{a}")
if b is None:
b = ""
- print("{0}{1}{2}{3}".format(self.green, "+", self.endc, b))
+ print(f"{self.green}+{self.endc}{b}")
lines = []
c = 0
else:
@@ -230,4 +225,4 @@ class NewConfig:
n.split("/")[-1], n[:-4].split("/")[-1]))
def quit(self):
- raise SystemExit()
+ raise SystemExit()
\ No newline at end of file
diff --git a/slpkg/pkg_find.py b/slpkg/pkg_find.py
index 97d59921..bbe9c35e 100644
--- a/slpkg/pkg_find.py
+++ b/slpkg/pkg_find.py
@@ -45,11 +45,9 @@ class FindFromRepos:
def find(self, pkg, flag):
"""Start to find packages and print
"""
- print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
- self.cyan, ", ".join(pkg), self.endc))
+ print(f"\nPackages with name matching [ {self.cyan}{', '.join(pkg)}{self.endc} ]\n")
Msg().template(78)
- print("| {0} {1}{2}{3}".format("Repository", "Package", " " * 54,
- "Size"))
+ print(f"| Repository Package {' ' * 54}Size")
Msg().template(78)
for repo in _meta_.repositories:
PACKAGES_TXT = PackageManager(pkg).list_lib(repo)
@@ -69,16 +67,12 @@ class FindFromRepos:
self.cache = repo
self.count_pkg += 1
ver = self.sbo_version(repo, find)
- print(" {0}{1}{2}{3}{4} {5}{6:>11}".format(
- self.cyan, repo, self.endc,
- " " * (12 - len(repo)),
- find + ver, " " * (53 - len(find + ver)),
- size))
+ print(f" {self.cyan}{repo}{self.endc}{' ' * (12 - len(repo))}{find + ver} "
+ f"{' ' * (53 -len(find + ver))}{size:>11}")
print("\nFound summary")
print("=" * 79)
- print("{0}Total found {1} packages in {2} repositories."
- "{3}\n".format(self.grey, self.count_pkg,
- self.count_repo, self.endc))
+ print(f"{self.grey}Total found {self.count_pkg} packages in "
+ f"{self.count_repo} repositories.{self.endc}\n")
def sbo_version(self, repo, find):
"""
From dccf29b7d39ac297739df03977e531280b316ec3 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 13 Jan 2020 16:02:08 +0100
Subject: [PATCH 09/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/repoenable.py | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/slpkg/repoenable.py b/slpkg/repoenable.py
index 19aeb895..15ce8016 100644
--- a/slpkg/repoenable.py
+++ b/slpkg/repoenable.py
@@ -36,6 +36,9 @@ class RepoEnable:
"""
def __init__(self):
self.meta = _meta_
+ self.red = _meta_.color["RED"]
+ self.grey = _meta_.color["GREY"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.tag = "[REPOSITORIES]"
self.tag_line = False
@@ -101,8 +104,7 @@ Keys: SPACE select or deselect the highlighted repositories,
"""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:
+ with open(f"{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:
@@ -130,15 +132,13 @@ Keys: SPACE select or deselect the highlighted repositories,
"""
total_enabled = ", ".join(self.selected)
if len(total_enabled) < 1:
- total_enabled = ("{0}Are you crazy? This is a package "
- "manager for packages :p{1}".format(
- self.meta.color["RED"],
- self.meta.color["ENDC"]))
+ total_enabled = (f"{self.red}Are you crazy? This is a package "
+ f"manager for packages :p{self.endc}")
self.msg.template(78)
print("| Enabled repositories:")
self.msg.template(78)
- print("| {0}".format(total_enabled))
+ print(f"| {total_enabled}")
self.msg.template(78)
- print("{0}Total {1}/{2} repositories enabled.{3}\n".format(
- self.meta.color["GREY"], len(self.selected),
- len(self.enabled + self.disabled), self.meta.color["ENDC"]))
+ print(f"{self.grey}Total {len(self.selected)}/{len(self.enabled + self.disabled)} "
+ f"repositories enabled.{self.endc}\n")
+ #.format(self.meta.color["GREY"], len(self.selected), len(self.enabled + self.disabled), self.meta.color["ENDC"]))
From 40f06a0075ab69f468c45f411fc1acc6969bd5b3 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 13 Jan 2020 16:08:37 +0100
Subject: [PATCH 10/40] Switch to python3-pythondialog
Signed-off-by: Dimitris Zlatanidis
---
EXAMPLES.md | 6 +++---
man/slpkg.8 | 2 +-
man/slpkg.html | 2 +-
slpkg/main.py | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/EXAMPLES.md b/EXAMPLES.md
index d2d9be86..14384460 100644
--- a/EXAMPLES.md
+++ b/EXAMPLES.md
@@ -5,7 +5,7 @@
First you need to run '`slpkg update`' to synchronize the lists of packages, also every time you add
a new repository. To add or remove repositories must edit the file '`/etc/slpkg/repositories.conf`'
-or run '`slpkg repo-enable`' (python2-pythondialog required). Add custom repositories with the
+or run '`slpkg repo-enable`' (python3-pythondialog required). Add custom repositories with the
command '`slpkg add-repo `' and after run '`slpkg update`' to update package
list. View list of repositories with the command `slpkg repo-list` or get repository information
with the command '`slpkg repo-info `'.
@@ -74,7 +74,7 @@ remove packages from your system events. Notable mention you must give in the co
after editing configuration file '`/etc/slpkg/slpkg.conf`' (default is disable) or add additional
option '`--deps`'. Also you can check if the packages they are used as dependency with additional
option '`--check-deps`'. Option '`--tag`' allow to remove packages with by TAG. Optional you can use
-the dialog utility with the additional option '`--checklist`' (require python2-pythondialog). Rmove
+the dialog utility with the additional option '`--checklist`' (require python3-pythondialog). Rmove
third-party packages with the option '`--third-party`'.
The command '`slpkg -d `' is useful to print the entire contents of a package.
@@ -85,7 +85,7 @@ Some examples you will see below.
##### Slpkg Examples
Enable or disable default repositories, edit '`/etc/slpkg/repositories.conf`' file or with the command.
-(require pythondialog, install with '`slpkg -s sbo python2-pythondialog`'):
+(require pythondialog, install with '`slpkg -s sbo python3-pythondialog`'):
```
$ slpkg repo-enable
diff --git a/man/slpkg.8 b/man/slpkg.8
index 42db813e..3c449f69 100644
--- a/man/slpkg.8
+++ b/man/slpkg.8
@@ -188,7 +188,7 @@ Additional options:
.PP
\fB--skip=[packages...]\fP : Skip packages from upgrade separate by comma like "# slpkg -c sbo --skip=jdk,pep8,pip" (See REGEX).
.PP
-\fB--checklist\fP : Enable dialog utility and checklist option. (Require python2-pythondialog)
+\fB--checklist\fP : Enable dialog utility and checklist option. (Require python3-pythondialog)
.SS -s, --sync, synchronize packages, download, build and install package with all dependencies
\fBslpkg\fP \fB-s\fP <\fIrepository\fP> <\fInames of packages\fP>, \fB--resolve-off\fP, \fB--case-ins\fP, \fB--patches\fP
diff --git a/man/slpkg.html b/man/slpkg.html
index 15571370..8b76d2fa 100644
--- a/man/slpkg.html
+++ b/man/slpkg.html
@@ -346,7 +346,7 @@ slpkg -c sbo --skip=jdk,pep8,pip" (See REGEX).
--checklist
: Enable dialog utility and checklist option. (Require
-python2-pythondialog)
+python3-pythondialog)
-s, --sync,
synchronize packages, download, build and install package
diff --git a/slpkg/main.py b/slpkg/main.py
index 39285798..aa183a2f 100644
--- a/slpkg/main.py
+++ b/slpkg/main.py
@@ -778,7 +778,7 @@ class ArgParse:
from dialog import Dialog
except ImportError:
print("Require 'pythondialog': Install with 'slpkg -s sbo "
- "python2-pythondialog'")
+ "python3-pythondialog'")
raise SystemExit()
From 9edec1f99978dc84c35efaa6dcc87cb198db8483 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 13 Jan 2020 18:57:47 +0100
Subject: [PATCH 11/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/repoenable.py | 3 +-
slpkg/repoinfo.py | 12 +++---
slpkg/sbo/autobuild.py | 3 +-
slpkg/sbo/build_num.py | 6 +--
slpkg/sbo/check.py | 4 +-
slpkg/sbo/greps.py | 4 +-
slpkg/sbo/network.py | 75 +++++++++++++-------------------------
slpkg/toolbar.py | 3 +-
slpkg/tracking.py | 20 +++-------
slpkg/upgrade_checklist.py | 6 +--
slpkg/url_read.py | 6 +--
11 files changed, 52 insertions(+), 90 deletions(-)
diff --git a/slpkg/repoenable.py b/slpkg/repoenable.py
index 15ce8016..7ad6b9d6 100644
--- a/slpkg/repoenable.py
+++ b/slpkg/repoenable.py
@@ -140,5 +140,4 @@ Keys: SPACE select or deselect the highlighted repositories,
print(f"| {total_enabled}")
self.msg.template(78)
print(f"{self.grey}Total {len(self.selected)}/{len(self.enabled + self.disabled)} "
- f"repositories enabled.{self.endc}\n")
- #.format(self.meta.color["GREY"], len(self.selected), len(self.enabled + self.disabled), self.meta.color["ENDC"]))
+ f"repositories enabled.{self.endc}\n")
\ No newline at end of file
diff --git a/slpkg/repoinfo.py b/slpkg/repoinfo.py
index 8bcfc64f..43ef3ff4 100644
--- a/slpkg/repoinfo.py
+++ b/slpkg/repoinfo.py
@@ -35,6 +35,9 @@ class RepoInfo:
"""Repository information
"""
def __init__(self):
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.endc = _meta_.color["ENDC"]
self.form = {
"Last updated:": "",
"Number of packages:": "",
@@ -55,17 +58,14 @@ class RepoInfo:
"""
View repository information
"""
- status = "{0}disabled{1}".format(self.meta.color["RED"],
- self.meta.color["ENDC"])
+ status = f"{self.red}disabled{self.endc}"
self.form["Status:"] = status
self.form["Default:"] = "no"
if repo in self.meta.default_repositories:
self.form["Default:"] = "yes"
if (repo in self.meta.repositories and
- os.path.isfile(self.meta.lib_path + "{0}_repo/PACKAGES."
- "TXT".format(repo))):
- status = "{0}enabled{1}".format(self.meta.color["GREEN"],
- self.meta.color["ENDC"])
+ os.path.isfile(self.meta.lib_path + f"{repo}_repo/PACKAGES.TXT")):
+ status = f"{self.green}enabled{self.endc}"
if repo != "sbo":
data = self.repository_data(repo)
size = units(data[1], data[2])
diff --git a/slpkg/sbo/autobuild.py b/slpkg/sbo/autobuild.py
index bfb29867..858e0f44 100644
--- a/slpkg/sbo/autobuild.py
+++ b/slpkg/sbo/autobuild.py
@@ -68,6 +68,5 @@ class AutoBuild:
raise SystemExit()
for src in self.sources:
if not os.path.isfile(self.path + src):
- print("\nslpkg: Error: Source file '{0}' not found\n".format(
- src))
+ print(f"\nslpkg: Error: Source file '{src}' not found\n")
raise SystemExit()
diff --git a/slpkg/sbo/build_num.py b/slpkg/sbo/build_num.py
index 43fe7fca..2d41345f 100644
--- a/slpkg/sbo/build_num.py
+++ b/slpkg/sbo/build_num.py
@@ -40,11 +40,9 @@ class BuildNumber:
def get(self):
num = "NO_BUILD"
if self.sbo_url:
- SlackBuild = URL("{0}{1}.SlackBuild".format(
- self.sbo_url, self.pkg)).reading()
+ SlackBuild = URL(f"{self.sbo_url}{self.pkg}.SlackBuild").reading()
else:
- SlackBuild = Utils().read_file("{0}{1}/{2}.SlackBuild".format(
- self.meta.build_path, self.pkg, self.pkg))
+ SlackBuild = Utils().read_file(f"{self.meta.build_path}{self.pkg}/{self.pkg}.SlackBuild")
for line in SlackBuild.splitlines():
line = line.lstrip()
if line.startswith("BUILD="):
diff --git a/slpkg/sbo/check.py b/slpkg/sbo/check.py
index b0e39a9d..9288090c 100644
--- a/slpkg/sbo/check.py
+++ b/slpkg/sbo/check.py
@@ -47,8 +47,8 @@ def sbo_upgrade(skip, flag):
name = split_package(pkg)[0]
ver = split_package(pkg)[1]
if (name in data and name not in skip and name not in blacklist):
- sbo_package = ("{0}-{1}".format(name, SBoGrep(name).version()))
- package = ("{0}-{1}".format(name, ver))
+ sbo_package = f"{name}-{SBoGrep(name).version()}"
+ package = f"{name}-{ver}"
if parse_version(sbo_package) > parse_version(package):
upgrade_names.append(name)
Msg().done()
diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py
index 4412fb03..09dbf4c4 100644
--- a/slpkg/sbo/greps.py
+++ b/slpkg/sbo/greps.py
@@ -36,11 +36,11 @@ class SBoGrep:
self.line_name = "SLACKBUILD NAME: "
self.line_files = "SLACKBUILD FILES: "
self.line_down = "SLACKBUILD DOWNLOAD: "
- self.line_down_64 = "SLACKBUILD DOWNLOAD_{0}: ".format(arch64)
+ self.line_down_64 = f"SLACKBUILD DOWNLOAD_{arch64}: "
self.line_req = "SLACKBUILD REQUIRES: "
self.line_ver = "SLACKBUILD VERSION: "
self.line_md5 = "SLACKBUILD MD5SUM: "
- self.line_md5_64 = "SLACKBUILD MD5SUM_{0}: ".format(arch64)
+ self.line_md5_64 = f"SLACKBUILD MD5SUM_{arch64}: "
self.line_des = "SLACKBUILD SHORT DESCRIPTION: "
self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT"
self.answer = ["y", "Y"]
diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py
index 45f14ba2..40ab682b 100644
--- a/slpkg/sbo/network.py
+++ b/slpkg/sbo/network.py
@@ -94,7 +94,7 @@ class SBoNetwork:
from slackbuilds.org
"""
if self.sbo_url and self.name not in self.blacklist:
- self.prgnam = ("{0}-{1}".format(self.name, self.sbo_version))
+ self.prgnam = f"{self.name}-{self.sbo_version}"
self.view_sbo()
while True:
self.read_choice()
@@ -147,10 +147,10 @@ class SBoNetwork:
commands = {
"r": "README",
"R": "README",
- "s": "{0}.SlackBuild".format(self.name),
- "S": "{0}.SlackBuild".format(self.name),
- "f": "{0}.info".format(self.name),
- "F": "{0}.info".format(self.name),
+ "s": f"{self.name}.SlackBuild",
+ "S": f"{self.name}.SlackBuild",
+ "f": f"{self.name}.info",
+ "F": f"{self.name}.info",
"o": "doinst.sh",
"O": "doinst.sh",
"d": "download",
@@ -171,8 +171,7 @@ class SBoNetwork:
}
try:
message = " Choose an option > "
- self.choice = input("{0}{1}{2}".format(self.grey, message,
- self.endc))
+ self.choice = input(f"{self.grey}{message}{self.endc}")
except EOFError:
print()
raise SystemExit()
@@ -263,49 +262,27 @@ class SBoNetwork:
fix_sp = ""
print() # new line at start
self.msg.template(78)
- print("| {0}{1}SlackBuilds Repository{2}".format(" " * 28, self.grey,
- self.endc))
+ print(f"| {' ' * 28}{self.grey}SlackBuilds Repository{self.endc}")
self.msg.template(78)
- print("| {0} > {1} > {2}{3}{4}".format(slack_ver(),
- sbo_url.split("/")[-3].title(),
- self.cyan, self.name,
- self.endc))
+ print(f"| {slack_ver()} > {sbo_url.split('/')[-3].title()} > {self.cyan}{self.name}{self.endc}")
self.msg.template(78)
- print("| {0}Package url{1}: {2}".format(self.green, self.endc,
- sbo_url))
+ print(f"| {self.green}Package url{self.endc}: {sbo_url}")
self.msg.template(78)
- print("| {0}Description: {1}{2}".format(self.green,
- self.endc, self.sbo_desc))
- print("| {0}SlackBuild: {1}{2}".format(self.green, self.endc,
- self.sbo_dwn.split("/")[-1]))
- print("| {0}Sources: {1}{2}".format(
- self.green, self.endc,
- (", ".join([src.split("/")[-1] for src in self.source_dwn]))))
- print("| {0}Requirements: {1}{2}".format(self.yellow,
- self.endc,
- ", ".join(self.sbo_req)))
+ print(f"| {self.green}Description: {self.endc}{self.sbo_desc}")
+ print(f"| {self.green}SlackBuild: {self.endc}{self.sbo_dwn.split('/')[-1]}")
+ print(f"| {self.green}Sources: {self.endc}{', '.join([src.split('/')[-1] for src in self.source_dwn])}")
+ print(f"| {self.yellow}Requirements: {self.endc}{', '.join(self.sbo_req)}")
self.msg.template(78)
- print("| {0}R{1}{2}EADME View the README file".format(
- self.red, self.endc, br2))
- print("| {0}S{1}{2}lackBuild View the .SlackBuild "
- "file".format(self.red, self.endc, br2))
- print("| In{0}{1}f{2}{3}o{4} View the .info "
- "file".format(br1, self.red, self.endc, br2, fix_sp))
+ print(f"| {self.red}R{self.endc}{br2}EADME View the README file")
+ print(f"| {self.red}S{self.endc}{br2}lackBuild View the .SlackBuild file")
+ print(f"| In{br1}{self.red}f{self.endc}{br2}o{fix_sp} View the .info file")
if "doinst.sh" in self.sbo_files.split():
- print("| D{0}{1}o{2}{3}inst.sh{4} View the doinst.sh "
- "file".format(br1, self.red, self.endc, br2, fix_sp))
- print("| {0}D{1}{2}ownload Download this package".format(
- self.red, self.endc, br2))
- print("| {0}B{1}{2}uild Download and build".format(
- self.red, self.endc, br2))
- print("| {0}I{1}{2}nstall Download/Build/Install".format(
- self.red, self.endc, br2))
- print("| {0}C{1}{2}lear Clear screen".format(self.red,
- self.endc,
- br2))
- print("| {0}Q{1}{2}uit Quit".format(self.red,
- self.endc, br2))
-
+ print(f"| D{br1}{self.red}o{self.endc}{br2}inst.sh{fix_sp} View the doinst.sh file")
+ print(f"| {self.red}D{self.endc}{br2}ownload Download this package")
+ print(f"| {self.red}B{self.endc}{br2}uild Download and build")
+ print(f"| {self.red}I{self.endc}{br2}nstall Download/Build/Install")
+ print(f"| {self.red}C{self.endc}{br2}lear Clear screen")
+ print(f"| {self.red}Q{self.endc}{br2}uit Quit")
self.msg.template(78)
def with_checklist(self):
@@ -321,7 +298,7 @@ class SBoNetwork:
if data:
text = "Press 'spacebar' to choose SlackBuild for view"
title = " SlackBuilds.org "
- backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__)
+ backtitle = f"{_meta_.__all__} {_meta_.__version__}"
status = False
pkg = DialogUtil(data, text, title, backtitle, status).checklist()
if pkg and len(pkg) > 1:
@@ -367,8 +344,7 @@ class SBoNetwork:
if self.FAULT:
print()
self.msg.template(78)
- print("| Package {0} {1} {2} {3}".format(self.prgnam, self.red,
- self.FAULT, self.endc))
+ print(f"| Package {self.prgnam} {self.red} {self.FAULT} {self.endc}")
self.msg.template(78)
else:
sources = []
@@ -391,6 +367,5 @@ class SBoNetwork:
"""Install SBo package found in /tmp directory.
"""
binary = slack_package(self.prgnam)
- print("[ {0}Installing{1} ] --> {2}".format(self.green, self.endc,
- self.name))
+ print(f"[ {self.green}Installing{self.endc} ] --> {self.name}")
PackageManager(binary).upgrade(flag="--install-new")
diff --git a/slpkg/toolbar.py b/slpkg/toolbar.py
index 485030da..a193c6d7 100644
--- a/slpkg/toolbar.py
+++ b/slpkg/toolbar.py
@@ -34,7 +34,6 @@ def status(sec):
if _meta_.prg_bar in ["on", "ON"]:
syms = ["|", "/", "-", "\\"]
for sym in syms:
- print("\b{0}{1}{2}".format(_meta_.color["GREY"], sym,
- _meta_.color["ENDC"]), end="")
+ print(f"\b{_meta_.color['GREY']}{sym}{_meta_.color['ENDC']}", end="")
print(end="", flush=True)
time.sleep(float(sec))
diff --git a/slpkg/tracking.py b/slpkg/tracking.py
index 60e133b0..92440ac2 100644
--- a/slpkg/tracking.py
+++ b/slpkg/tracking.py
@@ -81,20 +81,16 @@ class TrackingDeps:
pkg_len = len(self.name) + 24
print() # new line at start
self.msg.template(pkg_len)
- print("| Package {0}{1}{2} dependencies :".format(
- self.cyan, self.name, self.endc))
+ print(f"| Package {self.cyan}{self.name}{self.endc} dependencies :")
self.msg.template(pkg_len)
print("\\")
- print(" +---{0}[ Tree of dependencies ]{1}".format(self.yellow,
- self.endc))
+ print(f" +---{self.yellow}[ Tree of dependencies ]{self.endc}")
index = 0
for pkg in self.dependencies:
if "--check-deps" in self.flag:
used = self.check_used(pkg)
self.deps_used(pkg, used)
- used = "{0} {1}{2}{3}".format(
- "is dependence on -->", self.cyan,
- ", ".join(used), self.endc)
+ used = f"is dependence on --> {self.cyan}{', '.join(used)}{self.endc}"
else:
used = ""
index += 1
@@ -103,14 +99,10 @@ class TrackingDeps:
if self.meta.use_colors in ["off", "OFF"]:
installed = "* "
print(" |")
- print(" {0}{1}: {2}{3}{4} {5}{6}".format(
- "+--", index, self.green, pkg,
- self.endc, installed, used))
+ print(f" +--{index}: {self.green}{pkg}{self.endc} {installed}{used}")
else:
print(" |")
- print(" {0}{1}: {2}{3}{4} {5}".format(
- "+--", index, self.red, pkg,
- self.endc, installed))
+ print(f" +--{index}: {self.red}{pkg}{self.endc} {installed}")
if self.meta.use_colors in ["off", "OFF"]:
print("\n * = Installed\n")
else:
@@ -132,7 +124,7 @@ class TrackingDeps:
self.dependencies_list = Requires(self.flag).sbo(self.name)
else:
PACKAGES_TXT = Utils().read_file(
- self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(self.repo))
+ self.meta.lib_path + f"{self.repo}_repo/PACKAGES.TXT")
self.names = Utils().package_name(PACKAGES_TXT)
self.bin_case_insensitive()
self.find_pkg = search_pkg(self.name, self.repo)
diff --git a/slpkg/upgrade_checklist.py b/slpkg/upgrade_checklist.py
index cb171057..9b03e773 100644
--- a/slpkg/upgrade_checklist.py
+++ b/slpkg/upgrade_checklist.py
@@ -31,19 +31,19 @@ from slpkg.pkg.installed import GetFromInstalled
def choose_upg(packages):
- """Create checklist to choose packages for upgrade
+ """Creating checklist to choose packages for upgrade
"""
selected_packages, data = [], []
if packages:
for pkg in packages:
name = GetFromInstalled(pkg).name()
ver = GetFromInstalled(pkg).version()
- binary = "{0}{1}".format(name, ver)
+ binary = f"{name}{ver}"
installed = find_package(binary + _meta_.sp, _meta_.pkg_path)[0]
data.append(installed)
text = "Press 'spacebar' to unchoose packages from upgrade"
title = " Upgrade "
- backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__)
+ backtitle = f"{_meta_.__all__} {_meta_.__version__}"
status = True
pkgs = DialogUtil(data, text, title, backtitle,
status).checklist()
diff --git a/slpkg/url_read.py b/slpkg/url_read.py
index 993630c6..1763f810 100644
--- a/slpkg/url_read.py
+++ b/slpkg/url_read.py
@@ -33,6 +33,8 @@ class URL:
def __init__(self, link):
self.link = link
self.meta = _meta_
+ self.red = _meta_.color["RED"]
+ self.endc = _meta_.color["ENDC"]
self.http = urllib3.PoolManager()
def reading(self):
@@ -42,7 +44,5 @@ class URL:
f = self.http.request('GET', self.link)
return f.data.decode("utf-8", "ignore")
except urllib3.exceptions.NewConnectionError:
- print("\n{0}Can't read the file '{1}'{2}".format(
- self.meta.color["RED"], self.link.split("/")[-1],
- self.meta.color["ENDC"]))
+ print(f"\n{self.red}Can't read the file '{self.link.split('/')[-1]}'{self.endc}")
return " "
From 985ac593743a368ef5a21132412d3d78852385d4 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 13 Jan 2020 21:32:43 +0100
Subject: [PATCH 12/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/sbo/queue.py | 21 ++++++-------
slpkg/sbo/search.py | 2 +-
slpkg/sbo/slackbuild.py | 67 ++++++++++++++++++-----------------------
3 files changed, 40 insertions(+), 50 deletions(-)
diff --git a/slpkg/sbo/queue.py b/slpkg/sbo/queue.py
index eb1c86fd..4e888aef 100644
--- a/slpkg/sbo/queue.py
+++ b/slpkg/sbo/queue.py
@@ -50,6 +50,9 @@ class QueuePkgs:
"#\n"
]
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.endc = _meta_.color["ENDC"]
self.quit = False
self.queue = self.meta.lib_path + "queue/"
self.queue_list = self.queue + "queue_list"
@@ -82,8 +85,7 @@ class QueuePkgs:
print("\nPackages in the queue:\n")
for pkg in self.packages():
if pkg:
- print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
- self.meta.color["ENDC"]))
+ print(f"{self.green}{pkg}{self.endc}")
self.quit = True
if self.quit:
print() # new line at exit
@@ -98,13 +100,11 @@ class QueuePkgs:
for pkg in pkgs:
find = sbo_search_pkg(pkg)
if pkg not in queue_list and find is not None:
- print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
- self.meta.color["ENDC"]))
+ print(f"{self.green}{pkg}{self.endc}")
queue.write(pkg + "\n")
self.quit = True
else:
- print("{0}{1}{2}".format(self.meta.color["RED"], pkg,
- self.meta.color["ENDC"]))
+ print(f"{self.red}{pkg}{self.endc}")
self.quit = True
queue.close()
if self.quit:
@@ -119,8 +119,7 @@ class QueuePkgs:
if line not in pkgs:
queue.write(line + "\n")
else:
- print("{0}{1}{2}".format(self.meta.color["RED"], line,
- self.meta.color["ENDC"]))
+ print(f"{self.red}{line}{self.endc}")
self.quit = True
queue.close()
if self.quit:
@@ -161,13 +160,13 @@ class QueuePkgs:
print() # new line at start
for pkg in packages:
ver = SBoGrep(pkg).version()
- prgnam = "{0}-{1}".format(pkg, ver)
+ prgnam = f"{pkg}-{ver}"
if find_package(prgnam, self.meta.output):
binary = slack_package(prgnam)
PackageManager(binary).upgrade(flag="--install-new")
else:
- print("\nPackage {0} not found in the {1} for "
- "installation\n".format(prgnam, self.meta.output))
+ print(f"\nPackage {prgnam} not found in the {self.meta.output} for "
+ f"installation\n")
else:
print("\nPackages not found in the queue for installation\n")
raise SystemExit(1)
diff --git a/slpkg/sbo/search.py b/slpkg/sbo/search.py
index 5eefe4a2..e6ce7e75 100644
--- a/slpkg/sbo/search.py
+++ b/slpkg/sbo/search.py
@@ -34,7 +34,7 @@ def sbo_search_pkg(name):
return url
"""
repo = Repo().default_repository()["sbo"]
- sbo_url = "{0}{1}/".format(repo, slack_ver())
+ sbo_url = f"{repo}{slack_ver()}/"
SLACKBUILDS_TXT = Utils().read_file(
_meta_.lib_path + "sbo_repo/SLACKBUILDS.TXT")
for line in SLACKBUILDS_TXT.splitlines():
diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py
index 4c3aa40a..72969e13 100644
--- a/slpkg/sbo/slackbuild.py
+++ b/slpkg/sbo/slackbuild.py
@@ -57,6 +57,10 @@ class SBoInstall:
pkg_security(self.slackbuilds)
self.flag = flag
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.yellow = _meta_.color["YELLOW"]
+ self.grey = _meta_.color["GREY"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.arch = SBoArch().get()
self.build_folder = self.meta.build_path
@@ -145,19 +149,15 @@ class SBoInstall:
if self.match and [""] != self.slackbuilds:
print("\nMatching summary")
print("=" * 79)
- print("Total {0} matching packages\n".format(count_total))
+ print(f"Total {count_total} matching packages\n")
raise SystemExit(1)
print("\nInstalling summary")
print("=" * 79)
- print("{0}Total {1} {2}.".format(
- self.meta.color["GREY"], count_total,
- self.msg.pkg(count_total)))
- print("{0} {1} will be installed, {2} already installed and "
- "{3} {4}".format(self.count_uni,
- self.msg.pkg(self.count_uni),
- self.count_ins, self.count_upg,
- self.msg.pkg(self.count_upg)))
- print("will be upgraded.{0}\n".format(self.meta.color["ENDC"]))
+ print(f"{self.grey}Total {count_total} {self.msg.pkg(count_total)}.")
+ print(f"{self.count_uni} {self.msg.pkg(self.count_uni)} will be installed, "
+ f"{self.count_ins} already installed and "
+ f"{self.count_upg} {self.msg.pkg(self.count_upg)}")
+ print(f"will be upgraded.{self.endc}\n")
self.continue_to_install()
else:
self.msg.not_found(self.is_upgrade)
@@ -227,7 +227,7 @@ class SBoInstall:
sbo_versions, sources = [], []
for sbo in slackbuilds:
status(0.02)
- sbo_ver = "{0}-{1}".format(sbo, SBoGrep(sbo).version())
+ sbo_ver = f"{sbo}-{SBoGrep(sbo).version()}"
sbo_versions.append(sbo_ver)
sources.append(SBoGrep(sbo).source())
return [sbo_versions, sources]
@@ -250,13 +250,12 @@ class SBoInstall:
"""View top template
"""
self.msg.template(78)
- print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
- "| Package", " " * 17,
- "New version", " " * 8,
- "Arch", " " * 4,
- "Build", " " * 2,
- "Repos", " " * 10,
- "Size"))
+ print(f"| Packages{' ' * 16}"
+ f"New version{' ' * 8}"
+ f"Arch{' ' * 4}"
+ f"Build{' ' * 2}"
+ f"Repos{' ' * 10}"
+ f"Size")
self.msg.template(78)
def view_packages(self, *args):
@@ -267,12 +266,11 @@ class SBoInstall:
args[3] arch
"""
ver = GetFromInstalled(args[1]).version()
- print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>11}{12}".format(
- args[0], args[1] + ver, self.meta.color["ENDC"],
- " " * (23-len(args[1] + ver)), args[2],
- " " * (18-len(args[2])), args[3],
- " " * (15-len(args[3])), "",
- "", "SBo", "", "").rstrip())
+ print(f" {args[0]}{args[1] + ver}{self.endc} "
+ f"{' ' * (23-len(args[1] + ver))}{args[2]}"
+ f"{' ' * (18-len(args[2]))} {args[3]}"
+ f"{' ' * (15-len(args[3]))}{''}"
+ f"{''}SBo{''}{'':>11}{''}")
def tag(self, sbo):
"""Tag with color green if package already installed,
@@ -337,9 +335,7 @@ class SBoInstall:
self.msg.template(78)
elif self.unst[0] in src_link or self.unst[1] in src_link:
self.msg.template(78)
- print("| Package {0} {1}{2}{3}".format(
- prgnam, self.meta.color["RED"], "".join(src_link),
- self.meta.color["ENDC"]))
+ print(f"| Package {prgnam} {self.red}{''.join(src_link)}{self.endc}")
self.msg.template(78)
else:
sbo_url = sbo_search_pkg(pkg)
@@ -358,14 +354,10 @@ class SBoInstall:
binary = slack_package(prgnam)
if os.path.isfile("".join(binary)):
if GetFromInstalled(pkg).name() == pkg:
- print("[ {0}Upgrading{1} ] --> {2}".format(
- self.meta.color["YELLOW"],
- self.meta.color["ENDC"], prgnam))
+ print(f"[ {self.yellow}Upgrading{self.endc} ] --> {prgnam}")
upgraded.append(prgnam)
else:
- print("[ {0}Installing{1} ] --> {2}".format(
- self.meta.color["GREEN"],
- self.meta.color["ENDC"], prgnam))
+ print(f"[ {self.green}Installing{self.endc} ] --> {prgnam}")
installs.append(prgnam)
if ("--rebuild" in self.flag and
GetFromInstalled(pkg).name() == pkg):
@@ -384,8 +376,8 @@ class SBoInstall:
ins_ver = "0"
if parse_version(sbo_ver) < parse_version(ins_ver):
self.msg.template(78)
- print("| Package {0} don't downgrade, "
- "setting by user".format(name))
+ print(f"| Package {name} don't downgrade, "
+ f"setting by user")
self.msg.template(78)
return True
@@ -393,9 +385,8 @@ class SBoInstall:
"""Alternative repository for sbo sources"""
sources = []
name = "-".join(prgnam.split("-")[:-1])
- category = "{0}/{1}/".format(sbo_link.split("/")[-2], name)
+ category = f"{sbo_link.split('/')[-2]}/{name}/"
for link in src_link:
source = link.split("/")[-1]
- sources.append("{0}{1}{2}".format(self.meta.sbosrcarch_link,
- category, source))
+ sources.append(f"{self.meta.sbosrcarch_link}{category}{source}")
return sources
From 62cdb43fc4a59e5a4b9cd6d440e0461240cd471b Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Tue, 14 Jan 2020 13:32:30 +0100
Subject: [PATCH 13/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/binary/greps.py | 3 +-
slpkg/binary/install.py | 61 ++++++++++++++++-------------------------
slpkg/sbo/slackbuild.py | 4 +--
3 files changed, 27 insertions(+), 41 deletions(-)
diff --git a/slpkg/binary/greps.py b/slpkg/binary/greps.py
index 834f266b..fc07c2a7 100644
--- a/slpkg/binary/greps.py
+++ b/slpkg/binary/greps.py
@@ -165,8 +165,7 @@ class Requires:
else:
return ""
else:
- PACKAGES_TXT = Utils().read_file("{0}{1}_repo/PACKAGES.TXT".format(
- _meta_.lib_path, self.repo))
+ PACKAGES_TXT = Utils().read_file(f"{_meta_.lib_path}{self.repo}_repo/PACKAGES.TXT")
for line in PACKAGES_TXT.splitlines():
if line.startswith("PACKAGE NAME:"):
pkg_name = split_package(line[14:].strip())[0]
diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py
index 01a28df5..5576b649 100644
--- a/slpkg/binary/install.py
+++ b/slpkg/binary/install.py
@@ -60,6 +60,11 @@ class BinaryInstall:
self.repo = repo
self.flag = flag
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.grey = _meta_.color["GREY"]
+ self.yellow = _meta_.color['YELLOW']
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.version = self.meta.slack_rel
self.tmp_path = self.meta.slpkg_tmp_packages
@@ -124,22 +129,16 @@ class BinaryInstall:
if self.matching and [""] != self.packages:
print("\nMatching summary")
print("=" * 79)
- print("Total {0} matching packages\n".format(sum(sums)))
+ print(f"Total {sum(sums)} matching packages\n")
raise SystemExit(1)
print("\nInstalling summary")
print("=" * 79)
- print("{0}Total {1} {2}.".format(self.meta.color["GREY"],
- sum(sums),
- self.msg.pkg(sum(sums))))
- print("{0} {1} will be installed, {2} will be upgraded and "
- "{3} will be reinstalled.".format(sums[2],
- self.msg.pkg(sums[2]),
- sums[1], sums[0]))
- print("Need to get {0} {1} of archives.".format(size[0],
- unit[0]))
- print("After this process, {0} {1} of additional disk "
- "space will be used.{2}".format(size[1], unit[1],
- self.meta.color["ENDC"]))
+ print(f"{self.grey}Total {sum(sums)} {self.msg.pkg(sum(sums))}.")
+ print(f"{sums[2]} {self.msg.pkg(sums[2])} will be installed, {sums[1]} will be upgraded and "
+ f"{sums[0]} will be reinstalled.")
+ print(f"Need to get {size[0]} {unit[0]} of archives.")
+ print(f"After this process, {size[1]} {unit[1]} of additional disk "
+ f"space will be used.{self.endc}")
print()
self.if_all_installed()
if self.msg.answer() in ["y", "Y"]:
@@ -221,20 +220,17 @@ class BinaryInstall:
installs, upgraded = [], []
for inst in (self.dep_install + self.install):
package = (self.tmp_path + inst).split()
- pkg_ver = "{0}-{1}".format(split_package(inst)[0],
- split_package(inst)[1])
+ pkg_ver = f"{inst[0]}-{inst[1]}"
self.checksums(inst)
if GetFromInstalled(split_package(inst)[0]).name():
- print("[ {0}upgrading{1} ] --> {2}".format(
- self.meta.color["YELLOW"], self.meta.color["ENDC"], inst))
+ print(f"[ {self.yellow}upgrading{self.endc} ] --> {inst}")
upgraded.append(pkg_ver)
if "--reinstall" in self.flag:
PackageManager(package).upgrade("--reinstall")
else:
PackageManager(package).upgrade("--install-new")
else:
- print("[ {0}installing{1} ] --> {2}".format(
- self.meta.color["GREEN"], self.meta.color["ENDC"], inst))
+ print(f"[ {self.green}installing{self.endc} ] --> {inst}")
installs.append(pkg_ver)
PackageManager(package).upgrade("--install-new")
return [installs, upgraded]
@@ -249,8 +245,7 @@ class BinaryInstall:
ins_ver = "0"
if parse_version(rep_ver) < parse_version(ins_ver):
self.msg.template(78)
- print("| Package {0} don't downgrade, "
- "setting by user".format(name))
+ print(f"| Package {name} don't downgrade, setting by user")
self.msg.template(78)
return True
@@ -302,26 +297,18 @@ class BinaryInstall:
COLOR = self.meta.color["RED"]
uni_sum += 1
ver = GetFromInstalled(pkg_repo[0]).version()
- print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>11}{12}".format(
- COLOR, pkg_repo[0] + ver, self.meta.color["ENDC"],
- " " * (23-len(pkg_repo[0] + ver)), pkg_repo[1],
- " " * (18-len(pkg_repo[1])), pkg_repo[2],
- " " * (8-len(pkg_repo[2])), pkg_repo[3],
- " " * (7-len(pkg_repo[3])), repo,
- comp, " K").rstrip())
+ print(f" {COLOR}{pkg_repo[0] + ver}{self.endc}"
+ f"{' ' * (23-len(pkg_repo[0] + ver))} {pkg_repo[1]}"
+ f"{' ' * (18-len(pkg_repo[1]))} {pkg_repo[2]}"
+ f"{' ' * (8-len(pkg_repo[2]))}{pkg_repo[3]}"
+ f"{' ' * (7-len(pkg_repo[3]))}{repo}{comp:>11}{' K'}")
return [pkg_sum, upg_sum, uni_sum]
def top_view(self):
"""Print packages status bar
"""
self.msg.template(78)
- print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
- "| Package", " " * 17,
- "New Version", " " * 8,
- "Arch", " " * 4,
- "Build", " " * 2,
- "Repos", " " * 10,
- "Size"))
+ print(f"| Package{' ' * 17}New Version{' ' * 8}Arch{' ' * 4}Build{' ' * 2}Repos{' ' * 10}Size")
self.msg.template(78)
def store(self, packages):
@@ -338,7 +325,7 @@ class BinaryInstall:
if (pk and pkg == split_package(pk)[0] and
pk not in install and
split_package(pk)[0] not in self.blacklist):
- dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk))
+ dwn.append(f"{self.mirror}{loc}/{pk}")
install.append(pk)
comp_sum.append(comp)
uncomp_sum.append(uncomp)
@@ -349,7 +336,7 @@ class BinaryInstall:
name = split_package(pk)[0]
if (pk and pkg in name and name not in self.blacklist):
self.matching = True
- dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk))
+ dwn.append(f"{self.mirror}{loc}/{pk}")
install.append(pk)
comp_sum.append(comp)
uncomp_sum.append(uncomp)
diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py
index 72969e13..2eff2a0f 100644
--- a/slpkg/sbo/slackbuild.py
+++ b/slpkg/sbo/slackbuild.py
@@ -266,8 +266,8 @@ class SBoInstall:
args[3] arch
"""
ver = GetFromInstalled(args[1]).version()
- print(f" {args[0]}{args[1] + ver}{self.endc} "
- f"{' ' * (23-len(args[1] + ver))}{args[2]}"
+ print(f" {args[0]}{args[1] + ver}{self.endc}"
+ f"{' ' * (24-len(args[1] + ver))}{args[2]}"
f"{' ' * (18-len(args[2]))} {args[3]}"
f"{' ' * (15-len(args[3]))}{''}"
f"{''}SBo{''}{'':>11}{''}")
From e71546595d0820d9772ed6d48ee98bb1f271fbf8 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Tue, 14 Jan 2020 22:28:08 +0100
Subject: [PATCH 14/40] Added .gitlab-ci.yml file
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 .gitlab-ci.yml
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..43e691d7
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,10 @@
+image: python:3.7-alpine
+
+pages:
+ script:
+ - pip install -r requirements.txt
+ artifacts:
+ paths:
+ - public/
+ only:
+ - develop
From 421a03a62a1da2a1e399d1e5cb83d775fd54cc3c Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Tue, 14 Jan 2020 22:35:40 +0100
Subject: [PATCH 15/40] Updated .gitlab-ci.yml file
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++--------
1 file changed, 35 insertions(+), 8 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 43e691d7..69111e35 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,10 +1,37 @@
-image: python:3.7-alpine
+image: "python:3.7"
-pages:
- script:
+before_script:
+ - python --version
- pip install -r requirements.txt
- artifacts:
- paths:
- - public/
- only:
- - develop
+
+stages:
+ - Static Analysis
+ - Test
+
+mypy:
+ stage: Static Analysis
+ script:
+ - pwd
+ - ls -l
+ - python -m mypy bild/file.py
+ - python -m mypy bild/directory.py
+
+flake8:
+ stage: Static Analysis
+ script:
+ - flake8 --max-line-length=120 bild/*.py
+
+pylint:
+ stage: Static Analysis
+ allow_failure: true
+ script:
+ - pylint -d C0301 bild/*.py
+
+unit_test:
+ stage: Test
+ script:
+ - pwd
+ - ls -l
+ - export PYTHONPATH="$PYTHONPATH:."
+ - python -c "import sys;print(sys.path)"
+ - pytest
\ No newline at end of file
From ebf74b3e4f2868341511ed790f9ff9af823d9bb7 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Tue, 14 Jan 2020 22:39:28 +0100
Subject: [PATCH 16/40] Updated .gitlab-ci.yml file
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 18 ------------------
requirements.txt | 2 ++
2 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 69111e35..1499b35b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,15 +6,6 @@ before_script:
stages:
- Static Analysis
- - Test
-
-mypy:
- stage: Static Analysis
- script:
- - pwd
- - ls -l
- - python -m mypy bild/file.py
- - python -m mypy bild/directory.py
flake8:
stage: Static Analysis
@@ -26,12 +17,3 @@ pylint:
allow_failure: true
script:
- pylint -d C0301 bild/*.py
-
-unit_test:
- stage: Test
- script:
- - pwd
- - ls -l
- - export PYTHONPATH="$PYTHONPATH:."
- - python -c "import sys;print(sys.path)"
- - pytest
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 8eeb20f6..bd08168a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,3 +12,5 @@
# python3-pythondialog >= 3.5.0 (Python interface to the UNIX dialog utility)
urllib3 >= 1.25.7
+flake8 >= 3.5.0
+pylint >= 2.4.4
\ No newline at end of file
From 238047c0f3833ffdea7813445918ff35b3da4b0f Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Tue, 14 Jan 2020 22:42:30 +0100
Subject: [PATCH 17/40] Updated .gitlab-ci.yml file
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 12 ++++++++----
requirements.txt | 2 +-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1499b35b..8e33b97f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,14 +6,18 @@ before_script:
stages:
- Static Analysis
+ - Test
flake8:
stage: Static Analysis
script:
- flake8 --max-line-length=120 bild/*.py
-pylint:
- stage: Static Analysis
- allow_failure: true
+ unit_test:
+ stage: Test
script:
- - pylint -d C0301 bild/*.py
+ - pwd
+ - ls -l
+ - export PYTHONPATH="$PYTHONPATH:."
+ - python -c "import sys;print(sys.path)"
+ - pytest
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index bd08168a..12a2b132 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,4 +13,4 @@
urllib3 >= 1.25.7
flake8 >= 3.5.0
-pylint >= 2.4.4
\ No newline at end of file
+pytest >= 5.3.0
\ No newline at end of file
From 8cb73f329ac0e45315dd36bc915147cf7ec63904 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 00:12:09 +0100
Subject: [PATCH 18/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/binary/repo_init.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/slpkg/binary/repo_init.py b/slpkg/binary/repo_init.py
index f6367977..71170624 100644
--- a/slpkg/binary/repo_init.py
+++ b/slpkg/binary/repo_init.py
@@ -41,7 +41,7 @@ class RepoInit:
def fetch(self):
if self.repo in self.meta.default_repositories:
- exec("self._init_{0}()".format(self.repo))
+ exec(f"self._init_{self.repo}()")
else:
exec("self._init_custom()")
self.lib = self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(
From f0d01bea95176b32a742f0d118b74e629e328f55 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 00:30:44 +0100
Subject: [PATCH 19/40] Fixed build pkg-ver reference
Signed-off-by: Dimitris Zlatanidis
---
slpkg/binary/install.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py
index 5576b649..eac5d011 100644
--- a/slpkg/binary/install.py
+++ b/slpkg/binary/install.py
@@ -220,7 +220,7 @@ class BinaryInstall:
installs, upgraded = [], []
for inst in (self.dep_install + self.install):
package = (self.tmp_path + inst).split()
- pkg_ver = f"{inst[0]}-{inst[1]}"
+ pkg_ver = f"{split_package(inst)[0]}-{split_package(inst)[1]}"
self.checksums(inst)
if GetFromInstalled(split_package(inst)[0]).name():
print(f"[ {self.yellow}upgrading{self.endc} ] --> {inst}")
From 115891c720fe9f549a3912f64e89f88fce2798f3 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 00:34:39 +0100
Subject: [PATCH 20/40] Remove travis.yml
Signed-off-by: Dimitris Zlatanidis
---
.travis.yml | 7 -------
1 file changed, 7 deletions(-)
delete mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 8a4f7cda..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-language: python
-python:
- - "2.7"
-# command to install dependencies
-install: "pip install -r requirements.txt"
-# command to run tests
-script: nosetests
From e0c61b07a0851ee5896ef135c2fe8c7a2999ae24 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 00:39:03 +0100
Subject: [PATCH 21/40] Fix indentation
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8e33b97f..a4bc3c7f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -13,11 +13,11 @@ flake8:
script:
- flake8 --max-line-length=120 bild/*.py
- unit_test:
- stage: Test
- script:
- - pwd
- - ls -l
- - export PYTHONPATH="$PYTHONPATH:."
- - python -c "import sys;print(sys.path)"
- - pytest
\ No newline at end of file
+unit_test:
+stage: Test
+script:
+- pwd
+- ls -l
+- export PYTHONPATH="$PYTHONPATH:."
+- python -c "import sys;print(sys.path)"
+- pytest
\ No newline at end of file
From 56ad4da2687ce225805b64d925e49109748a4f71 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 00:42:05 +0100
Subject: [PATCH 22/40] Fix indentation
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a4bc3c7f..8cdf58d3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,10 +14,10 @@ flake8:
- flake8 --max-line-length=120 bild/*.py
unit_test:
-stage: Test
-script:
-- pwd
-- ls -l
-- export PYTHONPATH="$PYTHONPATH:."
-- python -c "import sys;print(sys.path)"
-- pytest
\ No newline at end of file
+ stage: Test
+ script:
+ - pwd
+ - ls -l
+ - export PYTHONPATH="$PYTHONPATH:."
+ - python -c "import sys;print(sys.path)"
+ - pytest
\ No newline at end of file
From d59295676775d6c21b33961cc03d535af257c65c Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 00:52:04 +0100
Subject: [PATCH 23/40] Updated pytest
Signed-off-by: Dimitris Zlatanidis
---
slpkg/md5sum.py | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/slpkg/md5sum.py b/slpkg/md5sum.py
index f8d3bf48..80f71495 100644
--- a/slpkg/md5sum.py
+++ b/slpkg/md5sum.py
@@ -32,12 +32,4 @@ def md5(source):
source = source.replace("%2B", "+")
with open(source, "rb") as file_to_check:
data = file_to_check.read()
- return hashlib.md5(data).hexdigest()
-
-
-def test_md5(source="superuser.py"):
- """Testing hashing with pytest"""
- source = source.replace("%2B", "+")
- with open(source, "rb") as file_to_check:
- data = file_to_check.read()
- assert hashlib.md5(data).hexdigest() == "e6cebdf37fbc1b8e9d3c5e3e53b300c1"
+ return hashlib.md5(data).hexdigest()
\ No newline at end of file
From 0e9897169c483b9a1823e0f889d7848b4e39ee7f Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 01:01:20 +0100
Subject: [PATCH 24/40] Updated pytest
Signed-off-by: Dimitris Zlatanidis
---
slpkg/test_md5sum.py | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 slpkg/test_md5sum.py
diff --git a/slpkg/test_md5sum.py b/slpkg/test_md5sum.py
new file mode 100644
index 00000000..001da660
--- /dev/null
+++ b/slpkg/test_md5sum.py
@@ -0,0 +1,7 @@
+from slpkg.md5sum import md5
+
+
+
+def test_md5():
+ result = md5('slpkg/superuser.py')
+ assert result == "e6cebdf37fbc1b8e9d3c5e3e53b300c1"
From d8cc26a44af60ee32cf0e0096431ed3c74a221f8 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 01:10:52 +0100
Subject: [PATCH 25/40] Setup pytest
Signed-off-by: Dimitris Zlatanidis
---
pytest.ini | 4 ++++
setup.py | 4 +++-
2 files changed, 7 insertions(+), 1 deletion(-)
create mode 100644 pytest.ini
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 00000000..c085b4c5
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,4 @@
+[pytest]
+python_files = test_*
+python_classes = *Tests
+python_functions = test_*
diff --git a/setup.py b/setup.py
index 4896a5ad..cc81c26f 100755
--- a/setup.py
+++ b/setup.py
@@ -35,7 +35,9 @@ except ImportError:
from distutils.core import setup
docs_requires = []
-tests_requires = []
+tests_requires = [
+ "pytest>=5.3.2"
+]
install_requires = [
"urllib3>=1.25.7"
]
From 342e2d58bee444c0fb4a943f72824acd4defd389 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 01:16:49 +0100
Subject: [PATCH 26/40] Updated pytest requirements
Signed-off-by: Dimitris Zlatanidis
---
.gitlab-ci.yml | 2 --
requirements.txt | 2 +-
slpkg/test_md5sum.py | 1 -
3 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8cdf58d3..9d6b9b40 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,8 +16,6 @@ flake8:
unit_test:
stage: Test
script:
- - pwd
- - ls -l
- export PYTHONPATH="$PYTHONPATH:."
- python -c "import sys;print(sys.path)"
- pytest
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 12a2b132..cd8f53d8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,4 +13,4 @@
urllib3 >= 1.25.7
flake8 >= 3.5.0
-pytest >= 5.3.0
\ No newline at end of file
+pytest >= 5.3.2
\ No newline at end of file
diff --git a/slpkg/test_md5sum.py b/slpkg/test_md5sum.py
index 001da660..9f5f0797 100644
--- a/slpkg/test_md5sum.py
+++ b/slpkg/test_md5sum.py
@@ -1,7 +1,6 @@
from slpkg.md5sum import md5
-
def test_md5():
result = md5('slpkg/superuser.py')
assert result == "e6cebdf37fbc1b8e9d3c5e3e53b300c1"
From a3c0470f098b10cb1c6a8535b9966ed01557e274 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 01:18:59 +0100
Subject: [PATCH 27/40] Added tests folder
Signed-off-by: Dimitris Zlatanidis
---
{slpkg => tests}/test_md5sum.py | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename {slpkg => tests}/test_md5sum.py (100%)
diff --git a/slpkg/test_md5sum.py b/tests/test_md5sum.py
similarity index 100%
rename from slpkg/test_md5sum.py
rename to tests/test_md5sum.py
From 81c86a5620d5b5babcf9b785d5d2cd880ba5fd5a Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 16:09:55 +0100
Subject: [PATCH 28/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/binary/repo_init.py | 48 +++++++++++++++------------------------
1 file changed, 18 insertions(+), 30 deletions(-)
diff --git a/slpkg/binary/repo_init.py b/slpkg/binary/repo_init.py
index 71170624..eb3e9986 100644
--- a/slpkg/binary/repo_init.py
+++ b/slpkg/binary/repo_init.py
@@ -44,19 +44,18 @@ class RepoInit:
exec(f"self._init_{self.repo}()")
else:
exec("self._init_custom()")
- self.lib = self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(
- self.repo)
+ self.lib = self.meta.lib_path + f"{self.repo}_repo/PACKAGES.TXT"
PACKAGES_TXT = Utils().read_file(self.lib)
return PACKAGES_TXT, self.mirror
def _init_custom(self):
- self.mirror = "{0}".format(Repo().custom_repository()[self.repo])
+ self.mirror = f"{Repo.custom_repository()[self.repo]}"
def _init_slack(self):
self.mirror = mirrors(name="", location="")
def _init_rlw(self):
- self.mirror = "{0}{1}/".format(self.def_repo_dict["rlw"], slack_ver())
+ self.mirror = f"{self.def_repo_dict}{slack_ver()}/"
def _init_alien(self):
ver = slack_ver()
@@ -65,30 +64,28 @@ class RepoInit:
arch = "x86_64"
if self.meta.slack_rel == "current":
ver = self.meta.slack_rel
- self.mirror = "{0}{1}/{2}/".format(self.def_repo_dict["alien"],
- ver, arch)
+ self.mirror = f"{self.def_repo_dict['alien']}{ver}/{arch}/"
def _init_slacky(self):
arch = ""
if self.meta.arch == "x86_64":
arch = "64"
- self.mirror = "{0}slackware{1}-{2}/".format(
- self.def_repo_dict["slacky"], arch, slack_ver())
+ self.mirror = f"{self.def_repo_dict}slackware{arch}-{slack_ver()}/"
def _init_conrad(self):
self.mirror = self.def_repo_dict["conrad"]
def _init_slonly(self):
ver = slack_ver()
- arch = "{0}-x86".format(ver)
+ arch = f"{ver}-x86"
if self.meta.arch == "x86_64":
- arch = "{0}-x86_64".format(ver)
+ arch = f"{ver}-x86_64"
if self.meta.slack_rel == "current":
if self.meta.arch == "x86_64":
- arch = "{0}-x86_64".format(self.meta.slack_rel)
+ arch = f"{self.meta.slack_rel}-x86_64"
else:
- arch = "{0}-x86".format(self.meta.slack_rel)
- self.mirror = "{0}{1}/".format(self.def_repo_dict["slonly"], arch)
+ arch = f"{self.meat.slack_rel}-x86"
+ self.mirror = f"{self.def_repo_dict['slonly']}{arch}/"
def _init_ktown(self):
self.mirror = self.def_repo_dict["ktown"]
@@ -103,23 +100,20 @@ class RepoInit:
arch = ""
if self.meta.arch == "x86_64":
arch = "64"
- self.mirror = "{0}slacke{1}/slackware{2}-{3}/".format(
- self.def_repo_dict["slacke"], self.meta.slacke_sub_repo[1:-1],
- arch, slack_ver())
+ self.mirror = (f"{self.def_repo_dict['slacke']}"
+ f"slacke{self.meta.slacke_sub_repo[1:-1]}/slackware{arch}-{slack_ver()}/")
def _init_salix(self):
arch = "i486"
if self.meta.arch == "x86_64":
arch = "x86_64"
- self.mirror = "{0}{1}/{2}/".format(self.def_repo_dict["salix"],
- arch, slack_ver())
+ self.mirror = f"{self.def_repo_dict['salix']}{arch}/{slack_ver()}/"
def _init_slackl(self):
arch = "i486"
if self.meta.arch == "x86_64":
arch = "x86_64"
- self.mirror = "{0}{1}/current/".format(self.def_repo_dict["slackl"],
- arch)
+ self.mirror = f"{self.def_repo_dict['slackl']}{arch}/current/"
def _init_rested(self):
self.mirror = self.def_repo_dict["rested"]
@@ -128,28 +122,22 @@ class RepoInit:
arch = "x86"
if self.meta.arch == "x86_64":
arch = "x86_64"
- self.mirror = "{0}{1}/{2}/{3}/".format(
- self.def_repo_dict["msb"], slack_ver(),
- self.meta.msb_sub_repo[1:-1], arch)
+ self.mirror = f"{self.def_repo_dict['msb']}{slack_ver()}/{self.meta.msb_sub_repo[1:-1]}/{arch}/"
def _init_csb(self):
arch = "x86"
if self.meta.arch == "x86_64":
arch = "x86_64"
- self.mirror = "{0}{1}/{2}".format(
- self.def_repo_dict["csb"], slack_ver(), arch)
+ self.mirror = f"{self.def_repo_dict['csb']}{slack_ver()}/{arch}"
def _init_connos(self):
arch = ""
if self.meta.arch == "x86_64":
arch = "64"
- self.mirror = "{0}slack-n-free{1}-{2}/".format(
- self.def_repo_dict["connos"], arch, slack_ver())
+ self.mirror = f"{self.def_repo_dict['connos']}slack-n-free{arch}-{slack_ver()}/"
def _init_mles(self):
arch = "32"
if self.meta.arch == "x86_64":
arch = "64"
- self.mirror = "{0}{1}-{2}-{3}bit/".format(
- self.def_repo_dict["mles"],
- self.meta.mles_sub_repo[1:-1], slack_ver(), arch)
+ self.mirror = f"{self.def_repo_dict['mles']}{self.meta.mles_sub_repo[1:-1]}-{slack_ver()}-{arch}bit/"
\ No newline at end of file
From 27d4ba541922c92d86a5ff24d498d1de6ca375fe Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 23:23:06 +0100
Subject: [PATCH 29/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/binary/search.py | 3 +--
slpkg/init.py | 31 ++++++++++++++++++++++---------
slpkg/slack/mirrors.py | 12 ++++++------
3 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py
index a5526bc1..a0a012e1 100644
--- a/slpkg/binary/search.py
+++ b/slpkg/binary/search.py
@@ -33,8 +33,7 @@ def search_pkg(name, repo):
"""Search if package exists in PACKAGES.TXT file
and return the name.
"""
- PACKAGES_TXT = Utils().read_file(_meta_.lib_path + "{0}_repo/"
- "PACKAGES.TXT".format(repo))
+ PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT")
names = Utils().package_name(PACKAGES_TXT)
blacklist = BlackList().packages(pkgs=names, repo=repo)
for line in PACKAGES_TXT.splitlines():
diff --git a/slpkg/init.py b/slpkg/init.py
index 2f0e1afa..a746f742 100644
--- a/slpkg/init.py
+++ b/slpkg/init.py
@@ -137,14 +137,17 @@ class Initialization:
self.down(log, ChangeLog_txt, repo_name)
self.remote(log, ChangeLog_txt, lib, PACKAGES_TXT, CHECKSUMS_MD5,
FILELIST_TXT, repo_name)
- self.merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT",
- "extra/PACKAGES.TXT",
- "pasture/PACKAGES.TXT",
- "patches/PACKAGES.TXT"])
- self.merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5",
- "extra/CHECKSUMS.md5",
- "pasture/CHECKSUMS.md5",
- "patches/CHECKSUMS_md5"])
+ merge = self.merge_stable
+ if self.meta.slack_rel == "current":
+ merge = self.merge_current
+ merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT",
+ "extra/PACKAGES.TXT",
+ "pasture/PACKAGES.TXT",
+ "patches/PACKAGES.TXT"])
+ merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5",
+ "extra/CHECKSUMS.md5",
+ "pasture/CHECKSUMS.md5",
+ "patches/CHECKSUMS_md5"])
def sbo(self):
"""Creating sbo local library
@@ -682,7 +685,17 @@ class Initialization:
self.down(lib_path, FILELIST_TXT, repo)
self.down(log_path, ChangeLog_txt, repo)
- def merge(self, path, outfile, infiles):
+ def merge_stable(self, path, outfile, infiles):
+ """Merge files
+ """
+ with open(path + outfile, 'w') as out_f:
+ for i in infiles:
+ if os.path.isfile(f"{path}{i}"):
+ with open(path + i, "r") as in_f:
+ for line in in_f:
+ out_f.write(line)
+
+ def merge_current(self, path, outfile, infiles):
"""Merge files
"""
code = "utf-8"
diff --git a/slpkg/slack/mirrors.py b/slpkg/slack/mirrors.py
index 3de98493..50af32a8 100644
--- a/slpkg/slack/mirrors.py
+++ b/slpkg/slack/mirrors.py
@@ -38,17 +38,17 @@ def mirrors(name, location):
repo = Repo().slack()
if _meta_.arch == "x86_64":
if rel == "stable":
- http = repo + "slackware64-{0}/{1}{2}".format(ver, location, name)
+ http = f"{repo}slackware64-{ver}/{location}{name}"
else:
- http = repo + "slackware64-{0}/{1}{2}".format(rel, location, name)
+ http = f"{repo}slackware64-{rel}/{location}{name}"
elif _meta_.arch.startswith("arm"):
if rel == "stable":
- http = repo + "slackwarearm-{0}/{1}{2}".format(ver, location, name)
+ http = f"{repo}slackwarearm-{ver}/{location}{name}"
else:
- http = repo + "slackwarearm-{0}/{1}{2}".format(rel, location, name)
+ http = f"{repo}slackwarearm-{rel}/{location}{name}"
else:
if rel == "stable":
- http = repo + "slackware-{0}/{1}{2}".format(ver, location, name)
+ http = f"{repo}slackware-{ver}/{location}{name}"
else:
- http = repo + "slackware-{0}/{1}{2}".format(rel, location, name)
+ http = f"{repo}slackware-{rel}/{location}{name}"
return http
From 6c09177ea584f6b8622b9dd64c16daeac3b6a9a0 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 23:26:48 +0100
Subject: [PATCH 30/40] Updated for version 3.7.5
Signed-off-by: Dimitris Zlatanidis
---
ChangeLog.txt | 8 +++++++-
README.md | 2 +-
slpkg/__metadata__.py | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 18e7934c..c40b5a56 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,6 +1,12 @@
+3.7.5 - 15/01/2020
+Fixed:
+- Bugfix: merge files with slack repository between current and slack versions
+Updated:
+- code to improve for Python 3
+
3.7.4 - 20/12/2019
Fixed:
--Bugfix: UnicodeDecodeError: 'utf-8' codec can't decode byte
+- Bugfix: UnicodeDecodeError: 'utf-8' codec can't decode byte
3.7.3 - 11/12/2019
FIxed:
diff --git a/README.md b/README.md
index 49b36041..b431290e 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# slpkg 3.7.4
+# slpkg 3.7.5
Slpkg is a powerful software package manager that installs, updates, and removes packages on
[Slackware](http://www.slackware.com/) based systems. It automatically computes dependencies and
diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py
index fd8d3d71..704a52ee 100644
--- a/slpkg/__metadata__.py
+++ b/slpkg/__metadata__.py
@@ -78,7 +78,7 @@ class MetaData:
__all__ = "slpkg"
__author__ = "dslackw"
- __version_info__ = (3, 7, 4)
+ __version_info__ = (3, 7, 5)
__version__ = "{0}.{1}.{2}".format(*__version_info__)
__license__ = "GNU General Public License v3 (GPLv3)"
__email__ = "d.zlatanidis@gmail.com"
From 95b53cc51c0758ac58e26148f61ccef100d714df Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 23:40:15 +0100
Subject: [PATCH 31/40] Bugfix merge files for slack repository
Signed-off-by: Dimitris Zlatanidis
---
slpkg/init.py | 33 ++++++++++-----------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/slpkg/init.py b/slpkg/init.py
index a746f742..ec716b1c 100644
--- a/slpkg/init.py
+++ b/slpkg/init.py
@@ -137,17 +137,14 @@ class Initialization:
self.down(log, ChangeLog_txt, repo_name)
self.remote(log, ChangeLog_txt, lib, PACKAGES_TXT, CHECKSUMS_MD5,
FILELIST_TXT, repo_name)
- merge = self.merge_stable
- if self.meta.slack_rel == "current":
- merge = self.merge_current
- merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT",
- "extra/PACKAGES.TXT",
- "pasture/PACKAGES.TXT",
- "patches/PACKAGES.TXT"])
- merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5",
- "extra/CHECKSUMS.md5",
- "pasture/CHECKSUMS.md5",
- "patches/CHECKSUMS_md5"])
+ self.merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT",
+ "extra/PACKAGES.TXT",
+ "pasture/PACKAGES.TXT",
+ "patches/PACKAGES.TXT"])
+ self.merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5",
+ "extra/CHECKSUMS.md5",
+ "pasture/CHECKSUMS.md5",
+ "patches/CHECKSUMS_md5"])
def sbo(self):
"""Creating sbo local library
@@ -685,23 +682,13 @@ class Initialization:
self.down(lib_path, FILELIST_TXT, repo)
self.down(log_path, ChangeLog_txt, repo)
- def merge_stable(self, path, outfile, infiles):
- """Merge files
- """
- with open(path + outfile, 'w') as out_f:
- for i in infiles:
- if os.path.isfile(f"{path}{i}"):
- with open(path + i, "r") as in_f:
- for line in in_f:
- out_f.write(line)
-
- def merge_current(self, path, outfile, infiles):
+ def merge(self, path, outfile, infiles):
"""Merge files
"""
code = "utf-8"
with open(path + outfile, 'w', encoding=code) as out_f:
for f in infiles:
- if os.path.isfile("f{path}{f}"):
+ if os.path.isfile(f"{path}{f}"):
# checking the encoding before read the file
code = Utils.check_encoding(path, f)
with open(path + f, "r", encoding=code) as in_f:
From 3a7f53c00b9d4c6f99d8fb3a82b8dbfef0c6925c Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Wed, 15 Jan 2020 23:47:06 +0100
Subject: [PATCH 32/40] Updated to self method
Signed-off-by: Dimitris Zlatanidis
---
slpkg/init.py | 3 ++-
slpkg/utils.py | 3 +--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/slpkg/init.py b/slpkg/init.py
index ec716b1c..935b3a46 100644
--- a/slpkg/init.py
+++ b/slpkg/init.py
@@ -690,7 +690,8 @@ class Initialization:
for f in infiles:
if os.path.isfile(f"{path}{f}"):
# checking the encoding before read the file
- code = Utils.check_encoding(path, f)
+ utils = Utils()
+ code = utils.check_encoding(path, f)
with open(path + f, "r", encoding=code) as in_f:
for line in in_f:
out_f.write(line)
diff --git a/slpkg/utils.py b/slpkg/utils.py
index fd9b28af..b3be5dd2 100644
--- a/slpkg/utils.py
+++ b/slpkg/utils.py
@@ -102,8 +102,7 @@ class Utils:
else:
return file_name
- @staticmethod
- def check_encoding(path, f):
+ def check_encoding(self, path, f):
"""Checking the file encoding default is utf-8
"""
try:
From 91fe0a9789d1b114e3b5dccc2516d32fc694a0b1 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Thu, 16 Jan 2020 12:10:01 +0100
Subject: [PATCH 33/40] Fixed read iso-8859-1 files
Signed-off-by: Dimitris Zlatanidis
---
slpkg/utils.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/slpkg/utils.py b/slpkg/utils.py
index b3be5dd2..b2c5c98a 100644
--- a/slpkg/utils.py
+++ b/slpkg/utils.py
@@ -59,9 +59,11 @@ class Utils:
def read_file(self, registry):
"""Returns reading file
"""
- with open(registry, "r") as file_txt:
+ code = self.check_encoding('', registry)
+ if not code:
+ code = "utf-8"
+ with open(registry, "r", encoding=code) as file_txt:
read_file = file_txt.read()
- file_txt.close()
return read_file
def package_name(self, PACKAGES_TXT):
From 41ba3586e108fb8ba4979a6cf2cd52f635d92a81 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 18 Jan 2020 12:41:23 +0100
Subject: [PATCH 34/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/sbo/slackbuild.py | 5 +--
slpkg/slack/patches.py | 75 ++++++++++++++++-------------------------
2 files changed, 32 insertions(+), 48 deletions(-)
diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py
index 2eff2a0f..2643c1be 100644
--- a/slpkg/sbo/slackbuild.py
+++ b/slpkg/sbo/slackbuild.py
@@ -178,9 +178,10 @@ class SBoInstall:
def update_deps(self):
"""Update dependencies dictionary with all package
"""
+ utils = Utils()
onelist, dependencies = [], []
- onelist = Utils().dimensional_list(self.deps)
- dependencies = Utils().remove_dbs(onelist)
+ onelist = utils.dimensional_list(self.deps)
+ dependencies = utils.remove_dbs(onelist)
for dep in dependencies:
deps = Requires(self.flag).sbo(dep)
self.deps_dict[dep] = self.one_for_all(deps)
diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py
index 2d99f31f..8b3f1d7f 100644
--- a/slpkg/slack/patches.py
+++ b/slpkg/slack/patches.py
@@ -58,6 +58,11 @@ class Patches:
self.skip = skip
self.flag = flag
self.meta = _meta_
+ self.grey = _meta_.color["GREY"]
+ self.yellow = _meta_.color["YELLOW"]
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.version = self.meta.slack_rel
self.patch_path = self.meta.slpkg_tmp_patches
@@ -89,29 +94,20 @@ class Patches:
self.dialog_checklist()
print("\nThese packages need upgrading:\n")
self.msg.template(78)
- print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format(
- "| Package", " " * 17,
- "New Version", " " * 8,
- "Arch", " " * 4,
- "Build", " " * 2,
- "Repos", " " * 10,
- "Size"))
+ print(f"| Package{' ' * 17}New Version{' ' * 8}Arch"
+ f"{' ' * 4}Build{' ' * 2}Repo{' ' * 11}Size")
self.msg.template(78)
print("Upgrading:")
self.views()
unit, size = units(self.comp_sum, self.uncomp_sum)
print("\nInstalling summary")
print("=" * 79)
- print("{0}Total {1} {2} will be upgraded and {3} will be "
- "installed.".format(self.meta.color["GREY"],
- self.count_upg,
- self.msg.pkg(len(self.upgrade_all)),
- self.count_added))
- print("Need to get {0} {1} of archives.".format(size[0],
- unit[0]))
- print("After this process, {0} {1} of additional disk space "
- "will be used.{2}".format(size[1], unit[1],
- self.meta.color["ENDC"]))
+ print(f"{self.grey}Total {self.count_upg}"
+ f"{self.msg.pkg(len(self.upgrade_all))} will be upgraded and"
+ f" {self.count_added} will be installed.")
+ print(f"Need to get {size[0]} {unit[0]} of archives.")
+ print(f"After this process, {size[1]} {unit[1]} of additional disk space "
+ f"will be used.{self.endc}")
print()
if self.msg.answer() in ["y", "Y"]:
Download(self.patch_path, self.dwn_links,
@@ -132,8 +128,8 @@ class Patches:
slack_arch = ""
if self.meta.arch == "x86_64":
slack_arch = "64"
- print("\nSlackware{0} '{1}' v{2} distribution is up to "
- "date!\n".format(slack_arch, self.version, slack_ver()))
+ print(f"\nSlackware{slack_arch} '{self.version}' v{slack_ver()}"
+ f"distribution is up to date!\n")
def store(self):
"""
@@ -147,8 +143,7 @@ class Patches:
if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and
repo_pkg_name not in black and
repo_pkg_name not in self.skip):
- self.dwn_links.append("{0}{1}/{2}".format(mirrors("", ""),
- loc, name))
+ self.dwn_links.append(f"{mirrors('', '')}{loc}/{name}")
self.comp_sum.append(comp)
self.uncomp_sum.append(uncomp)
self.upgrade_all.append(name)
@@ -167,8 +162,7 @@ class Patches:
data.append(upg[:-4])
text = "Press 'spacebar' to unchoose packages from upgrade"
title = " Upgrade "
- backtitle = "{0} {1}".format(self.meta.__all__,
- self.meta.__version__)
+ backtitle = f"{self.meta.__all__} {self.meta.__version__}"
status = True
pkgs = DialogUtil(data, text, title, backtitle,
status).checklist()
@@ -198,13 +192,11 @@ class Patches:
if pkg_repo[0] == pkg_inst:
color = self.meta.color["YELLOW"]
ver = GetFromInstalled(pkg_repo[0]).version()
- print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>12}{12}".format(
- color, pkg_repo[0] + ver, self.meta.color["ENDC"],
- " " * (23-len(pkg_repo[0] + ver)), pkg_repo[1],
- " " * (18-len(pkg_repo[1])), pkg_repo[2],
- " " * (8-len(pkg_repo[2])), pkg_repo[3],
- " " * (7-len(pkg_repo[3])), "Slack",
- size, " K").rstrip())
+ print(f" {color}{pkg_repo[0] + ver}{self.endc}"
+ f"{' ' * (23-len(pkg_repo[0] + ver))} {pkg_repo[1]}"
+ f"{' ' * (18-len(pkg_repo[1]))} {pkg_repo[2]}"
+ f"{' ' * (8-len(pkg_repo[2]))}{pkg_repo[3]}"
+ f"{' ' * (7-len(pkg_repo[3]))}Slack{size:>12} K")
def upgrade(self):
"""
@@ -213,20 +205,15 @@ class Patches:
for pkg in self.upgrade_all:
check_md5(pkg_checksum(pkg, "slack_patches"),
self.patch_path + pkg)
- pkg_ver = "{0}-{1}".format(split_package(pkg)[0],
- split_package(pkg)[1])
+ pkg_ver = f"{split_package(pkg)[0]}-{split_package(pkg)[1]}"
if find_package(split_package(pkg)[0] + self.meta.sp,
self.meta.pkg_path):
- print("[ {0}upgrading{1} ] --> {2}".format(
- self.meta.color["YELLOW"], self.meta.color["ENDC"],
- pkg[:-4]))
+ print(f"[ {self.yellow}upgrading{self.endc} ] --> {pkg[:-4]}")
PackageManager((self.patch_path + pkg).split()).upgrade(
"--install-new")
self.upgraded.append(pkg_ver)
else:
- print("[ {0}installing{1} ] --> {2}".format(
- self.meta.color["GREEN"], self.meta.color["ENDC"],
- pkg[:-4]))
+ print(f"[ {self.green}installing{self.endc} ] --> {pkg[:-4]}")
PackageManager((self.patch_path + pkg).split()).upgrade(
"--install-new")
self.installed.append(pkg_ver)
@@ -243,9 +230,8 @@ class Patches:
else:
print()
self.msg.template(78)
- print("| {0}*** HIGHLY recommended reinstall boot loader "
- "***{1}".format(self.meta.color["RED"],
- self.meta.color["ENDC"]))
+ print(f"| {self.red}*** HIGHLY recommended reinstall "
+ f"boot loader ***{self.endc}")
print("| L=lilo / E=elilo / G=grub")
self.msg.template(78)
try:
@@ -269,8 +255,6 @@ class Patches:
"""This replace slackpkg ChangeLog.txt file with new
from Slackware official mirrors after update distribution.
"""
- print(mirrors("ChangeLog.txt", ""))
-
NEW_ChangeLog_txt = URL(mirrors("ChangeLog.txt", "")).reading()
if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt.old"):
os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt.old")
@@ -285,8 +269,7 @@ class Patches:
"""Update packages list and ChangeLog.txt file after
upgrade distribution
"""
- print("{0}Update the package lists ?{1}".format(
- self.meta.color["GREEN"], self.meta.color["ENDC"]))
+ print(f"{self.green}Update the package lists ?{self.endc}")
print("=" * 79)
if self.msg.answer() in ["y", "Y"]:
- Update().repository(["slack"])
+ Update().repository(["slack"])
\ No newline at end of file
From 2a42b775276e99c358d412e780141ac6a4360470 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 18 Jan 2020 13:50:02 +0100
Subject: [PATCH 35/40] Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis
---
slpkg/pkg/build.py | 30 ++++-------
slpkg/pkg/manager.py | 119 +++++++++++++++----------------------------
2 files changed, 53 insertions(+), 96 deletions(-)
diff --git a/slpkg/pkg/build.py b/slpkg/pkg/build.py
index 33f1278b..ad61e537 100644
--- a/slpkg/pkg/build.py
+++ b/slpkg/pkg/build.py
@@ -52,7 +52,7 @@ class BuildPackage:
self.msg = Msg()
self._SOURCES = self.meta.SBo_SOURCES
self.prgnam = self.script[:-7]
- self.log_file = "build_{0}_log".format(self.prgnam)
+ self.log_file = f"build_{self.prgnam}_log"
self.sbo_logs = self.meta.log_path + "sbo/"
self.build_logs = self.sbo_logs + "build_logs/"
self.start_log_time = time.strftime("%H:%M:%S")
@@ -94,27 +94,21 @@ class BuildPackage:
shutil.copy2(src, self.path + self.prgnam)
os.chdir(self.path + self.prgnam)
# change permissions
- subprocess.call("chmod +x {0}.SlackBuild".format(self.prgnam),
- shell=True)
+ subprocess.call(f"chmod +x {self.prgnam}.SlackBuild", shell=True)
pass_var = self._pass_variable()
if self.meta.sbo_build_log in ["on", "ON"]:
if os.path.isfile(self.build_logs + self.log_file):
os.remove(self.build_logs + self.log_file)
# start log write
log_head(self.build_logs, self.log_file, self.start_log_time)
- subprocess.Popen("{0} ./{1}.SlackBuild 2>&1 | tee -a "
- "{2}{3}".format(" ".join(pass_var),
- self.prgnam, self.build_logs,
- self.log_file), shell=True,
- stdout=sys.stdout).communicate()
+ subprocess.Popen(f"{' '.join(pass_var)} ./{self.prgnam}.SlackBuild 2>&1 | tee -a "
+ f"{self.build_logs}{self.log_file}", shell=True, stdout=sys.stdout).communicate()
sum_time = build_time(self.start_time)
# write end in log file
log_end(self.build_logs, self.log_file, sum_time)
- print("Total build time for the package {0} : {1}\n".format(
- self.prgnam, sum_time))
+ print(f"Total build time for the package {self.prgnam} : {sum_time}\n")
else:
- subprocess.call("{0} ./{1}.SlackBuild".format(
- " ".join(pass_var), self.prgnam), shell=True)
+ subprocess.call(f"{' '.join(pass_ver)} ./{self.prgnam}.SlackBuild", shell=True)
os.chdir(self.path)
except KeyboardInterrupt: # (OSError, IOError):
self.msg.pkg_not_found("\n", self.prgnam, "Wrong file", "\n")
@@ -141,7 +135,7 @@ class BuildPackage:
"""
if self.meta.makeflags in ["on", "ON"]:
cpus = multiprocessing.cpu_count()
- os.environ["MAKEFLAGS"] = "-j{0}".format(cpus)
+ os.environ["MAKEFLAGS"] = f"-j{cpus}"
def _pass_variable(self):
"""Return enviroment variables
@@ -150,7 +144,7 @@ class BuildPackage:
for var in os.environ.keys():
expVAR = var.split("_")
if expVAR[0] == self.prgnam.upper() and expVAR[1] != "PATH":
- pass_var.append("{0}={1}".format(expVAR[1], os.environ[var]))
+ pass_var.append(f"{expVAR[1]}={os.environ[var]}")
return pass_var
def _delete_sbo_tar_gz(self):
@@ -188,7 +182,7 @@ def log_end(path, log_file, sum_time):
log.seek(2)
log.write("#" * 79 + "\n\n")
log.write("Time : " + time.strftime("%H:%M:%S") + "\n")
- log.write("Total build time : {0}\n".format(sum_time))
+ log.write(f"Total build time : {sum_time}\n")
log.write(" " * 38 + "E N D\n\n")
log.write("#" * 79 + "\n\n")
log.close()
@@ -204,11 +198,9 @@ def build_time(start_time):
elif diff_time > 59.99 and diff_time <= 3599.99:
sum_time = round(diff_time / 60, 2)
sum_time_list = re.findall(r"\d+", str(sum_time))
- sum_time = ("{0} Min {1} Sec".format(sum_time_list[0],
- sum_time_list[1]))
+ sum_time = (f"{sum_time_list[0]} Min {sum_time_list[1]} Sec")
elif diff_time > 3599.99:
sum_time = round(diff_time / 3600, 2)
sum_time_list = re.findall(r"\d+", str(sum_time))
- sum_time = ("{0} Hours {1} Min".format(sum_time_list[0],
- sum_time_list[1]))
+ sum_time = (f"{sum_time_list[0]} Hours {sum_time_list[1]} Min")
return sum_time
diff --git a/slpkg/pkg/manager.py b/slpkg/pkg/manager.py
index 016cda25..60ab5ec7 100644
--- a/slpkg/pkg/manager.py
+++ b/slpkg/pkg/manager.py
@@ -45,6 +45,12 @@ class PackageManager:
def __init__(self, binary):
self.binary = binary
self.meta = _meta_
+ self.green = _meta_.color["GREEN"]
+ self.red = _meta_.color["RED"]
+ self.yellow = _meta_.color["YELLOW"]
+ self.cyan = _meta_.color["CYAN"]
+ self.grey = _meta_.color["GREY"]
+ self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.skip = []
self.size = 0
@@ -56,8 +62,7 @@ class PackageManager:
"""
for pkg in self.binary:
try:
- subprocess.call("installpkg {0} {1}".format(flag, pkg),
- shell=True)
+ subprocess.call(f"installpkg {flag} {pkg}", shell=True)
check = pkg[:-4].split("/")[-1]
if os.path.isfile(self.meta.pkg_path + check):
print("Completed!\n")
@@ -72,8 +77,7 @@ class PackageManager:
"""
for pkg in self.binary:
try:
- subprocess.call("upgradepkg {0} {1}".format(flag, pkg),
- shell=True)
+ subprocess.call(f"upgradepkg {flag} {pkg}", shell=True)
check = pkg[:-4].split("/")[-1]
if os.path.isfile(self.meta.pkg_path + check):
print("Completed!\n")
@@ -183,8 +187,7 @@ class PackageManager:
for pkg in self.binary:
name = GetFromInstalled(pkg).name()
ver = GetFromInstalled(pkg).version()
- package = find_package("{0}{1}{2}".format(
- name, ver, self.meta.sp), self.meta.pkg_path)
+ package = find_package(f"{name}{ver}{self.meta.sp}", self.meta.pkg_path)
if pkg and name == pkg:
removed.append(pkg)
packages.append(package[0])
@@ -197,14 +200,12 @@ class PackageManager:
"""View packages before removed
"""
print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
- self.meta.color["CYAN"], ", ".join(self.binary),
- self.meta.color["ENDC"]))
+ self.cyan, ", ".join(self.binary), self.endc))
removed, packages = self._get_removed()
if packages and "--checklist" in self.extra:
removed = []
text = "Press 'spacebar' to unchoose packages from the remove"
- backtitle = "{0} {1}".format(self.meta.__all__,
- self.meta.__version__)
+ backtitle = f"{self.meta.__all__} {self.meta.__version__}"
status = True
pkgs = DialogUtil(packages, text, " Remove ", backtitle,
status).checklist()
@@ -215,16 +216,14 @@ class PackageManager:
else:
for rmv, pkg in zip(removed, packages):
self._sizes(pkg)
- print("[ {0}delete{1} ] --> [ {2} ] - {3}".format(
- self.meta.color["RED"], self.meta.color["ENDC"],
- self.file_size, pkg))
+ print(f"[ {self.red}delete{self.endc} ] --> [ {self.file_size} ] - {pkg}")
self._calc_sizes()
self._remove_summary()
if "--third-party" in self.extra:
print("\n")
self.msg.template(78)
print(("| {0}{1}*** WARNING ***{2}").format(
- " " * 27, self.meta.color["RED"], self.meta.color["ENDC"]))
+ " " * 27, self.red, self.endc))
print("| Before you use third-party option, be sure you have"
" updated the packages \n| lists. Run the command"
" 'slpkg update' and 'slpkg -c slack --upgrade'")
@@ -248,8 +247,7 @@ class PackageManager:
print("\nRemoved summary")
print("=" * 79)
print("{0}Size of removed packages {1} {2}.{3}".format(
- self.meta.color["GREY"], round(self.size, 2), self.unit,
- self.meta.color["ENDC"]))
+ self.grey, round(self.size, 2), self.unit, self.endc))
def _view_deps(self, path, package):
"""View dependencies before remove
@@ -267,8 +265,7 @@ class PackageManager:
if "--checklist" in self.extra:
deps, dependencies = [], []
text = "Found dependencies for the package {0}".format(package)
- backtitle = "{0} {1}".format(self.meta.__all__,
- self.meta.__version__)
+ backtitle = f"{self.meta.__all__} {self.meta.__version__}"
status = True
deps = DialogUtil(packages, text, " Remove ", backtitle,
status).checklist()
@@ -278,19 +275,16 @@ class PackageManager:
else:
print() # new line at start
self.msg.template(78)
- print("| Found dependencies for the package {0}:".format(
- package))
+ print(f"| Found dependencies for the package {package}:")
self.msg.template(78)
for pkg in packages:
find = find_package(pkg + self.meta.sp, self.meta.pkg_path)
self._sizes(find[0])
- print("| {0}{1}{2}".format(self.meta.color["RED"], pkg,
- self.meta.color["ENDC"]))
+ print(f"| {self.red}{pkg}{self.endc}")
self.msg.template(78)
self._calc_sizes()
print("| {0}Size of removed dependencies {1} {2}{3}".format(
- self.meta.color["GREY"], round(self.size, 2), self.unit,
- self.meta.color["ENDC"]))
+ self.grey, round(self.size, 2), self.unit, self.endc))
self.msg.template(78)
return dependencies
@@ -298,8 +292,7 @@ class PackageManager:
"""removepkg Slackware command
"""
try:
- subprocess.call("removepkg {0} {1}".format(self.flag, package),
- shell=True)
+ subprocess.call(f"removepkg {self.flag} {package}", shell=True)
if os.path.isfile(self.dep_path + package):
os.remove(self.dep_path + package) # remove log
except subprocess.CalledProcessError as er:
@@ -354,17 +347,14 @@ class PackageManager:
deps = Utils().read_file(self.dep_path + pkg)
for rmv in removes:
if GetFromInstalled(rmv).name() and rmv in deps.split():
- pkg_dep.append(
- "{0} is dependency of the package --> {1}".format(
- rmv, pkg))
+ pkg_dep.append(f"{rmv} is dependency of the package --> {pkg}")
package.append(pkg)
dependency.append(rmv)
if package:
if "--checklist" in self.extra:
text = ("Press 'spacebar' to choose packages for the"
" remove exception")
- backtitle = "{0} {1}".format(self.meta.__all__,
- self.meta.__version__)
+ backtitle = f"{self.meta.__all__} {self.meta.__version__}"
status = False
choose = DialogUtil(pkg_dep, text, " !!! WARNING !!! ",
backtitle, status).checklist()
@@ -373,15 +363,11 @@ class PackageManager:
else:
self.msg.template(78)
print("| {0}{1}{2}".format(
- self.meta.color["RED"], " " * 30 + "!!! WARNING !!!",
- self.meta.color["ENDC"]))
+ self.red, " " * 30 + "!!! WARNING !!!", self.endc))
self.msg.template(78)
for p, d in zip(package, dependency):
- print("| {0}{1}{2} is dependency of the package --> "
- "{3}{4}{5}".format(self.meta.color["YELLOW"], d,
- self.meta.color["ENDC"],
- self.meta.color["GREEN"], p,
- self.meta.color["ENDC"]))
+ print(f"| {self.yellow}{d}{self.endc} is dependency of the package --> "
+ f"{self.green}{p}{self.endc}")
self.msg.template(78)
self._skip_remove()
@@ -393,13 +379,13 @@ class PackageManager:
msg_pkg = "package"
if len(removes) > 1:
msg_pkg = "packages"
- print("| Total {0} {1} removed".format(len(removes), msg_pkg))
+ print(f"| Total {len(removes)} {msg_pkg} removed")
self.msg.template(78)
for pkg in removes:
if not GetFromInstalled(pkg).name():
- print("| Package {0} removed".format(pkg))
+ print(f"| Package {pkg} removed")
else:
- print("| Package {0} not found".format(pkg))
+ print(f"| Package {pkg} not found")
self.msg.template(78)
print() # new line at end
@@ -410,8 +396,7 @@ class PackageManager:
pkg_cache, match_cache = "", ""
slack_packages, slack_names = slackware_repository()
print("\nPackages with matching name [ {0}{1}{2} ]\n".format(
- self.meta.color["CYAN"], ", ".join(self.binary),
- self.meta.color["ENDC"]))
+ self.cyan, ", ".join(self.binary), self.endc))
for pkg in self.binary:
for match in find_package("", self.meta.pkg_path):
pkg_cache = pkg
@@ -434,9 +419,7 @@ class PackageManager:
for pkgs in packages:
matching += 1
self._sizes(pkgs)
- print("[ {0}installed{1} ] [ {2} ] - {3}".format(
- self.meta.color["GREEN"], self.meta.color["ENDC"],
- self.file_size, pkgs))
+ print(f"[ {self.green}installed{self.endc} ] [ {self.file_size} ] - {pkgs}")
if matching == 0:
message = "Can't find"
self.msg.pkg_not_found("", ", ".join(self.binary), message, "\n")
@@ -446,10 +429,9 @@ class PackageManager:
print("\nFound summary")
print("=" * 79)
print("{0}Total found {1} matching packages.{2}".format(
- self.meta.color["GREY"], matching, self.meta.color["ENDC"]))
+ self.grey, matching, self.endc))
print("{0}Size of installed packages {1} {2}.{3}\n".format(
- self.meta.color["GREY"], round(self.size, 2), self.unit,
- self.meta.color["ENDC"]))
+ self.grey, round(self.size, 2), self.unit, self.endc))
def _sizes(self, package):
"""Package size summary
@@ -472,8 +454,7 @@ class PackageManager:
for pkg in self.binary:
name = GetFromInstalled(pkg).name()
ver = GetFromInstalled(pkg).version()
- find = find_package("{0}{1}{2}".format(name, ver, self.meta.sp),
- self.meta.pkg_path)
+ find = find_package(f"{name}{ver}{self.meta.sp}", self.meta.pkg_path)
if find:
package = Utils().read_file(
self.meta.pkg_path + "".join(find))
@@ -501,28 +482,16 @@ class PackageManager:
print()
for pkg in sorted(pkg_list):
pkg = self._splitting_packages(pkg, repo, name)
- if installed:
- if repo == "sbo":
- if pkg in all_installed_names:
- pkg = ("{0}{1}{2}".format(self.meta.color["GREEN"],
- pkg,
- self.meta.color["ENDC"]))
- else:
- if pkg in all_installed_names:
- pkg = ("{0}{1}{2}".format(self.meta.color["GREEN"],
- pkg,
- self.meta.color["ENDC"]))
+ if installed and repo:
+ if pkg in all_installed_names:
+ pkg = f"{self.green}{pkg}{self.endc}"
+
if INDEX:
index += 1
pkg = self.list_color_tag(pkg)
- print("{0}{1}:{2} {3}".format(
- self.meta.color["GREY"], index,
- self.meta.color["ENDC"], pkg))
+ print(f"{self.grey}{index}:{self.endc} {pkg}")
if index == page:
- read = input("\nPress {0}Enter{1} to "
- "continue... ".format(
- self.meta.color["CYAN"],
- self.meta.color["ENDC"]))
+ read = input(f"\nPress {self.cyan}Enter{self.endc} to continue... ")
if read in ["Q", "q"]:
break
print() # new line after page
@@ -567,14 +536,11 @@ class PackageManager:
packages = ""
if repo == "sbo":
if (os.path.isfile(
- self.meta.lib_path + "{0}_repo/SLACKBUILDS.TXT".format(
- repo))):
- packages = Utils().read_file(self.meta.lib_path + "{0}_repo/"
- "SLACKBUILDS.TXT".format(repo))
+ self.meta.lib_path + f"{repo}_repo/SLACKBUILDS.TXT")):
+ packages = Utils().read_file(self.meta.lib_path + f"{repo}_repo/SLACKBUILDS.TXT")
else:
if (os.path.isfile(
- self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(
- repo))):
+ self.meta.lib_path + f"{repo}_repo/PACKAGES.TXT")):
packages = Utils().read_file(self.meta.lib_path + "{0}_repo/"
"PACKAGES.TXT".format(repo))
return packages
@@ -587,8 +553,7 @@ class PackageManager:
if pkg.endswith(".txz") or pkg.endswith(".tgz"):
find = pkg[:-4]
if find_package(find, self.meta.pkg_path):
- pkg = "{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
- self.meta.color["ENDC"])
+ pkg = f"{self.green}{pkg}{self.endc}"
return pkg
def list_of_installed(self, repo, name):
From be508cfea477cddcf01c21f61b3281703ac8aa3f Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 18 Jan 2020 14:05:36 +0100
Subject: [PATCH 36/40] Added tests
Signed-off-by: Dimitris Zlatanidis
---
tests/test_md5sum.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tests/test_md5sum.py b/tests/test_md5sum.py
index 9f5f0797..a3623d07 100644
--- a/tests/test_md5sum.py
+++ b/tests/test_md5sum.py
@@ -1,6 +1,10 @@
from slpkg.md5sum import md5
-def test_md5():
+def test_md5_superuser():
result = md5('slpkg/superuser.py')
assert result == "e6cebdf37fbc1b8e9d3c5e3e53b300c1"
+
+def test_md5_security():
+ result = md5('slpkg/security.py')
+ assert result == "d395d2fcf1c7b1a91ef6ce3dc8eb047b"
From 830f54b069c77e067ccc6d7c91cc8201ec6adecb Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 18 Jan 2020 15:08:01 +0100
Subject: [PATCH 37/40] Added tests
Signed-off-by: Dimitris Zlatanidis
---
slpkg/sizes.py | 4 +++-
slpkg/utils.py | 7 ++-----
tests/test_md5sum.py | 19 +++++++++++++++++++
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/slpkg/sizes.py b/slpkg/sizes.py
index ec55678a..a5423a69 100644
--- a/slpkg/sizes.py
+++ b/slpkg/sizes.py
@@ -25,6 +25,7 @@
def units(comp_sum, uncomp_sum):
"""Calculate package size
"""
+ print(comp_sum, uncomp_sum)
compressed = round((sum(map(float, comp_sum)) / 1024), 2)
uncompressed = round((sum(map(float, uncomp_sum)) / 1024), 2)
comp_unit = uncomp_unit = "Mb"
@@ -40,4 +41,5 @@ def units(comp_sum, uncomp_sum):
if uncompressed < 1:
uncompressed = sum(map(int, uncomp_sum))
uncomp_unit = "Kb"
- return [comp_unit, uncomp_unit], [compressed, uncompressed]
+ print(comp_unit, uncomp_unit, compressed, uncompressed)
+ return [comp_unit, uncomp_unit], [compressed, uncompressed]
\ No newline at end of file
diff --git a/slpkg/utils.py b/slpkg/utils.py
index b2c5c98a..bde618f4 100644
--- a/slpkg/utils.py
+++ b/slpkg/utils.py
@@ -23,6 +23,7 @@
import os
+from collections import OrderedDict
from slpkg.splitting import split_package
@@ -50,11 +51,7 @@ class Utils:
def remove_dbs(self, double):
"""Remove double item from list
"""
- one = []
- for dup in double:
- if dup not in one:
- one.append(dup)
- return one
+ return list(OrderedDict.fromkeys(double))
def read_file(self, registry):
"""Returns reading file
diff --git a/tests/test_md5sum.py b/tests/test_md5sum.py
index a3623d07..73242a06 100644
--- a/tests/test_md5sum.py
+++ b/tests/test_md5sum.py
@@ -1,10 +1,29 @@
from slpkg.md5sum import md5
+from slpkg.sizes import units
+from slpkg.utils import Utils
def test_md5_superuser():
result = md5('slpkg/superuser.py')
assert result == "e6cebdf37fbc1b8e9d3c5e3e53b300c1"
+
def test_md5_security():
result = md5('slpkg/security.py')
assert result == "d395d2fcf1c7b1a91ef6ce3dc8eb047b"
+
+
+def test_units():
+ assert ["Kb", "Kb"], ["100", "100"] == units(['100', ['100']])
+
+
+def test_dimensional_list():
+ lists = [[1, 2, 3, 4, 5]]
+ utils = Utils()
+ assert [1, 2, 3, 4, 5] == utils.dimensional_list(lists)
+
+
+def test_remove_dbs():
+ lists = [1, 2, 3, 3, 4, 5, 2, 1]
+ utils = Utils()
+ assert [1, 2, 3, 4, 5] == utils.remove_dbs(lists)
\ No newline at end of file
From 0c1ef40bd016c4cbcab1e9c8b5c4cbde0aada06d Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Sat, 18 Jan 2020 16:32:29 +0100
Subject: [PATCH 38/40] Updated tests
Signed-off-by: Dimitris Zlatanidis
---
tests/test_md5sum.py | 20 +-------------------
tests/test_units.py | 5 +++++
tests/test_utils.py | 17 +++++++++++++++++
3 files changed, 23 insertions(+), 19 deletions(-)
create mode 100644 tests/test_units.py
create mode 100644 tests/test_utils.py
diff --git a/tests/test_md5sum.py b/tests/test_md5sum.py
index 73242a06..5adf9dfd 100644
--- a/tests/test_md5sum.py
+++ b/tests/test_md5sum.py
@@ -1,6 +1,4 @@
from slpkg.md5sum import md5
-from slpkg.sizes import units
-from slpkg.utils import Utils
def test_md5_superuser():
@@ -10,20 +8,4 @@ def test_md5_superuser():
def test_md5_security():
result = md5('slpkg/security.py')
- assert result == "d395d2fcf1c7b1a91ef6ce3dc8eb047b"
-
-
-def test_units():
- assert ["Kb", "Kb"], ["100", "100"] == units(['100', ['100']])
-
-
-def test_dimensional_list():
- lists = [[1, 2, 3, 4, 5]]
- utils = Utils()
- assert [1, 2, 3, 4, 5] == utils.dimensional_list(lists)
-
-
-def test_remove_dbs():
- lists = [1, 2, 3, 3, 4, 5, 2, 1]
- utils = Utils()
- assert [1, 2, 3, 4, 5] == utils.remove_dbs(lists)
\ No newline at end of file
+ assert result == "d395d2fcf1c7b1a91ef6ce3dc8eb047b"
\ No newline at end of file
diff --git a/tests/test_units.py b/tests/test_units.py
new file mode 100644
index 00000000..1cb43bdf
--- /dev/null
+++ b/tests/test_units.py
@@ -0,0 +1,5 @@
+from slpkg.sizes import units
+
+
+def test_units():
+ assert ["Kb", "Kb"], ["100", "100"] == units(['100', ['100']])
\ No newline at end of file
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 00000000..fce14d11
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,17 @@
+from slpkg.utils import Utils
+
+
+def test_units():
+ assert ["Kb", "Kb"], ["100", "100"] == units(['100', ['100']])
+
+
+def test_dimensional_list():
+ lists = [[1, 2, 3, 4, 5]]
+ utils = Utils()
+ assert [1, 2, 3, 4, 5] == utils.dimensional_list(lists)
+
+
+def test_remove_dbs():
+ lists = [1, 2, 3, 3, 4, 5, 2, 1]
+ utils = Utils()
+ assert [1, 2, 3, 4, 5] == utils.remove_dbs(lists)
\ No newline at end of file
From 9b6b5dbfff4800c227df03cd14ce2ef44ce57db1 Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 20 Jan 2020 18:50:40 +0100
Subject: [PATCH 39/40] Updated for f string
Signed-off-by: Dimitris Zlatanidis
---
clean.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clean.py b/clean.py
index 4b8d4e2e..16c4ee13 100755
--- a/clean.py
+++ b/clean.py
@@ -49,11 +49,11 @@ class Clean:
def start(self):
for f in self.files:
if os.path.isfile(f):
- print("Remove file --> {0}".format(f))
+ print(f"Remove file --> {f}")
os.remove(f)
for d in self.dirs:
if os.path.exists(d):
- print("Remove directory --> {0}".format(d))
+ print(f"Remove directory --> {d}")
shutil.rmtree(d)
From e816763ca6a7f2ead3f0d8d33958f603b0ddd0de Mon Sep 17 00:00:00 2001
From: Dimitris Zlatanidis
Date: Mon, 20 Jan 2020 20:29:18 +0100
Subject: [PATCH 40/40] Updated for f string
Signed-off-by: Dimitris Zlatanidis
---
slpkg/graph.py | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/slpkg/graph.py b/slpkg/graph.py
index aa3b2606..0b18b58a 100644
--- a/slpkg/graph.py
+++ b/slpkg/graph.py
@@ -63,24 +63,23 @@ class Graph:
G = pgv.AGraph(deps_dict)
G.layout(prog="fdp")
if self.image == "ascii":
- G.write("{0}.dot".format(self.image))
+ G.write(f"{self.image}.dot")
self.graph_easy()
G.draw(self.image)
except IOError:
raise SystemExit()
if os.path.isfile(self.image):
- print("Graph image file '{0}' created".format(self.image))
+ print(f"Graph image file '{self.image}' created")
raise SystemExit()
def check_file(self):
"""Check for file format and type
"""
try:
- image_type = ".{0}".format(self.image.split(".")[1])
+ image_type = f".{self.image.split('.')[1]}"
if image_type not in self.file_format:
- print("Format: '{0}' not recognized. Use one of "
- "them:\n{1}".format(self.image.split(".")[1],
- ", ".join(self.file_format)))
+ print(f"Format: '{self.image.split('.')[1]}' not recognized. Use one of "
+ f"them:\n{', '.join(self.file_format)}")
raise SystemExit()
except IndexError:
print("slpkg: Error: Image file suffix missing")