diff --git a/ChangeLog.txt b/ChangeLog.txt index 1b7935f3..b961babd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,12 @@ +3.8.2 - 15/02/2020 +Fixed: +- SBo repository view Packages and New version +- msb repository PACKAGES.txt file +BugFix: +- Upgrade distribution with option -c, --check +Added: +- Managing multi packages in blacklist file + 3.8.1 - 13/02/2020 Fixed: - Bugfix double install packages from slack regular repo diff --git a/EXAMPLES.md b/EXAMPLES.md index 04c0797b..5fc1ab78 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -1175,8 +1175,7 @@ $ slpkg -q install (install packages from queue) $ slpkg -q build-install (build and install) ``` -Add or remove the packages in blacklist file manually from '`/etc/slpkg/blacklist`' or -with the following options: +Add or remove packages in blacklist file manually from the '`/etc/slpkg/blacklist`' file or with the following options: ``` $ slpkg -b live555 speex faac --add diff --git a/README.md b/README.md index 56ea6be5..14e9a60a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# slpkg 3.8.1 +# slpkg 3.8.2 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/conf/blacklist b/conf/blacklist index 0a5c3895..8615a8d1 100644 --- a/conf/blacklist +++ b/conf/blacklist @@ -10,6 +10,9 @@ # To blacklist the package 'wicd-1.7.2.4-x86_64-4.txz' the line will be: # wicd # +# To blacklist packages that start with name add * the end of the name: +# kernel* +# # # Sometimes the automatic kernel update creates problems because you # may need to file intervention 'lilo'. The slpkg automatically detects diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index 2be4e835..1d316e12 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -76,7 +76,7 @@ class MetaData: __all__ = "slpkg" __author__ = "dslackw" - __version_info__ = (3, 8, 1) + __version_info__ = (3, 8, 2) __version__ = "{0}.{1}.{2}".format(*__version_info__) __license__ = "GNU General Public License v3 (GPLv3)" __email__ = "d.zlatanidis@gmail.com" diff --git a/slpkg/binary/check.py b/slpkg/binary/check.py index dbc85f0a..004c9842 100644 --- a/slpkg/binary/check.py +++ b/slpkg/binary/check.py @@ -38,7 +38,8 @@ from slpkg.binary.repo_init import RepoInit def pkg_upgrade(repo, skip, flag): """Checking packages for upgrade """ - Msg().checking() + msg = Msg() + msg.checking() PACKAGES_TXT = RepoInit(repo).fetch()[0] pkgs_for_upgrade = [] # name = data[0] @@ -57,7 +58,7 @@ def pkg_upgrade(repo, skip, flag): inst_pkg[0] not in skip and repo_pkg[1] != "blacklist"): pkgs_for_upgrade.append(repo_pkg[0]) - Msg().done() + msg.done() if "--checklist" in flag: pkgs_for_upgrade = choose_upg(pkgs_for_upgrade) return pkgs_for_upgrade diff --git a/slpkg/binary/greps.py b/slpkg/binary/greps.py index f47d5915..27dc5b56 100644 --- a/slpkg/binary/greps.py +++ b/slpkg/binary/greps.py @@ -44,7 +44,7 @@ def repo_data(PACKAGES_TXT, repo, flag): if line.startswith("PACKAGE SIZE (uncompressed):"): unsize.append(line[30:-2].strip()) - if repo == "slack": + if repo == "slack" and "--upgrade" not in flag: (rname, rlocation, rsize, diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index 9852d432..6d4d8303 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -47,11 +47,12 @@ from slpkg.binary.repo_init import RepoInit from slpkg.binary.dependency import Dependencies -class BinaryInstall: +class BinaryInstall(BlackList): """Install binaries packages with all dependencies from repository """ def __init__(self, packages, repo, flag): + super().__init__() self.packages = packages pkg_security(packages) self.repo = repo @@ -63,6 +64,7 @@ class BinaryInstall: self.yellow = _meta_.color['YELLOW'] self.endc = _meta_.color["ENDC"] self.msg = Msg() + self.utils = Utils() self.version = self.meta.slack_rel self.tmp_path = self.meta.slpkg_tmp_packages self.init_flags() @@ -79,7 +81,7 @@ class BinaryInstall: self.repo_pkg_names = [] for name in self.data[0]: self.repo_pkg_names.append(split_package(name)[0]) - self.blacklist = BlackList().get_black() + self.blacklist = list(self.get_black()) self.matching = False def init_flags(self): @@ -159,10 +161,10 @@ class BinaryInstall: self.msg.template(78) if "--download-only" in self.flag: raise SystemExit() - self.dep_install = Utils().check_downloaded( - self.tmp_path, self.dep_install) - self.install = Utils().check_downloaded( - self.tmp_path, self.install) + self.dep_install = list(self.utils.check_downloaded( + self.tmp_path, self.dep_install)) + self.install = list(self.utils.check_downloaded( + self.tmp_path, self.install)) ins, upg = self.install_packages() self.msg.reference(ins, upg) write_deps(self.deps_dict) @@ -188,8 +190,8 @@ class BinaryInstall: lowercase """ if "--case-ins" in self.flag: - data = list(Utils().package_name(self.PACKAGES_TXT)) - data_dict = Utils().case_sensitive(data) + data = list(self.utils.package_name(self.PACKAGES_TXT)) + data_dict = self.utils.case_sensitive(data) for pkg in self.packages: index = self.packages.index(pkg) for key, value in data_dict.items(): @@ -200,7 +202,7 @@ class BinaryInstall: """Update dependencies dictionary with all package """ for dep in self.dependencies: - deps = Utils().dimensional_list(Dependencies( + deps = self.utils.dimensional_list(Dependencies( self.repo, self.blacklist).binary( dep, self.flag)) self.deps_dict[dep] = deps @@ -210,7 +212,7 @@ class BinaryInstall: or if added to install two or more times """ packages = [] - for mas in Utils().remove_dbs(self.packages): + for mas in self.utils.remove_dbs(self.packages): if mas not in self.dependencies: packages.append(mas) self.packages = packages @@ -264,11 +266,11 @@ class BinaryInstall: self.msg.resolving() for dep in self.packages: dependencies = [] - dependencies = Utils().dimensional_list(Dependencies( + dependencies = self.utils.dimensional_list(Dependencies( self.repo, self.blacklist).binary(dep, self.flag)) requires += list(self._fix_deps_repos(dependencies)) - self.deps_dict[dep] = Utils().remove_dbs(requires) - return Utils().remove_dbs(requires) + self.deps_dict[dep] = self.utils.remove_dbs(requires) + return self.utils.remove_dbs(requires) def _fix_deps_repos(self, dependencies): """Fix store deps include in repository diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py index 4aa548d5..8fb3ef09 100644 --- a/slpkg/binary/search.py +++ b/slpkg/binary/search.py @@ -33,6 +33,6 @@ def search_pkg(name, repo): """ PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT") names = list(Utils().package_name(PACKAGES_TXT)) - blacklist = BlackList().get_black() + blacklist = list(BlackList().get_black()) if name in names and name not in blacklist: return name \ No newline at end of file diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 4146c3c9..425d7870 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -25,10 +25,11 @@ import os from slpkg.utils import Utils +from slpkg.splitting import split_package from slpkg.__metadata__ import MetaData as _meta_ -class BlackList: +class BlackList(Utils): """Blacklist class to add, remove or listed packages in blacklist file.""" def __init__(self): @@ -38,30 +39,43 @@ class BlackList: self.blackfile = "/etc/slpkg/blacklist" self.black_conf = "" if os.path.isfile(self.blackfile): - self.black_conf = Utils().read_file(self.blackfile) + self.black_conf = self.read_file(self.blackfile) def get_black(self): """Return blacklist packages from /etc/slpkg/blacklist configuration file.""" - blacklist = [] + blacklist = list(self.black_filter()) + installed = os.listdir("/var/log/packages/") + + for black in blacklist: + if black.endswith("*"): + for inst in installed: + if inst.startswith(black[:-1]): + yield split_package(inst)[0] + else: + yield black + + def black_filter(self): + """Return all the installed files that start + by the name* + """ for read in self.black_conf.splitlines(): read = read.lstrip() if not read.startswith("#"): - blacklist.append(read.replace("\n", "")) - return blacklist + yield read.replace("\n", "") - def listed(self): + def black_listed(self): """Print blacklist packages """ print("Packages in the blacklist:\n") - for black in self.get_black(): + for black in list(self.black_filter()): if black: print(f"{self.green}{black}{self.endc}") - def add(self, pkgs): + def black_add(self, pkgs): """Add blacklist packages if not exist """ - blacklist = self.get_black() + blacklist = list(self.black_filter()) pkgs = set(pkgs) print("Add packages in the blacklist:\n") with open(self.blackfile, "a") as black_conf: @@ -70,7 +84,7 @@ class BlackList: print(f"{self.green}{pkg}{self.endc}") black_conf.write(pkg + "\n") - def remove(self, pkgs): + def black_remove(self, pkgs): """Remove packages from blacklist """ print("Remove packages from the blacklist:\n") diff --git a/slpkg/checksum.py b/slpkg/checksum.py index 0a362988..4004e46c 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -30,6 +30,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def check_md5(pkg_md5, src_file): """MD5 Checksum """ + msg = Msg() red = _meta_.color["RED"] green = _meta_.color["GREEN"] endc = _meta_.color["ENDC"] @@ -37,19 +38,19 @@ def check_md5(pkg_md5, src_file): print() md5s = md5(src_file) if pkg_md5 != md5s: - Msg().template(78) + msg.template(78) print(f"| MD5SUM check for {src_file.split('/')[-1]}" f" [ {red}FAILED{endc} ]") - Msg().template(78) + msg.template(78) print(f"| Expected: {pkg_md5}") print(f"| Found: {md5s}") - Msg().template(78) + msg.template(78) print() if not Msg().answer() in ["y", "Y"]: raise SystemExit() else: - Msg().template(78) + msg.template(78) print(f"| MD5SUM check for {src_file.split('/')[-1]}" f" [ {green}PASSED{endc} ]") - Msg().template(78) + msg.template(78) print() # new line after pass checksum diff --git a/slpkg/clean.py b/slpkg/clean.py index 5f20369e..97c8d9f9 100644 --- a/slpkg/clean.py +++ b/slpkg/clean.py @@ -39,11 +39,10 @@ def clean_tmp(): # Delete a whole slpkg folder from the tmp directory if os.path.exists(tmps[0]): shutil.rmtree(tmps[0]) - print("All packages and sources were deleted from: {0}".format( - tmps[0])) + print(f"All packages and sources were deleted from: {tmps[0]}") # Recreate the paths again if not os.path.exists(tmps[0]): for tmp in tmps: - print("Created directory: {0}".format(tmp)) + print(f"Created directory: {tmp}") os.mkdir(tmp) - print("Done!") + print("Done!") \ No newline at end of file diff --git a/slpkg/config.py b/slpkg/config.py index 9cac90d7..f3bda84b 100644 --- a/slpkg/config.py +++ b/slpkg/config.py @@ -36,6 +36,7 @@ class Config: def __init__(self): self.config_file = "/etc/slpkg/slpkg.conf" self.meta = _meta_ + self.utils = Utils() self.green = _meta_.color["GREEN"] self.red = _meta_.color["RED"] self.cyan = _meta_.color["CYAN"] @@ -66,11 +67,10 @@ class Config: "DOWNDER_OPTIONS", "SLACKPKG_LOG", "ONLY_INSTALLED", - "PRG_BAR", "EDITOR", "NOT_DOWNGRADE" ] - read_conf = Utils().read_file(self.config_file) + read_conf = self.utils.read_file(self.config_file) for line in read_conf.splitlines(): if not line.startswith("#") and line.split("=")[0] in conf_args: print(line) @@ -89,4 +89,4 @@ class Config: if filecmp.cmp(f"{self.config_file}.orig", self.config_file): print(f"{self.green}The reset was done{self.endc}") else: - print(f"{self.red}Reset failed{self.endc}") + print(f"{self.red}Reset failed{self.endc}") \ No newline at end of file diff --git a/slpkg/desc.py b/slpkg/desc.py index 00267752..d2d43caf 100644 --- a/slpkg/desc.py +++ b/slpkg/desc.py @@ -38,6 +38,7 @@ class PkgDesc: self.paint = paint self.meta = _meta_ self.msg = Msg() + self.utils = Utils() self.lib = "" self.color = { "red": self.meta.color["RED"], @@ -57,10 +58,10 @@ class PkgDesc: if self.repo == "sbo": description = SBoGrep(self.name).description() else: - PACKAGES_TXT = Utils().read_file(self.lib) + PACKAGES_TXT = self.utils.read_file(self.lib) for line in PACKAGES_TXT.splitlines(): if line.startswith(self.name + ":"): - description += line[len(self.name) + 2:] + "\n" + description += f"{line[len(self.name) + 2:]}\n" count += 1 if count == 11: break diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index 41a8eb6d..dfa1278e 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -31,11 +31,7 @@ class DialogUtil: """Create dialog checklist """ def __init__(self, *args): - try: - from dialog import Dialog - except ImportError: - raise SystemExit() - self.d = Dialog(dialog="dialog", autowidgetsize=True) + self.imp_dialog() self.data = args[0] self.text = args[1] self.title = args[2] @@ -44,6 +40,13 @@ class DialogUtil: self.ununicode = [] self.tags = [] + def imp_dialog(self): + try: + from dialog import Dialog + except ImportError: + raise SystemExit() + self.d = Dialog(dialog="dialog", autowidgetsize=True) + def checklist(self): """Run dialog checklist """ diff --git a/slpkg/graph.py b/slpkg/graph.py index 47ad3f7c..49d142f1 100644 --- a/slpkg/graph.py +++ b/slpkg/graph.py @@ -78,8 +78,8 @@ class Graph: try: image_type = f".{self.image.split('.')[1]}" if image_type not in self.file_format: - print(f"Format: '{self.image.split('.')[1]}' not recognized. Use one of " - f"them:\n{', '.join(self.file_format)}") + print(f"Format: '{self.image.split('.')[1]}' not recognized." + f" Use one of them:\n{', '.join(self.file_format)}") raise SystemExit() except IndexError: print("slpkg: Error: Image file suffix missing") @@ -89,8 +89,8 @@ class Graph: """Draw ascii diagram. graph-easy perl module require """ if not os.path.isfile("/usr/bin/graph-easy"): - print("Require 'graph-easy': Install with 'slpkg -s sbo " - "graph-easy'") + print("Require 'graph-easy': Install with 'slpkg -s sbo" + " graph-easy'") self.remove_dot() raise SystemExit() subprocess.call(f"graph-easy {self.image}.dot", shell=True) diff --git a/slpkg/health.py b/slpkg/health.py index 4072dbdd..da408b11 100644 --- a/slpkg/health.py +++ b/slpkg/health.py @@ -73,7 +73,7 @@ class PackageHealth: self.packages() self.cf = 0 for pkg in self.installed: - if os.path.isfile(self.meta.pkg_path + pkg): + if os.path.isfile(f"{self.meta.pkg_path}{pkg}"): self.lf = 0 with open(self.pkg_path + pkg, "r") as fopen: for line in fopen: diff --git a/slpkg/init.py b/slpkg/init.py index aa59d08d..d1a2b9fa 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -527,7 +527,7 @@ class Initialization: version = self.meta.msb_sub_repo[1:-1] if self.meta.slack_rel == "current": ver_slack = self.meta.slack_rel - PACKAGES_TXT = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}" + PACKAGES_TXT = f"{repo}{ver_slack}/{version}/{ar}/{lib_file}" FILELIST_TXT = "" CHECKSUMS_MD5 = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}" ChangeLog_txt = f"{repo}{log_file}" @@ -709,30 +709,42 @@ class Initialization: return True return False - def upgrade(self, only): - """Remove all package lists with changelog and checksums files - and create lists again""" + +class Upgrade: + + def __init__(self): + self.meta = _meta_ + self.log_path = self.meta.log_path + self.lib_path = self.meta.lib_path + + def run(self, repos): + """Removing and creating the packages lists + """ repositories = self.meta.repositories - if only: - repositories = only + + # Replace the enabled repositories from user defined + if repos: + repositories = repos + for repo in repositories: changelogs = f"{self.log_path}{repo}/ChangeLog.txt" if os.path.isfile(changelogs): os.remove(changelogs) - if os.path.isdir(self.lib_path + f"{repo}_repo/"): - for f in (os.listdir(self.lib_path + f"{repo}_repo/")): + + if os.path.isdir(f"{self.lib_path}{repo}_repo/"): + for f in os.listdir(f"{self.lib_path}{repo}_repo/"): files = f"{self.lib_path}{repo}_repo/{f}" if os.path.isfile(files): os.remove(files) elif os.path.isdir(files): shutil.rmtree(files) - Update().repository(only) + update = Update() + update.run(repos) class Update: def __init__(self): - self.initialization = globals()['Initialization'](False) self.meta = _meta_ self.grey = _meta_.color["GREY"] self.red = _meta_.color["RED"] @@ -741,21 +753,23 @@ class Update: self.done = f"{self.grey}Done{self.endc}\n" self.error = f"{self.red}Error{self.endc}\n" - def repository(self, only): + def run(self, repos): """Update repositories lists """ print("\nCheck and update repositories:\n") default = self.meta.default_repositories enabled = self.meta.repositories - if only: - enabled = only + + # Replace the enabled repositories from user defined + if repos: + enabled = repos + for repo in enabled: if check_for_local_repos(repo) is True: continue 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() + getattr(Initialization(False), repo)() print(self.done, end="") elif repo in enabled: Initialization(False).custom(repo) @@ -776,7 +790,6 @@ def check_exists_repositories(repo): 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))): return repo return "" @@ -788,4 +801,4 @@ def check_for_local_repos(repo): if repo in repos_dict: repo_url = repos_dict[repo] if repo_url.startswith("file:///"): - return True + return True \ No newline at end of file diff --git a/slpkg/load.py b/slpkg/load.py index 44a93be5..19135e37 100644 --- a/slpkg/load.py +++ b/slpkg/load.py @@ -34,15 +34,18 @@ from slpkg.pkg.find import find_package def library(repo): """Load packages from slpkg library and from local """ + utils = Utils() pkg_list, packages = [], "" if repo == "sbo": if (os.path.isfile( f"{_meta_.lib_path}{repo}_repo/SLACKBUILDS.TXT")): - packages = Utils().read_file(f"{_meta_.lib_path}{repo}_repo/SLACKBUILDS.TXT") + packages = utils.read_file( + f"{_meta_.lib_path}{repo}_repo/SLACKBUILDS.TXT") else: if (os.path.isfile( f"{_meta_.lib_path}{repo}_repo/PACKAGES.TXT")): - packages = Utils().read_file(f"{_meta_.lib_path}{repo}_repo/PACKAGES.TXT") + packages = utils.read_file( + f"{_meta_.lib_path}{repo}_repo/PACKAGES.TXT") for line in packages.splitlines(): if repo == "sbo": if line.startswith("SLACKBUILD NAME: "): diff --git a/slpkg/log_deps.py b/slpkg/log_deps.py index bb6f1a71..123dc0f2 100644 --- a/slpkg/log_deps.py +++ b/slpkg/log_deps.py @@ -34,13 +34,13 @@ def write_deps(deps_dict): into directory `/var/log/slpkg/dep/` """ for name, dependencies in deps_dict.items(): - if find_package(name + _meta_.sp, _meta_.pkg_path): - dep_path = _meta_.log_path + "dep/" + if find_package(f"{name}-", _meta_.pkg_path): + dep_path = f"{_meta_.log_path}dep/" if not os.path.exists(dep_path): os.mkdir(dep_path) - if os.path.isfile(dep_path + name): - os.remove(dep_path + name) + if os.path.isfile(f"{dep_path}{name}"): + os.remove(f"{dep_path}{name}") if len(dependencies) >= 1: - with open(dep_path + name, "w") as f: + with open(f"{dep_path}{name}", "w") as f: for dep in dependencies: - f.write(dep + "\n") + f.write(f"{dep}\n") \ No newline at end of file diff --git a/slpkg/main.py b/slpkg/main.py index fc144b0e..5adab7c7 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -48,7 +48,7 @@ from slpkg.status_deps import DependenciesStatus from slpkg.init import ( Update, - Initialization, + Upgrade, check_exists_repositories ) from slpkg.__metadata__ import MetaData as _meta_ @@ -66,9 +66,10 @@ from slpkg.binary.check import pkg_upgrade from slpkg.binary.install import BinaryInstall -class ArgParse: +class ArgParse(BlackList): def __init__(self, args): + super().__init__() self.args = args self.meta = _meta_ self.msg = Msg() @@ -121,15 +122,32 @@ class ArgParse: def command_update(self): """Update package lists repositories """ + update = Update() if len(self.args) == 1 and self.args[0] == "update": - Update().repository(only="") + update.run(repos="") elif (len(self.args) == 2 and self.args[0] == "update" and self.args[1].startswith("--repositories=")): repos = self.args[1].split("=")[-1].split(",") for rp in repos: if rp not in self.meta.repositories: repos.remove(rp) - Update().repository(repos) + update.run(repos) + else: + usage("") + + def command_upgrade(self): + """Recreate repositories package lists + """ + upgrade = Upgrade() + if len(self.args) == 1 and self.args[0] == "upgrade": + upgrade.run(repos="") + elif (len(self.args) == 2 and self.args[0] == "upgrade" and + self.args[1].startswith("--repositories=")): + repos = self.args[1].split("=")[-1].split(",") + for rp in repos: + if rp not in self.meta.repositories: + repos.remove(rp) + upgrade.run(repos) else: usage("") @@ -174,21 +192,6 @@ class ArgParse: else: usage("") - def command_upgrade(self): - """Recreate repositories package lists - """ - if len(self.args) == 1 and self.args[0] == "upgrade": - Initialization(False).upgrade(only="") - elif (len(self.args) == 2 and self.args[0] == "upgrade" and - self.args[1].startswith("--repositories=")): - repos = self.args[1].split("=")[-1].split(",") - for rp in repos: - if rp not in self.meta.repositories: - repos.remove(rp) - Initialization(False).upgrade(repos) - else: - usage("") - def command_repo_info(self): """Repositories informations """ @@ -317,7 +320,7 @@ class ArgParse: BinaryInstall(pkg_upgrade("slack", skip, flag), "slack", flag).start(is_upgrade=True) else: - Patches(skip, flag).start() + Patches(skip, flags[0]).start() elif self.args[1] == "sbo": SBoInstall(sbo_upgrade(skip, flag), flag).start( is_upgrade=True) @@ -460,7 +463,6 @@ class ArgParse: def pkg_blacklist(self): """Manage blacklist packages """ - blacklist = BlackList() options = [ "-b", "--blacklist" @@ -472,19 +474,19 @@ class ArgParse: command = ["list"] if (len(self.args) == 2 and self.args[0] in options and self.args[1] == command[0]): - blacklist.listed() + self.black_listed() elif (len(self.args) > 2 and self.args[0] in options and flag[0] in self.args): self.args.remove(flag[0]) - blacklist.add(self.args[1:]) + self.black_add(self.args[1:]) elif (len(self.args) == 2 and self.args[0] in options and flag[1] in self.args): self.args.remove(flag[1]) - blacklist.remove(blacklist.get_black()) + self.black_remove(list(self.get_black())) elif (len(self.args) > 2 and self.args[0] in options and flag[1] in self.args): self.args.remove(flag[1]) - blacklist.remove(self.args[1:]) + self.black_remove(self.args[1:]) else: usage("") diff --git a/slpkg/messages.py b/slpkg/messages.py index 1dbaf3e1..0150b7d5 100644 --- a/slpkg/messages.py +++ b/slpkg/messages.py @@ -158,4 +158,4 @@ class Msg: """Message for matching packages """ 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 + "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 871804bc..ce8cf1a4 100644 --- a/slpkg/new_config.py +++ b/slpkg/new_config.py @@ -51,7 +51,7 @@ class NewConfig: """ self.find_new() for n in self.news: - print(f"{n}") + print(n) print() self.msg.template(78) print(f"| Installed {len(self.news)} new configuration files:") diff --git a/slpkg/pkg/find.py b/slpkg/pkg/find.py index 8dffd840..f70979f6 100644 --- a/slpkg/pkg/find.py +++ b/slpkg/pkg/find.py @@ -32,7 +32,7 @@ def searching(find_pkg, directory): """ if os.path.isdir(directory): installed = os.listdir(directory) - blacklist = BlackList().get_black() + blacklist = list(BlackList().get_black()) if os.path.exists(directory): for pkg in installed: if (not pkg.startswith(".") and pkg.startswith(find_pkg) and diff --git a/slpkg/remove.py b/slpkg/remove.py index 63824961..4c288755 100644 --- a/slpkg/remove.py +++ b/slpkg/remove.py @@ -34,7 +34,7 @@ def delete_package(path, packages): """ if _meta_.del_all in ["on", "ON"]: for pkg in packages: - os.remove(path + pkg) + os.remove(f"{path}{pkg}") def delete_folder(folder): diff --git a/slpkg/repoenable.py b/slpkg/repoenable.py index 22b1782a..3b60ea8e 100644 --- a/slpkg/repoenable.py +++ b/slpkg/repoenable.py @@ -112,15 +112,15 @@ Keys: SPACE select or deselect the highlighted repositories, if self.tag_line and line.startswith("#"): repo = "".join(line.split("#")).strip() if repo in self.selected: - new_conf.write(line.replace(line, repo + "\n")) + new_conf.write(line.replace(line, f"{repo}\n")) continue if (self.tag_line and not line.startswith("#") and line != self.tag): repo = line.strip() if repo not in self.selected: - new_conf.write(line.replace(line, "# " + line + "\n")) + new_conf.write(line.replace(line, f"# {line}\n")) continue - new_conf.write(line + "\n") + new_conf.write(f"{line}\n") def clear_screen(self): """Clear screen diff --git a/slpkg/repoinfo.py b/slpkg/repoinfo.py index f64380b0..018abf81 100644 --- a/slpkg/repoinfo.py +++ b/slpkg/repoinfo.py @@ -31,13 +31,14 @@ from slpkg.repolist import RepoList from slpkg.__metadata__ import MetaData as _meta_ -class RepoInfo: +class RepoInfo(Utils): """Repository information """ def __init__(self): self.green = _meta_.color["GREEN"] self.red = _meta_.color["RED"] self.endc = _meta_.color["ENDC"] + self.repo = Repo() self.form = { "Last updated:": "", "Number of packages:": "", @@ -49,9 +50,9 @@ class RepoInfo: "Total uncompressed packages:": "" } self.meta = _meta_ - self.all_repos = Repo().default_repository() - self.all_repos["slack"] = Repo().slack() - self.all_repos.update(Repo().custom_repository()) + self.all_repos = self.repo.default_repository() + self.all_repos["slack"] = self.repo.slack() + self.all_repos.update(self.repo.custom_repository()) del RepoList().all_repos def view(self, repo): @@ -66,7 +67,7 @@ class RepoInfo: self.form["Default:"] = "yes" if (repo in self.meta.repositories and - os.path.isfile(self.meta.lib_path + f"{repo}_repo/PACKAGES.TXT")): + os.path.isfile(f"{self.meta.lib_path}{repo}_repo/PACKAGES.TXT")): status = f"{self.green}enabled{self.endc}" if repo != "sbo": @@ -81,19 +82,20 @@ class RepoInfo: self.form["Number of packages:"] = data[0] self.form["Status:"] = status self.form["Last updated:"] = data[3] + elif (repo == "sbo" and os.path.isfile( - self.meta.lib_path + f"{repo}_repo/SLACKBUILDS.TXT")): + f"{self.meta.lib_path}{repo}_repo/SLACKBUILDS.TXT")): status = f"{self.green}enabled{self.endc}" sum_sbo_pkgs = 0 - for line in (Utils().read_file( - self.meta.lib_path + "sbo_repo/SLACKBUILDS." + for line in (self.read_file( + f"{self.meta.lib_path}sbo_repo/SLACKBUILDS." "TXT").splitlines()): if line.startswith("SLACKBUILD NAME: "): sum_sbo_pkgs += 1 - changelog_txt = Utils().read_file( - self.meta.log_path + "sbo/ChangeLog.txt") + changelog_txt = self.read_file( + f"{self.meta.log_path}sbo/ChangeLog.txt") last_upd = changelog_txt.split("\n", 1)[0] self.form["Repo id:"] = repo @@ -108,13 +110,12 @@ class RepoInfo: print(f"{self.green}{key}{self.endc} {value}") def repository_data(self, repo): - """ - Grap data packages + """Grap data packages """ sum_pkgs, size, unsize, last_upd = 0, [], [], "" f = f"{self.meta.lib_path}{repo}_repo/PACKAGES.TXT" - for line in Utils().read_file(f).splitlines(): + for line in self.read_file(f).splitlines(): if line.startswith("PACKAGES.TXT;"): last_upd = line[14:].strip() if line.startswith("PACKAGE NAME:"): @@ -125,8 +126,8 @@ class RepoInfo: unsize.append(line[30:-2].strip()) if repo in ["salix", "slackl"]: - log = Utils().read_file( - self.meta.log_path + f"{repo}/ChangeLog.txt") + log = self.read_file( + f"{self.meta.log_path}{repo}/ChangeLog.txt") last_upd = log.split("\n", 1)[0] return [sum_pkgs, size, unsize, last_upd] \ No newline at end of file diff --git a/slpkg/repositories.py b/slpkg/repositories.py index 160e4884..5b74dcdc 100644 --- a/slpkg/repositories.py +++ b/slpkg/repositories.py @@ -28,7 +28,7 @@ from slpkg.utils import Utils from slpkg.__metadata__ import MetaData as _meta_ -class Repo: +class Repo(Utils): """Manage repositories configuration files """ def __init__(self): @@ -36,9 +36,9 @@ class Repo: self.DEFAULT_REPOS_NAMES = self.meta.default_repositories self.custom_repo_file = "/etc/slpkg/custom-repositories" self.default_repo_file = "/etc/slpkg/default-repositories" - self.custom_repositories_list = Utils().read_file( + self.custom_repositories_list = self.read_file( self.custom_repo_file) - self.default_repositories_list = Utils().read_file( + self.default_repositories_list = self.read_file( self.default_repo_file) self.default_repository() @@ -47,27 +47,25 @@ class Repo: """ repo_name = [] if not url.endswith("/"): - url = url + "/" + url += "/" for line in self.custom_repositories_list.splitlines(): line = line.lstrip() if line and not line.startswith("#"): repo_name.append(line.split()[0]) if (repo in self.meta.repositories or repo in repo_name or repo in self.meta.default_repositories): - print("\nRepository name '{0}' exist, select different name.\n" + print(f"\nRepository name '{repo}' exist, select different name.\n" "View all repositories with command 'slpkg " - "repo-list'.\n".format(repo)) - raise SystemExit() + "repo-list'.\n") + raise SystemExit(1) elif len(repo) > 6: print("\nslpkg: Error: Maximum repository name length must be " "six (6) characters\n") - raise SystemExit() + raise SystemExit(1) with open(self.custom_repo_file, "a") as repos: - new_line = " {0}{1}{2}\n".format(repo, " " * (10 - len(repo)), - url) + new_line = f" {repo}{' ' * (10 - len(repo))}{url}\n" repos.write(new_line) - print("\nRepository '{0}' successfully added\n".format(repo)) - raise SystemExit() + print(f"\nRepository '{repo}' successfully added\n") def remove(self, repo): """Remove custom repository @@ -77,14 +75,13 @@ class Repo: for line in self.custom_repositories_list.splitlines(): repo_name = line.split()[0] if repo_name != repo: - repos.write(line + "\n") + repos.write(f"{line}\n") else: - print("\nRepository '{0}' successfully " - "removed\n".format(repo)) + print(f"\nRepository '{repo}' successfully " + "removed\n") rem_repo = True if not rem_repo: - print("\nRepository '{0}' doesn't exist\n".format(repo)) - raise SystemExit() + print(f"\nRepository '{repo}' doesn't exist\n") def custom_repository(self): """Return dictionary with repo name and url (used external) @@ -106,11 +103,10 @@ class Repo: if line.split()[0] in self.DEFAULT_REPOS_NAMES: default_dict_repo[line.split()[0]] = line.split()[1] else: - print("\nslpkg: Error: Repository name '{0}' is not " - "default.\n Please check file: " - "/etc/slpkg/default-repositories\n".format( - line.split()[0])) - raise SystemExit() + print(f"\nslpkg: Error: Repository name '{line.split()[0]}'" + " is not default.\n Please check file: " + "/etc/slpkg/default-repositories\n") + raise SystemExit(1) return default_dict_repo def slack(self): @@ -120,12 +116,12 @@ class Repo: if self.meta.arch.startswith("arm"): default = "http://ftp.arm.slackware.com/slackwarearm/" if os.path.isfile("/etc/slpkg/slackware-mirrors"): - mirrors = Utils().read_file( - self.meta.conf_path + "slackware-mirrors") + mirrors = self.read_file( + f"{self.meta.conf_path}slackware-mirrors") for line in mirrors.splitlines(): line = line.rstrip() if not line.startswith("#") and line: default = line.split()[-1] if not default.endswith("/"): default += "/" - return default + return default \ No newline at end of file diff --git a/slpkg/sbo/check.py b/slpkg/sbo/check.py index 3c8d5db6..abbda538 100644 --- a/slpkg/sbo/check.py +++ b/slpkg/sbo/check.py @@ -41,7 +41,7 @@ def sbo_upgrade(skip, flag): msg.checking() upgrade_names = [] data = SBoGrep(name="").names() - blacklist = BlackList().get_black() + blacklist = list(BlackList().get_black()) for pkg in sbo_list(): name = split_package(pkg)[0] ver = split_package(pkg)[1] diff --git a/slpkg/sbo/compressed.py b/slpkg/sbo/compressed.py index 09f9c065..ad669c76 100644 --- a/slpkg/sbo/compressed.py +++ b/slpkg/sbo/compressed.py @@ -29,7 +29,6 @@ class SBoLink: self.sbo_url = sbo_url def tar_gz(self): + """Return link slackbuild tar.gz archive """ - Return link slackbuild tar.gz archive - """ - return (self.sbo_url[:-1] + ".tar.gz") + return f"{self.sbo_url[:-1]}.tar.gz" diff --git a/slpkg/sbo/dependency.py b/slpkg/sbo/dependency.py index c06a14e4..febf9347 100644 --- a/slpkg/sbo/dependency.py +++ b/slpkg/sbo/dependency.py @@ -30,14 +30,15 @@ from slpkg.__metadata__ import MetaData as _meta_ from slpkg.sbo.greps import SBoGrep -class Requires: +class Requires(BlackList): """Resolving SBo dependencies """ def __init__(self, flag): + super().__init__() self.flag = flag self.meta = _meta_ self.SLACKBUILDS_TXT = SBoGrep(name="").names() - self.blacklist = BlackList().get_black() + self.blacklist = list(self.get_black()) self.dep_results = [] def sbo(self, name): diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py index 75385c1f..97adcce7 100644 --- a/slpkg/sbo/network.py +++ b/slpkg/sbo/network.py @@ -48,11 +48,12 @@ from slpkg.sbo.slack_find import slack_package from slpkg.slack.slack_version import slack_ver -class SBoNetwork: +class SBoNetwork(BlackList): """View SBo site in terminal and also read, build or install packages """ def __init__(self, name, flag): + super().__init__() self.name = name self.flag = flag self.meta = _meta_ @@ -76,7 +77,6 @@ class SBoNetwork: self.with_checklist() grep = SBoGrep(self.name) self.sbo_files = grep.files() - self.blacklist = BlackList().get_black() self.sbo_url = sbo_search_pkg(self.name) if self.sbo_url: self.sbo_desc = grep.description()[len(self.name) + 2:-1] @@ -92,7 +92,7 @@ class SBoNetwork: """View SlackBuild package, read or install them from slackbuilds.org """ - if self.sbo_url and self.name not in self.blacklist: + if self.sbo_url and self.name not in self.get_black(): self.prgnam = f"{self.name}-{self.sbo_version}" self.view_sbo() while True: diff --git a/slpkg/sbo/search.py b/slpkg/sbo/search.py index 1436af11..7d6472db 100644 --- a/slpkg/sbo/search.py +++ b/slpkg/sbo/search.py @@ -30,9 +30,10 @@ from slpkg.slack.slack_version import slack_ver def sbo_search_pkg(name): - """Search for package path from SLACKBUILDS.TXT file and + """Search for package path in SLACKBUILDS.TXT file and return url """ + url = "" repo = Repo().default_repository()["sbo"] sbo_url = f"{repo}{slack_ver()}/" SLACKBUILDS_TXT = Utils().read_file( @@ -41,5 +42,5 @@ def sbo_search_pkg(name): if line.startswith("SLACKBUILD LOCATION"): sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip() if name == sbo_name: - return (sbo_url + line[23:].strip() + "/") - return "" + url = f"{sbo_url}{line[23:].strip()}/" + return url diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py index 0e887f84..78021dc3 100644 --- a/slpkg/sbo/slackbuild.py +++ b/slpkg/sbo/slackbuild.py @@ -25,7 +25,6 @@ import os from pkg_resources import parse_version - from slpkg.utils import Utils from slpkg.messages import Msg from slpkg.log_deps import write_deps @@ -48,10 +47,11 @@ from slpkg.sbo.search import sbo_search_pkg from slpkg.sbo.slack_find import slack_package -class SBoInstall: +class SBoInstall(BlackList, Utils): """Build and install SBo packages with all dependencies """ def __init__(self, slackbuilds, flag): + super().__init__() self.slackbuilds = slackbuilds pkg_security(self.slackbuilds) self.flag = flag @@ -80,7 +80,7 @@ class SBoInstall: self.count_uni = 0 self.msg.reading() self.data = SBoGrep(name="").names() - self.blacklist = BlackList().get_black() + self.blacklist = list(self.get_black()) def init_flags(self): """Flags initialization @@ -172,7 +172,7 @@ class SBoInstall: lowercase """ if "--case-ins" in self.flag: - data_dict = Utils().case_sensitive(self.data) + data_dict = self.case_sensitive(self.data) for name in self.slackbuilds: index = self.slackbuilds.index(name) for key, value in data_dict.items(): @@ -182,10 +182,9 @@ 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 = self.dimensional_list(self.deps) + dependencies = self.remove_dbs(onelist) for dep in dependencies: deps = Requires(self.flag).sbo(dep) self.deps_dict[dep] = self.one_for_all(deps) @@ -213,7 +212,7 @@ class SBoInstall: """Clear master slackbuilds if already exist in dependencies or if added to install two or more times """ - self.master_packages = Utils().remove_dbs(self.master_packages) + self.master_packages = self.remove_dbs(self.master_packages) for mas in self.master_packages: if mas in self.dependencies: self.master_packages.remove(mas) @@ -246,8 +245,8 @@ class SBoInstall: deps.reverse() # Inverting the list brings the # dependencies in order to be installed. - requires = Utils().dimensional_list(deps) - dependencies = Utils().remove_dbs(requires) + requires = self.dimensional_list(deps) + dependencies = self.remove_dbs(requires) return dependencies def top_view(self): @@ -270,7 +269,7 @@ class SBoInstall: args[3] arch """ ver = GetFromInstalled(args[1]).version() - print(f" {args[0]}{args[1] + ver}{self.endc}" + 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]))}{''}" diff --git a/slpkg/security.py b/slpkg/security.py index b53a0a3f..5fe8fab5 100644 --- a/slpkg/security.py +++ b/slpkg/security.py @@ -30,7 +30,7 @@ def pkg_security(pkgs): """Check packages before install or upgrade for security reasons. Configuration file in the /etc/slpkg/pkg_security""" security_packages = Utils().read_file("/etc/slpkg/pkg_security") - packages = [] + packages, msg = [], Msg() for read in security_packages.splitlines(): read = read.lstrip() if not read.startswith("#"): @@ -38,6 +38,6 @@ def pkg_security(pkgs): for p in pkgs: for pkg in packages: if p == pkg: - Msg().security_pkg(p) - if not Msg().answer() in ["y", "Y"]: + msg.security_pkg(p) + if not msg.answer() in ["y", "Y"]: raise SystemExit() diff --git a/slpkg/slack/mirrors.py b/slpkg/slack/mirrors.py index d05a2e08..f5d70974 100644 --- a/slpkg/slack/mirrors.py +++ b/slpkg/slack/mirrors.py @@ -29,9 +29,8 @@ from slpkg.slack.slack_version import slack_ver def mirrors(name, location): - """ - Select Slackware official mirror packages - based architecture and version. + """Select Slackware official mirror packages + based architecture and version. """ rel = _meta_.slack_rel ver = slack_ver() diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py index 6b145bb3..bfeb841c 100644 --- a/slpkg/slack/patches.py +++ b/slpkg/slack/patches.py @@ -50,10 +50,11 @@ from slpkg.slack.mirrors import mirrors from slpkg.slack.slack_version import slack_ver -class Patches: +class Patches(BlackList): """Upgrade distribution from official Slackware mirrors """ def __init__(self, skip, flag): + super().__init__() self.skip = skip self.flag = flag self.meta = _meta_ @@ -83,8 +84,7 @@ class Patches: self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "")).reading() def start(self): - """ - Install new patches from official Slackware mirrors + """Install new patches from official Slackware mirrors """ self.store() self.msg.done() @@ -111,8 +111,8 @@ class Patches: if self.msg.answer() in ["y", "Y"]: Download(self.patch_path, self.dwn_links, repo="slack").start() - self.upgrade_all = self.utils.check_downloaded( - self.patch_path, self.upgrade_all) + self.upgrade_all = list(self.utils.check_downloaded( + self.patch_path, self.upgrade_all)) self.upgrade() self.kernel() if self.meta.slackpkg_log in ["on", "ON"]: @@ -131,11 +131,10 @@ class Patches: f" distribution is up to date!\n") def store(self): - """ - Store and return packages for upgrading + """Store and return packages for upgrading """ data = repo_data(self.PACKAGES_TXT, "slack", self.flag) - black = BlackList().get_black() + black = list(self.get_black()) for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]): repo_pkg_name = split_package(name)[0] if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and @@ -179,8 +178,7 @@ class Patches: raise SystemExit() def views(self): - """ - Views packages + """Views packages """ for upg, size in sorted(zip(self.upgrade_all, self.comp_sum)): pkg_repo = split_package(upg[:-4]) @@ -196,8 +194,7 @@ class Patches: f"{' ' * (7-len(pkg_repo[3]))}Slack{size:>12} K") def upgrade(self): - """ - Upgrade packages + """Upgrade packages """ for pkg in self.upgrade_all: check_md5(pkg_checksum(pkg, "slack_patches"), @@ -216,8 +213,7 @@ class Patches: self.installed.append(pkg_ver) def kernel(self): - """ - Check if kernel upgraded if true + """Check if kernel upgraded if true then reinstall "lilo" """ for core in self.upgrade_all: @@ -253,13 +249,13 @@ class Patches: from Slackware official mirrors after update distribution. """ 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") - if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt"): - shutil.copy2(self.meta.slackpkg_lib_path + "ChangeLog.txt", - self.meta.slackpkg_lib_path + "ChangeLog.txt.old") - os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt") - with open(self.meta.slackpkg_lib_path + "ChangeLog.txt", "w") as log: + if os.path.isfile(f"{self.meta.slackpkg_lib_path}ChangeLog.txt.old"): + os.remove(f"{self.meta.slackpkg_lib_path}ChangeLog.txt.old") + if os.path.isfile(f"{self.meta.slackpkg_lib_path}ChangeLog.txt"): + shutil.copy2(f"{self.meta.slackpkg_lib_path}ChangeLog.txt", + f"{self.meta.slackpkg_lib_path}ChangeLog.txt.old") + os.remove(f"{self.meta.slackpkg_lib_path}ChangeLog.txt") + with open(f"{self.meta.slackpkg_lib_path}ChangeLog.txt", "w") as log: log.write(NEW_ChangeLog_txt) def update_lists(self): @@ -269,4 +265,4 @@ class Patches: print(f"{self.green}Update the package lists ?{self.endc}") print("=" * 79) if self.msg.answer() in ["y", "Y"]: - Update().repository(["slack"]) + Update().run(["slack"]) diff --git a/slpkg/slack/slackware_repo.py b/slpkg/slack/slackware_repo.py index 5a177d09..5b4fe2ff 100644 --- a/slpkg/slack/slackware_repo.py +++ b/slpkg/slack/slackware_repo.py @@ -31,12 +31,11 @@ from slpkg.__metadata__ import MetaData as _meta_ def slackware_repository(): """Return all official Slackware packages """ - slack_repo, packages, names, name = [], [], [], "" + slack_repo, packages, names = [], [], [] slack_repo = repo_data( Utils().read_file(f"{_meta_.lib_path}slack_repo/PACKAGES.TXT"), "slack", "") for pkg in slack_repo[0]: - name = split_package(pkg)[0] - names.append(name) + names.append(split_package(pkg)[0]) packages.append(pkg[:-4]) - return packages, names + return packages, names \ No newline at end of file diff --git a/slpkg/slpkg_update.py b/slpkg/slpkg_update.py index cc123a7e..349a9f00 100644 --- a/slpkg/slpkg_update.py +++ b/slpkg/slpkg_update.py @@ -62,7 +62,7 @@ def it_self_update(): answer = input("Would you like to upgrade [y/N]? ") except EOFError: print() - raise SystemExit() + raise SystemExit(1) if answer in ["y", "Y"]: print() # new line after answer else: @@ -78,17 +78,16 @@ def it_self_update(): os.makedirs(_meta_.build_path) Download(_meta_.build_path, dwn_link, repo="").start() os.chdir(_meta_.build_path) - slpkg_tar_file = "slpkg" + "-" + __new_version__ + ".tar.gz" + slpkg_tar_file = f"slpkg-{__new_version__}.tar.gz" tar = tarfile.open(slpkg_tar_file) tar.extractall() tar.close() - file_name = "{0}-{1}".format(_meta_.__all__, __new_version__) + file_name = f"{_meta_.__all__}-{__new_version__}" os.chdir(file_name) check_md5(pkg_checksum(slpkg_tar_file, _meta_.__all__), _meta_.build_path + slpkg_tar_file) subprocess.call("chmod +x {0}".format("install.sh"), shell=True) subprocess.call("sh install.sh", shell=True) else: - print("\n{0}: There is no new version, already used the last!" - "\n".format(_meta_.__all__)) - raise SystemExit() + print(f"\n{_meta_.__all__}: There is no new version, already used the last!\n") + raise SystemExit() \ No newline at end of file diff --git a/slpkg/status_deps.py b/slpkg/status_deps.py index 2861d851..94f4fa9f 100644 --- a/slpkg/status_deps.py +++ b/slpkg/status_deps.py @@ -40,6 +40,7 @@ class DependenciesStatus: self.image = image self.meta = _meta_ self.msg = Msg() + self.utils = Utils() self.grey = self.meta.color["GREY"] self.green = self.meta.color["GREEN"] self.endc = self.meta.color["ENDC"] @@ -57,10 +58,10 @@ class DependenciesStatus: dictionary database """ for pkg in self.installed: - if os.path.isfile(self.meta.pkg_path + pkg): + if os.path.isfile(f"{self.meta.pkg_path}{pkg}"): name = split_package(pkg)[0] for log in self.logs: - deps = Utils().read_file(self.dep_path + log) + deps = self.utils.read_file(f"{self.dep_path}{log}") for dep in deps.splitlines(): if name == dep: if name not in self.dmap.keys(): @@ -86,7 +87,7 @@ class DependenciesStatus: self.data() print() self.msg.template(78) - print("| {0}{1}{2}".format("Dependencies", " " * 20, "Packages")) + print(f"| Dependencies{' ' * 20}Packages") self.msg.template(78) for key, value in self.dmap.items(): print(" {0}{1}{2}{3}{4}".format( @@ -105,12 +106,12 @@ class DependenciesStatus: self.msg.template(78) self.data() for pkg, dep in self.dmap.items(): - print("+ {0}{1}{2}".format(self.green, pkg, self.endc)) + print(f"+ {self.green}{pkg}{self.endc}") print("|") for d in dep: - print("+-- {0}".format(d)) + print(f"+-- {d}") print("|") - print("\x1b[1A{0}\n".format(" "), end="", flush=True) + print("\x1b[1A \n", end="", flush=True) self.summary() if self.image: Graph(self.image).dependencies(self.dmap) diff --git a/slpkg/superuser.py b/slpkg/superuser.py index 0c6ec6ec..9c642e7e 100644 --- a/slpkg/superuser.py +++ b/slpkg/superuser.py @@ -30,4 +30,4 @@ def s_user(): """ if getpass.getuser() != "root": print("\nslpkg: Error: Must have root privileges\n") - raise SystemExit() + raise SystemExit(1) diff --git a/slpkg/tracking.py b/slpkg/tracking.py index 414daf39..9af75eae 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -38,18 +38,20 @@ from slpkg.binary.search import search_pkg from slpkg.binary.dependency import Dependencies -class TrackingDeps: +class TrackingDeps(BlackList): """View tree of dependencies and also highlight packages with color green if already installed and color red if not installed. """ def __init__(self, name, repo, flag): + super().__init__() self.name = name self.repo = repo self.flag = flag self.meta = _meta_ self.msg = Msg() + self.utils = Utils() self.green = self.meta.color["GREEN"] self.yellow = self.meta.color["YELLOW"] self.cyan = self.meta.color["CYAN"] @@ -59,6 +61,11 @@ class TrackingDeps: self.dependencies = [] self.dependencies_list = [] self.deps_dict = {} + self.init_flags() + + def init_flags(self): + """Flags initialization + """ for i in range(0, len(self.flag)): if self.flag[i].startswith("--graph="): self.image = self.flag[i].split("=")[1] @@ -71,8 +78,8 @@ class TrackingDeps: self.repositories() if self.find_pkg: self.dependencies_list.reverse() - self.requires = Utils().dimensional_list(self.dependencies_list) - self.dependencies = Utils().remove_dbs(self.requires) + self.requires = self.utils.dimensional_list(self.dependencies_list) + self.dependencies = self.utils.remove_dbs(self.requires) if self.dependencies == []: self.dependencies = ["No dependencies"] if "--graph=" in self.flag: @@ -123,13 +130,13 @@ class TrackingDeps: if self.find_pkg: self.dependencies_list = Requires(self.flag).sbo(self.name) else: - PACKAGES_TXT = Utils().read_file( - self.meta.lib_path + f"{self.repo}_repo/PACKAGES.TXT") - self.names = list(Utils().package_name(PACKAGES_TXT)) + PACKAGES_TXT = self.utils.read_file( + f"{self.meta.lib_path}{self.repo}_repo/PACKAGES.TXT") + self.names = list(self.utils.package_name(PACKAGES_TXT)) self.bin_case_insensitive() self.find_pkg = search_pkg(self.name, self.repo) if self.find_pkg: - self.black = BlackList().get_black() + self.black = list(self.get_black()) self.dependencies_list = Dependencies( self.repo, self.black).binary(self.name, self.flag) @@ -139,7 +146,7 @@ class TrackingDeps: """ if "--case-ins" in self.flag: data = SBoGrep(name="").names() - data_dict = Utils().case_sensitive(data) + data_dict = self.utils.case_sensitive(data) for key, value in data_dict.items(): if key == self.name.lower(): self.name = value @@ -149,7 +156,7 @@ class TrackingDeps: lowercase """ if "--case-ins" in self.flag: - data_dict = Utils().case_sensitive(self.names) + data_dict = self.utils.case_sensitive(self.names) for key, value in data_dict.items(): if key == self.name.lower(): self.name = value @@ -163,10 +170,10 @@ class TrackingDeps: """Check if dependencies used """ used = [] - dep_path = self.meta.log_path + "dep/" + dep_path = f"{self.meta.log_path}dep/" logs = find_package("", dep_path) for log in logs: - deps = Utils().read_file(dep_path + log) + deps = self.utils.read_file(f"{dep_path}{log}") for dep in deps.splitlines(): if pkg == dep: used.append(log) @@ -180,17 +187,17 @@ class TrackingDeps: for dep in dependencies: deps = Requires(flag="").sbo(dep) if dep not in self.deps_dict.values(): - self.deps_dict[dep] = Utils().dimensional_list(deps) + self.deps_dict[dep] = self.utils.dimensional_list(deps) else: for dep in dependencies: deps = Dependencies(self.repo, self.black).binary(dep, flag="") if dep not in self.deps_dict.values(): - self.deps_dict[dep] = Utils().dimensional_list(deps) + self.deps_dict[dep] = self.utils.dimensional_list(deps) def deps_used(self, pkg, used): """Create dependencies dictionary """ - if find_package(pkg + self.meta.sp, self.meta.pkg_path): + if find_package(f"{pkg}-", self.meta.pkg_path): if pkg not in self.deps_dict.values(): self.deps_dict[pkg] = used else: diff --git a/slpkg/utils.py b/slpkg/utils.py index fe4dedb1..1f1eaa36 100644 --- a/slpkg/utils.py +++ b/slpkg/utils.py @@ -70,15 +70,13 @@ class Utils: if line.startswith("PACKAGE NAME:"): yield split_package(line[14:].strip())[0] - def check_downloaded(self, path, maybe_downloaded): + def check_downloaded(self, path, downloaded): """Check if files downloaded and return downloaded packages """ - downloaded = [] - for pkg in maybe_downloaded: - if os.path.isfile(path + pkg): - downloaded.append(pkg) - return downloaded + for pkg in downloaded: + if os.path.isfile(f"{path}{pkg}"): + yield pkg def read_config(self, config): """Read config file and returns first uncomment line @@ -103,7 +101,7 @@ class Utils: """Checking the file encoding default is utf-8 """ try: - with open(path + f, "r") as ftest: + with open(f"{path}{f}", "r") as ftest: ftest.read() except UnicodeDecodeError: return "ISO-8859-1" diff --git a/slpkg/version.py b/slpkg/version.py index e45b2b81..734468d7 100644 --- a/slpkg/version.py +++ b/slpkg/version.py @@ -22,20 +22,15 @@ # along with this program. If not, see . -from slpkg.__metadata__ import MetaData as _meta_ +from slpkg.__metadata__ import MetaData as m def prog_version(): """Print version, license and email """ - print("Version : {0}\n" - "Licence : {1}\n" - "Email : {2}\n" - "Homepage : {3}\n" - "Twitter : {4}\n" - "Maintainer: {5}".format(_meta_.__version__, - _meta_.__license__, - _meta_.__email__, - _meta_.__homepage__, - _meta_.__twitter__, - _meta_.__maintainer__)) + print(f"Version : {m.__version__}\n" + f"Licence : {m.__license__}\n" + f"Email : {m.__email__}\n" + f"Homepage : {m.__homepage__}\n" + f"Twitter : {m.__twitter__}\n" + f"Maintainer: {m.__maintainer__}") diff --git a/tests/test_md5sum.py b/tests/test_md5sum.py index 71109f9a..bf11cb01 100644 --- a/tests/test_md5sum.py +++ b/tests/test_md5sum.py @@ -3,9 +3,9 @@ from slpkg.md5sum import md5 def test_md5_superuser(): result = md5('slpkg/superuser.py') - assert result == "25ec85aa9c2803ece6397e4147449ea6" + assert result == "c6a3576c247bda199c75b43540bfc3d7" def test_md5_security(): result = md5('slpkg/security.py') - assert result == "3f10bf99b21f66af879dc0882bcd92b3" + assert result == "36c3a9213a27ab0b49e9c1bdd5bd2db6" diff --git a/tests/test_utils.py b/tests/test_utils.py index 17aa5352..aa8ab3d7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -10,4 +10,4 @@ def test_dimensional_list(): 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) + assert [1, 2, 3, 4, 5] == utils.remove_dbs(lists) \ No newline at end of file