From 290e3a01c75bdae6942d23bd602eaf0d9d83cabd Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sat, 28 May 2022 17:31:52 +0300 Subject: [PATCH 01/23] Fixed complexity --- slpkg/sbo/greps.py | 50 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index f7b4be56..34d19fa4 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -32,19 +32,17 @@ class SBoGrep(Utils): def __init__(self, name): self.name = name self.meta = _meta_ - arch64 = "x86_64" + self.arch64 = "x86_64" self.line_name = "SLACKBUILD NAME: " self.line_files = "SLACKBUILD FILES: " self.line_down = "SLACKBUILD DOWNLOAD: " - self.line_down_64 = f"SLACKBUILD DOWNLOAD_{arch64}: " + self.line_down_64 = f"SLACKBUILD DOWNLOAD_{self.arch64}: " self.line_req = "SLACKBUILD REQUIRES: " self.line_ver = "SLACKBUILD VERSION: " self.line_md5 = "SLACKBUILD MD5SUM: " - self.line_md5_64 = f"SLACKBUILD MD5SUM_{arch64}: " + self.line_md5_64 = f"SLACKBUILD MD5SUM_{self.arch64}: " self.line_des = "SLACKBUILD SHORT DESCRIPTION: " self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT" - self.answer = ["y", "Y"] - self.unst = ["UNSUPPORTED", "UNTESTED"] self.SLACKBUILDS_TXT = self.read_file(self.sbo_txt) def _names_grabbing(self): @@ -73,25 +71,7 @@ class SBoGrep(Utils): if line.startswith(self.line_down_64): if sbo_name == self.name and line[28:].strip(): source64 = line[28:] - return self._select_source_arch(source, source64) - - def _select_source_arch(self, source, source64): - """Return sources by arch - """ - src = "" - if self.meta.arch == "x86_64": - if source64: - src = source64 - else: - src = source - if self.meta.skip_unst in self.answer and source64 in self.unst: - src = source - else: - if source: - src = source - if self.meta.skip_unst in self.answer and source in self.unst: - src = source64 - return src + return self._sorting_arch(source, source64) def requires(self): """Grab package requirements @@ -126,20 +106,7 @@ class SBoGrep(Utils): if line.startswith(self.line_md5): if sbo_name == self.name and line[19:].strip(): md5sum = line[19:].strip().split() - return self._select_md5sum_arch(md5sum, md5sum64) - - def _select_md5sum_arch(self, md5sum, md5sum64): - """Return checksums by arch - """ - if md5sum and md5sum64: - if self.meta.arch == "x86_64": - return md5sum64 - else: - return md5sum - if md5sum: - return md5sum - else: - return md5sum64 + return self._sorting_arch(md5sum, md5sum64) def description(self): """Grab package version @@ -160,3 +127,10 @@ class SBoGrep(Utils): if line.startswith(self.line_files): if sbo_name == self.name: return line[18:].strip() + + def _sorting_arch(self, arch, arch64): + """Return sources by arch + """ + if self.meta.arch == self.arch64 and arch64: + return arch64 + return arch From df3da1ea846cb2e9c1d1a4459bb40de9d7f116d8 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 00:16:55 +0300 Subject: [PATCH 02/23] Switch to sqlite3 --- slpkg/__metadata__.py | 3 + slpkg/init.py | 31 +++++++++ slpkg/models/__init.py__ | 0 slpkg/models/models.py | 110 +++++++++++++++++++++++++++++++ slpkg/sbo/greps.py | 138 ++++++++++++++++++++++++++------------- 5 files changed, 238 insertions(+), 44 deletions(-) create mode 100644 slpkg/models/__init.py__ create mode 100644 slpkg/models/models.py diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index 99c42418..22794666 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -241,6 +241,9 @@ class MetaData: # slackpkg lib path slackpkg_lib_path = "/var/lib/slackpkg/" + # database name + db = "database.slpkg" + # computer architecture if comp_arch in ["off", "OFF"]: arch = os.uname()[4] diff --git a/slpkg/init.py b/slpkg/init.py index fc6666ba..0202c69c 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -24,6 +24,8 @@ import os import shutil +import sqlite3 +from models.models import Database from slpkg.utils import Utils from slpkg.repositories import Repo @@ -54,6 +56,7 @@ class Initialization(Utils): self.slpkg_tmp_packages = self.meta.slpkg_tmp_packages self.slpkg_tmp_patches = self.meta.slpkg_tmp_patches self.constructing() + self.database() def constructing(self): """Creating the all necessary directories @@ -75,6 +78,15 @@ class Initialization(Utils): self.make_dir(paths_basic) self.make_dirs(paths_extra) + def database(self): + """Initializing the database + """ + self.db = "database.slpkg" + db_lib = self.lib_path + "database/" + self.make_dirs([db_lib]) + self.con = sqlite3.connect(db_lib + self.db) + self.cur = self.con.cursor() + def make_dir(self, path: list): for p in path: if not os.path.exists(p): @@ -626,6 +638,9 @@ class Initialization(Utils): self.down(lib_path, CHECKSUMS_MD5, repo) self.down(lib_path, FILELIST_TXT, repo) self.down(log_path, ChangeLog_txt, repo) + if repo == 'sbo': + self.cur.execute("DROP TABLE IF EXISTS sbo") + self.con.commit() def merge(self, path, outfile, infiles): """Merge files @@ -728,14 +743,30 @@ class Update: else: print(self.error, end="") print() # new line at end + self.check_db() raise SystemExit() + def check_db(self): + sbo_db = Database("sbo", "SLACKBUILDS.TXT") + if sbo_db.table_exists() == 0: + sbo_db.create_sbo_table() + sbo_db.insert_sbo_table() + def done_msg(self, repo): print(f"{self.grey}Check repository " f"[{self.cyan}{repo}{self.grey}] ... " f"{self.endc}", end="", flush=True) +def database(text_file): + db_lib = _meta_.lib_path + "database" + init = Initialization(False) + init.make_dirs([db_lib]) + data = Database("sbo", text_file) + data.create_sbo_table() + data.insert_sbo_table() + + def check_exists_repositories(repo): """Checking if repositories exists by PACKAGES.TXT file """ diff --git a/slpkg/models/__init.py__ b/slpkg/models/__init.py__ new file mode 100644 index 00000000..e69de29b diff --git a/slpkg/models/models.py b/slpkg/models/models.py new file mode 100644 index 00000000..696114f2 --- /dev/null +++ b/slpkg/models/models.py @@ -0,0 +1,110 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +# models.py file is part of slpkg. + +# Copyright 2014-2022 Dimitris Zlatanidis +# All rights reserved. + +# Slpkg is a user-friendly package manager for Slackware installations + +# https://gitlab.com/dslackw/slpkg + +# Slpkg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import sqlite3 +from progress.bar import Bar +from slpkg.__metadata__ import MetaData as _meta_ + + +class Database: + + def __init__(self, table_name, text_file): + self.lib_path = _meta_.lib_path + self.table_name = table_name + self.text_file = text_file + self.db = _meta_.db + self.con = sqlite3.connect(f'{self.lib_path}database/{self.db}') + self.cur = self.con.cursor() + + def table_exists(self): + self.cur.execute("""SELECT count(name) + FROM sqlite_master + WHERE type='table' + AND name='{}'""".format(self.table_name)) + return self.cur.fetchone()[0] + + def create_sbo_table(self): + self.cur.execute('''CREATE TABLE IF NOT EXISTS {} + (name text, location text, files text, version text, + download text, download64 text, md5sum text, + md5sum64 text, requires text, short_desc text) + '''.format(self.table_name)) + self.con.commit() + + def insert_sbo_table(self): + self.sbo = [ + 'SLACKBUILD NAME:', + 'SLACKBUILD LOCATION:', + 'SLACKBUILD FILES:', + 'SLACKBUILD VERSION:', + 'SLACKBUILD DOWNLOAD:', + 'SLACKBUILD DOWNLOAD_x86_64:', + 'SLACKBUILD MD5SUM:', + 'SLACKBUILD MD5SUM_x86_64:', + 'SLACKBUILD REQUIRES:', + 'SLACKBUILD SHORT DESCRIPTION:' + ] + + sbo_file = self.open_file(f"{self.lib_path}sbo_repo/SLACKBUILDS.TXT") + + bar = Bar("Database sbo creating", max=len(sbo_file), + suffix='%(percent)d%% - %(eta)ds') + for i, line in enumerate(sbo_file, 1): + + if line.startswith(self.sbo[0]): + name = line.replace(self.sbo[0], '').strip() + if line.startswith(self.sbo[1]): + location = line.replace(self.sbo[1], '').strip() + if line.startswith(self.sbo[2]): + files = line.replace(self.sbo[2], '').strip() + if line.startswith(self.sbo[3]): + version = line.replace(self.sbo[3], '').strip() + if line.startswith(self.sbo[4]): + download = line.replace(self.sbo[4], '').strip() + if line.startswith(self.sbo[5]): + download64 = line.replace(self.sbo[5], '').strip() + if line.startswith(self.sbo[6]): + md5sum = line.replace(self.sbo[6], '').strip() + if line.startswith(self.sbo[7]): + md5sum64 = line.replace(self.sbo[7], '').strip() + if line.startswith(self.sbo[8]): + requires = line.replace(self.sbo[8], '').strip() + if line.startswith(self.sbo[9]): + short_desc = line.replace(self.sbo[9], '').strip() + + if i % 11 == 0: + values = [(name, location, files, version, download, + download64, md5sum, md5sum64, requires, short_desc), + ] + self.cur.executemany("""INSERT INTO {} VALUES + (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""".format( + self.table_name), values) + self.con.commit() + bar.next() + bar.finish() + self.con.close() + + def open_file(self, file): + with open(file, 'r', encoding='utf-8') as f: + return f.readlines() diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 34d19fa4..542cc513 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -22,6 +22,7 @@ # along with this program. If not, see . +import sqlite3 from slpkg.utils import Utils from slpkg.__metadata__ import MetaData as _meta_ @@ -32,6 +33,7 @@ class SBoGrep(Utils): def __init__(self, name): self.name = name self.meta = _meta_ + self.db = self.meta.db self.arch64 = "x86_64" self.line_name = "SLACKBUILD NAME: " self.line_files = "SLACKBUILD FILES: " @@ -43,6 +45,9 @@ class SBoGrep(Utils): self.line_md5_64 = f"SLACKBUILD MD5SUM_{self.arch64}: " self.line_des = "SLACKBUILD SHORT DESCRIPTION: " self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT" + self.sbo_db = f"{self.meta.lib_path}database/{self.db}" + self.con = sqlite3.connect(self.sbo_db) + self.cur = self.con.cursor() self.SLACKBUILDS_TXT = self.read_file(self.sbo_txt) def _names_grabbing(self): @@ -61,72 +66,117 @@ class SBoGrep(Utils): def source(self): """Grab sources downloads links """ - source, source64, = "", "" - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - sbo_name = line[17:].strip() - if line.startswith(self.line_down): - if sbo_name == self.name and line[21:].strip(): - source = line[21:] - if line.startswith(self.line_down_64): - if sbo_name == self.name and line[28:].strip(): - source64 = line[28:] +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# sbo_name = line[17:].strip() +# if line.startswith(self.line_down): +# if sbo_name == self.name and line[21:].strip(): +# source = line[21:] +# if line.startswith(self.line_down_64): +# if sbo_name == self.name and line[28:].strip(): +# source64 = line[28:] + + source, source64 = self.cur.execute("""SELECT download, download64 + FROM sbo + WHERE name = '{}'""".format( + self.name)).fetchone() return self._sorting_arch(source, source64) def requires(self): """Grab package requirements """ - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - sbo_name = line[17:].strip() - if line.startswith(self.line_req): - if sbo_name == self.name: - return line[21:].strip().split() + requires = self.cur.execute("""SELECT requires + FROM sbo + WHERE name = '{}'""".format( + self.name)).fetchone() + return requires[0].split() + +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# sbo_name = line[17:].strip() +# if line.startswith(self.line_req): +# if sbo_name == self.name: +# # print(line[21:].strip().split()) +# return line[21:].strip().split() def version(self): """Grab package version """ - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - sbo_name = line[17:].strip() - if line.startswith(self.line_ver): - if sbo_name == self.name: - return line[20:].strip() + version = self.cur.execute("""SELECT version + FROM sbo + WHERE name = '{}'""".format( + self.name)).fetchone() + return version[0] + +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# sbo_name = line[17:].strip() +# if line.startswith(self.line_ver): +# if sbo_name == self.name: +# print(line[20:].strip()) +# +# return line[20:].strip() def checksum(self): """Grab checksum string """ md5sum, md5sum64, = [], [] - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - sbo_name = line[17:].strip() - if line.startswith(self.line_md5_64): - if sbo_name == self.name and line[26:].strip(): - md5sum64 = line[26:].strip().split() - if line.startswith(self.line_md5): - if sbo_name == self.name and line[19:].strip(): - md5sum = line[19:].strip().split() + mds5, md5s64 = self.cur.execute("""SELECT md5sum, md5sum64 + FROM sbo + WHERE name = '{}'""".format( + self.name)).fetchone() + if mds5: + md5sum.append(mds5) + if md5s64: + md5sum64.append(md5s64) return self._sorting_arch(md5sum, md5sum64) +# md5sum, md5sum64, = [], [] +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# sbo_name = line[17:].strip() +# if line.startswith(self.line_md5_64): +# if sbo_name == self.name and line[26:].strip(): +# md5sum64 = line[26:].strip().split() +# if line.startswith(self.line_md5): +# if sbo_name == self.name and line[19:].strip(): +# md5sum = line[19:].strip().split() +# print(md5sum, md5sum64) +# return self._sorting_arch(md5sum, md5sum64) + def description(self): - """Grab package version + """Grab package description """ - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - sbo_name = line[17:].strip() - if line.startswith(self.line_des): - if sbo_name == self.name: - return line[31:].strip() + desc = self.cur.execute("""SELECT short_desc + FROM sbo + WHERE name = '{}'""".format( + self.name)).fetchone() + return desc[0] + +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# sbo_name = line[17:].strip() +# if line.startswith(self.line_des): +# if sbo_name == self.name: +# print(line[31:].strip()) +# +# return line[31:].strip() def files(self): """Grab files """ - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - sbo_name = line[17:].strip() - if line.startswith(self.line_files): - if sbo_name == self.name: - return line[18:].strip() + files = self.cur.execute("""SELECT files + FROM sbo + WHERE name = '{}'""".format( + self.name)).fetchone() + return files[0] + +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# sbo_name = line[17:].strip() +# if line.startswith(self.line_files): +# if sbo_name == self.name: +# return line[18:].strip() def _sorting_arch(self, arch, arch64): """Return sources by arch From 6cb10873fb692faa4cafa781b3a6043a498ca700 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 00:25:45 +0300 Subject: [PATCH 03/23] Updated style --- slpkg/models/models.py | 56 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/slpkg/models/models.py b/slpkg/models/models.py index 696114f2..92747d94 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -34,64 +34,68 @@ class Database: self.table_name = table_name self.text_file = text_file self.db = _meta_.db - self.con = sqlite3.connect(f'{self.lib_path}database/{self.db}') + self.con = sqlite3.connect(f"{self.lib_path}database/{self.db}") self.cur = self.con.cursor() def table_exists(self): + """Checking if the table exists + """ self.cur.execute("""SELECT count(name) FROM sqlite_master WHERE type='table' - AND name='{}'""".format(self.table_name)) + AND name="{}""".format(self.table_name)) return self.cur.fetchone()[0] def create_sbo_table(self): - self.cur.execute('''CREATE TABLE IF NOT EXISTS {} + self.cur.execute("""CREATE TABLE IF NOT EXISTS {} (name text, location text, files text, version text, download text, download64 text, md5sum text, md5sum64 text, requires text, short_desc text) - '''.format(self.table_name)) + """.format(self.table_name)) self.con.commit() def insert_sbo_table(self): + """Grabbing data line by line and inserting them into the database + """ self.sbo = [ - 'SLACKBUILD NAME:', - 'SLACKBUILD LOCATION:', - 'SLACKBUILD FILES:', - 'SLACKBUILD VERSION:', - 'SLACKBUILD DOWNLOAD:', - 'SLACKBUILD DOWNLOAD_x86_64:', - 'SLACKBUILD MD5SUM:', - 'SLACKBUILD MD5SUM_x86_64:', - 'SLACKBUILD REQUIRES:', - 'SLACKBUILD SHORT DESCRIPTION:' + "SLACKBUILD NAME:", + "SLACKBUILD LOCATION:", + "SLACKBUILD FILES:", + "SLACKBUILD VERSION:", + "SLACKBUILD DOWNLOAD:", + "SLACKBUILD DOWNLOAD_x86_64:", + "SLACKBUILD MD5SUM:", + "SLACKBUILD MD5SUM_x86_64:", + "SLACKBUILD REQUIRES:", + "SLACKBUILD SHORT DESCRIPTION:" ] sbo_file = self.open_file(f"{self.lib_path}sbo_repo/SLACKBUILDS.TXT") bar = Bar("Database sbo creating", max=len(sbo_file), - suffix='%(percent)d%% - %(eta)ds') + suffix="%(percent)d%% - %(eta)ds") for i, line in enumerate(sbo_file, 1): if line.startswith(self.sbo[0]): - name = line.replace(self.sbo[0], '').strip() + name = line.replace(self.sbo[0], "").strip() if line.startswith(self.sbo[1]): - location = line.replace(self.sbo[1], '').strip() + location = line.replace(self.sbo[1], "").strip() if line.startswith(self.sbo[2]): - files = line.replace(self.sbo[2], '').strip() + files = line.replace(self.sbo[2], "").strip() if line.startswith(self.sbo[3]): - version = line.replace(self.sbo[3], '').strip() + version = line.replace(self.sbo[3], "").strip() if line.startswith(self.sbo[4]): - download = line.replace(self.sbo[4], '').strip() + download = line.replace(self.sbo[4], "").strip() if line.startswith(self.sbo[5]): - download64 = line.replace(self.sbo[5], '').strip() + download64 = line.replace(self.sbo[5], "").strip() if line.startswith(self.sbo[6]): - md5sum = line.replace(self.sbo[6], '').strip() + md5sum = line.replace(self.sbo[6], "").strip() if line.startswith(self.sbo[7]): - md5sum64 = line.replace(self.sbo[7], '').strip() + md5sum64 = line.replace(self.sbo[7], "").strip() if line.startswith(self.sbo[8]): - requires = line.replace(self.sbo[8], '').strip() + requires = line.replace(self.sbo[8], "").strip() if line.startswith(self.sbo[9]): - short_desc = line.replace(self.sbo[9], '').strip() + short_desc = line.replace(self.sbo[9], "").strip() if i % 11 == 0: values = [(name, location, files, version, download, @@ -106,5 +110,5 @@ class Database: self.con.close() def open_file(self, file): - with open(file, 'r', encoding='utf-8') as f: + with open(file, "r", encoding="utf-8") as f: return f.readlines() From 6293c135e0064a2b36d69790301586566515c1f0 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 00:35:39 +0300 Subject: [PATCH 04/23] Fixed quotes --- slpkg/models/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slpkg/models/models.py b/slpkg/models/models.py index 92747d94..c6ea2e89 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -43,7 +43,7 @@ class Database: self.cur.execute("""SELECT count(name) FROM sqlite_master WHERE type='table' - AND name="{}""".format(self.table_name)) + AND name='{}'""".format(self.table_name)) return self.cur.fetchone()[0] def create_sbo_table(self): From 1fe2112fcfc518f797118c454994d12898d416a1 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 16:47:10 +0300 Subject: [PATCH 05/23] Rplaced generator --- slpkg/sbo/greps.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 542cc513..94905e80 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -53,9 +53,13 @@ class SBoGrep(Utils): def _names_grabbing(self): """Generator that collecting all packages names """ - for line in self.SLACKBUILDS_TXT.splitlines(): - if line.startswith(self.line_name): - yield line[17:].strip() + names = self.cur.execute("SELECT name FROM sbo").fetchall() + for n in names: + yield n[0] + +# for line in self.SLACKBUILDS_TXT.splitlines(): +# if line.startswith(self.line_name): +# yield line[17:].strip() def names(self): """Alias method convert generator and return From 37736f784782517169ce70b5344c14b6548157e0 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 17:14:21 +0300 Subject: [PATCH 06/23] Removed unused --- slpkg/init.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/slpkg/init.py b/slpkg/init.py index 0202c69c..8cfdf081 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -747,6 +747,8 @@ class Update: raise SystemExit() def check_db(self): + """Checking if the table exists + """ sbo_db = Database("sbo", "SLACKBUILDS.TXT") if sbo_db.table_exists() == 0: sbo_db.create_sbo_table() @@ -758,15 +760,6 @@ class Update: f"{self.endc}", end="", flush=True) -def database(text_file): - db_lib = _meta_.lib_path + "database" - init = Initialization(False) - init.make_dirs([db_lib]) - data = Database("sbo", text_file) - data.create_sbo_table() - data.insert_sbo_table() - - def check_exists_repositories(repo): """Checking if repositories exists by PACKAGES.TXT file """ From 20798145601742e03b111b6fe958047e018d96a7 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 17:18:47 +0300 Subject: [PATCH 07/23] Removed unused old code --- slpkg/sbo/greps.py | 71 ---------------------------------------------- 1 file changed, 71 deletions(-) diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 94905e80..4de60ba4 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -35,20 +35,9 @@ class SBoGrep(Utils): self.meta = _meta_ self.db = self.meta.db self.arch64 = "x86_64" - self.line_name = "SLACKBUILD NAME: " - self.line_files = "SLACKBUILD FILES: " - self.line_down = "SLACKBUILD DOWNLOAD: " - self.line_down_64 = f"SLACKBUILD DOWNLOAD_{self.arch64}: " - self.line_req = "SLACKBUILD REQUIRES: " - self.line_ver = "SLACKBUILD VERSION: " - self.line_md5 = "SLACKBUILD MD5SUM: " - self.line_md5_64 = f"SLACKBUILD MD5SUM_{self.arch64}: " - self.line_des = "SLACKBUILD SHORT DESCRIPTION: " - self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT" self.sbo_db = f"{self.meta.lib_path}database/{self.db}" self.con = sqlite3.connect(self.sbo_db) self.cur = self.con.cursor() - self.SLACKBUILDS_TXT = self.read_file(self.sbo_txt) def _names_grabbing(self): """Generator that collecting all packages names @@ -57,10 +46,6 @@ class SBoGrep(Utils): for n in names: yield n[0] -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# yield line[17:].strip() - def names(self): """Alias method convert generator and return a list @@ -70,16 +55,6 @@ class SBoGrep(Utils): def source(self): """Grab sources downloads links """ -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# sbo_name = line[17:].strip() -# if line.startswith(self.line_down): -# if sbo_name == self.name and line[21:].strip(): -# source = line[21:] -# if line.startswith(self.line_down_64): -# if sbo_name == self.name and line[28:].strip(): -# source64 = line[28:] - source, source64 = self.cur.execute("""SELECT download, download64 FROM sbo WHERE name = '{}'""".format( @@ -95,14 +70,6 @@ class SBoGrep(Utils): self.name)).fetchone() return requires[0].split() -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# sbo_name = line[17:].strip() -# if line.startswith(self.line_req): -# if sbo_name == self.name: -# # print(line[21:].strip().split()) -# return line[21:].strip().split() - def version(self): """Grab package version """ @@ -112,15 +79,6 @@ class SBoGrep(Utils): self.name)).fetchone() return version[0] -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# sbo_name = line[17:].strip() -# if line.startswith(self.line_ver): -# if sbo_name == self.name: -# print(line[20:].strip()) -# -# return line[20:].strip() - def checksum(self): """Grab checksum string """ @@ -135,19 +93,6 @@ class SBoGrep(Utils): md5sum64.append(md5s64) return self._sorting_arch(md5sum, md5sum64) -# md5sum, md5sum64, = [], [] -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# sbo_name = line[17:].strip() -# if line.startswith(self.line_md5_64): -# if sbo_name == self.name and line[26:].strip(): -# md5sum64 = line[26:].strip().split() -# if line.startswith(self.line_md5): -# if sbo_name == self.name and line[19:].strip(): -# md5sum = line[19:].strip().split() -# print(md5sum, md5sum64) -# return self._sorting_arch(md5sum, md5sum64) - def description(self): """Grab package description """ @@ -157,15 +102,6 @@ class SBoGrep(Utils): self.name)).fetchone() return desc[0] -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# sbo_name = line[17:].strip() -# if line.startswith(self.line_des): -# if sbo_name == self.name: -# print(line[31:].strip()) -# -# return line[31:].strip() - def files(self): """Grab files """ @@ -175,13 +111,6 @@ class SBoGrep(Utils): self.name)).fetchone() return files[0] -# for line in self.SLACKBUILDS_TXT.splitlines(): -# if line.startswith(self.line_name): -# sbo_name = line[17:].strip() -# if line.startswith(self.line_files): -# if sbo_name == self.name: -# return line[18:].strip() - def _sorting_arch(self, arch, arch64): """Return sources by arch """ From 79f435591356fef051469e1b6eca8b069476de1c Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 18:05:13 +0300 Subject: [PATCH 08/23] Fixed complexity --- slpkg/models/models.py | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/slpkg/models/models.py b/slpkg/models/models.py index c6ea2e89..b83a968e 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -74,37 +74,26 @@ class Database: bar = Bar("Database sbo creating", max=len(sbo_file), suffix="%(percent)d%% - %(eta)ds") + + cache = [] # init cache + for i, line in enumerate(sbo_file, 1): - if line.startswith(self.sbo[0]): - name = line.replace(self.sbo[0], "").strip() - if line.startswith(self.sbo[1]): - location = line.replace(self.sbo[1], "").strip() - if line.startswith(self.sbo[2]): - files = line.replace(self.sbo[2], "").strip() - if line.startswith(self.sbo[3]): - version = line.replace(self.sbo[3], "").strip() - if line.startswith(self.sbo[4]): - download = line.replace(self.sbo[4], "").strip() - if line.startswith(self.sbo[5]): - download64 = line.replace(self.sbo[5], "").strip() - if line.startswith(self.sbo[6]): - md5sum = line.replace(self.sbo[6], "").strip() - if line.startswith(self.sbo[7]): - md5sum64 = line.replace(self.sbo[7], "").strip() - if line.startswith(self.sbo[8]): - requires = line.replace(self.sbo[8], "").strip() - if line.startswith(self.sbo[9]): - short_desc = line.replace(self.sbo[9], "").strip() + for s in self.sbo: + if line.startswith(s): + line = line.replace(s, "").strip() + cache.append(line) - if i % 11 == 0: - values = [(name, location, files, version, download, - download64, md5sum, md5sum64, requires, short_desc), - ] + if (i % 11) == 0: + values = [ + (cache[0], cache[1], cache[2], cache[3], cache[4], + cache[5], cache[6], cache[7], cache[8], cache[9]), + ] self.cur.executemany("""INSERT INTO {} VALUES - (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""".format( - self.table_name), values) + (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""".format( + self.table_name), values) self.con.commit() + cache = [] # reset cache after line bar.next() bar.finish() self.con.close() From 7acb3587e04ffc927bc38348f73d05d8053203a9 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 18:09:36 +0300 Subject: [PATCH 09/23] Updated progress bar message --- slpkg/models/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slpkg/models/models.py b/slpkg/models/models.py index b83a968e..37de4dc8 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -72,7 +72,7 @@ class Database: sbo_file = self.open_file(f"{self.lib_path}sbo_repo/SLACKBUILDS.TXT") - bar = Bar("Database sbo creating", max=len(sbo_file), + bar = Bar("Creating sbo database", max=len(sbo_file), suffix="%(percent)d%% - %(eta)ds") cache = [] # init cache @@ -93,7 +93,7 @@ class Database: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""".format( self.table_name), values) self.con.commit() - cache = [] # reset cache after line + cache = [] # reset cache after 11 lines bar.next() bar.finish() self.con.close() From 1ea9e7b635de6c999bb09b92358cd5bc527af154 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 19:14:27 +0300 Subject: [PATCH 10/23] Reorder variables --- slpkg/init.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slpkg/init.py b/slpkg/init.py index 8cfdf081..e1e2fbaa 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -45,8 +45,6 @@ class Initialization(Utils): self.check = check self.meta = _meta_ self.arch = _meta_.arch - self.slack_ver = slack_ver() - self.def_repos_dict = Repo().default_repository() self.conf_path = self.meta.conf_path self.log_path = self.meta.log_path self.lib_path = self.meta.lib_path @@ -55,8 +53,9 @@ class Initialization(Utils): self._SOURCES = self.meta.SBo_SOURCES self.slpkg_tmp_packages = self.meta.slpkg_tmp_packages self.slpkg_tmp_patches = self.meta.slpkg_tmp_patches + self.slack_ver = slack_ver() + self.def_repos_dict = Repo().default_repository() self.constructing() - self.database() def constructing(self): """Creating the all necessary directories @@ -77,6 +76,7 @@ class Initialization(Utils): self.make_dir(paths_basic) self.make_dirs(paths_extra) + self.database() def database(self): """Initializing the database From 272cddfb03a8e2f3a1d18423c0406291364be87b Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 19:47:58 +0300 Subject: [PATCH 11/23] Updated for version 4.0.0 --- ChangeLog.txt | 5 +++++ README.rst | 8 ++++---- requirements.txt | 2 ++ setup.py | 2 +- slpkg/__metadata__.py | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 10716956..0a5f13ef 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,8 @@ +4.0.0 - 29/05/2022 +Added: +- sqlite3 database replaced the sbo repository +- python package 'progress' added as dependency + 3.9.9 - 24/05/2022 Updated: - Stderr error output to auto-install packages diff --git a/README.rst b/README.rst index b6b3e1b2..4ff21245 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ *********** -slpkg 3.9.9 +slpkg 4.0.0 *********** Slpkg is a powerful software package manager that installs, updates, and removes packages on @@ -35,9 +35,9 @@ Install from the official third party `SBo repository =1.6"] optional_requires = [ "pythondialog>=3.5.1", "pygraphviz>=1.3.1" diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index 22794666..9751d6d6 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -81,7 +81,7 @@ class MetaData: __all__ = "slpkg" __author__ = "dslackw" - __version_info__ = (3, 9, 9) + __version_info__ = (4, 0, 0) __version__ = "{0}.{1}.{2}".format(*__version_info__) __license__ = "GNU General Public License v3 (GPLv3)" __email__ = "d.zlatanidis@gmail.com" From f90780102f39aa7ad522ba4ece10be8f9767489f Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 20:18:59 +0300 Subject: [PATCH 12/23] Switched with sqlite --- slpkg/sbo/search.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/slpkg/sbo/search.py b/slpkg/sbo/search.py index a39b918d..f9c8f53a 100644 --- a/slpkg/sbo/search.py +++ b/slpkg/sbo/search.py @@ -22,7 +22,7 @@ # along with this program. If not, see . -from slpkg.utils import Utils +import sqlite3 from slpkg.repositories import Repo from slpkg.__metadata__ import MetaData as _meta_ @@ -33,16 +33,17 @@ def sbo_search_pkg(name): """Search for package path in SLACKBUILDS.TXT file and return url """ - url = "" - utils = Utils() + db = _meta_.db + lib_path = _meta_.lib_path + con = sqlite3.connect(f"{lib_path}{db}") + cur = con.cursor() + + loc = cur.execute("""SELECT location + FROM sbo + WHERE name = '{}'""".format(name)).fetchone() + repo = Repo() sbo = repo.default_repository()["sbo"] sbo_url = f"{sbo}{slack_ver()}/" - SLACKBUILDS_TXT = utils.read_file( - f"{_meta_.lib_path}sbo_repo/SLACKBUILDS.TXT") - for line in SLACKBUILDS_TXT.splitlines(): - if line.startswith("SLACKBUILD LOCATION"): - sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip() - if name == sbo_name: - url = f"{sbo_url}{line[23:].strip()}/" - return url + + return f"{sbo_url}{loc[0][2:]}/" From d3c251a6dbbe4698749939d3fcf26a21bff790fa Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 20:20:01 +0300 Subject: [PATCH 13/23] Redefined database path --- slpkg/__metadata__.py | 2 +- slpkg/init.py | 5 ++--- slpkg/models/models.py | 2 +- slpkg/sbo/greps.py | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index 9751d6d6..11728094 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -242,7 +242,7 @@ class MetaData: slackpkg_lib_path = "/var/lib/slackpkg/" # database name - db = "database.slpkg" + db = "/database/database.slpkg" # computer architecture if comp_arch in ["off", "OFF"]: diff --git a/slpkg/init.py b/slpkg/init.py index e1e2fbaa..8e404959 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -81,10 +81,9 @@ class Initialization(Utils): def database(self): """Initializing the database """ - self.db = "database.slpkg" - db_lib = self.lib_path + "database/" + db_lib = self.lib_path + self.meta.db self.make_dirs([db_lib]) - self.con = sqlite3.connect(db_lib + self.db) + self.con = sqlite3.connect(db_lib) self.cur = self.con.cursor() def make_dir(self, path: list): diff --git a/slpkg/models/models.py b/slpkg/models/models.py index 37de4dc8..85e63111 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -34,7 +34,7 @@ class Database: self.table_name = table_name self.text_file = text_file self.db = _meta_.db - self.con = sqlite3.connect(f"{self.lib_path}database/{self.db}") + self.con = sqlite3.connect(f"{self.lib_path}{self.db}") self.cur = self.con.cursor() def table_exists(self): diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 4de60ba4..611f4322 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -35,7 +35,7 @@ class SBoGrep(Utils): self.meta = _meta_ self.db = self.meta.db self.arch64 = "x86_64" - self.sbo_db = f"{self.meta.lib_path}database/{self.db}" + self.sbo_db = f"{self.meta.lib_path}{self.db}" self.con = sqlite3.connect(self.sbo_db) self.cur = self.con.cursor() From 6d1934a1d96145f507c52d1dcb2b2e681860c408 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 21:00:32 +0300 Subject: [PATCH 14/23] Fixed typos --- slpkg/sbo/autobuild.py | 6 +++--- slpkg/sbo/build_num.py | 2 +- slpkg/sbo/check.py | 4 ++-- slpkg/sbo/compressed.py | 4 +--- slpkg/sbo/dependency.py | 8 ++++---- slpkg/sbo/greps.py | 18 +++++++++--------- slpkg/sbo/network.py | 14 +++++++------- slpkg/sbo/queue.py | 16 ++++++++-------- slpkg/sbo/search.py | 8 ++++---- 9 files changed, 39 insertions(+), 41 deletions(-) diff --git a/slpkg/sbo/autobuild.py b/slpkg/sbo/autobuild.py index 3b292d17..cbfd73dd 100644 --- a/slpkg/sbo/autobuild.py +++ b/slpkg/sbo/autobuild.py @@ -41,20 +41,20 @@ class AutoBuild: self.sbo_sources = [] def run(self): - """Build package and fix ordelist per checksum + """Builds package and fix ordelist per checksum """ self.files_exist() self.info_file() sources = self.sources if len(sources) > 1 and self.sbo_sources != sources: sources = self.sbo_sources - # If the list does not have the same order use from .info + # If the list does not have the same order uses from .info # order. BuildPackage(self.script, sources, self.path, auto=True).build() raise SystemExit() def info_file(self): - """Grab sources from .info file and store filename + """Grabs sources from .info file and stores filename """ sources = SBoGrep(self.prgnam).source().split() for source in sources: diff --git a/slpkg/sbo/build_num.py b/slpkg/sbo/build_num.py index bbc8c08e..f06c1955 100644 --- a/slpkg/sbo/build_num.py +++ b/slpkg/sbo/build_num.py @@ -30,7 +30,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class BuildNumber(Utils): - """Get build number from SlackBuild script + """Gets build number from SlackBuild script """ def __init__(self, sbo_url, pkg): self.sbo_url = sbo_url diff --git a/slpkg/sbo/check.py b/slpkg/sbo/check.py index 78c42312..6e04532a 100644 --- a/slpkg/sbo/check.py +++ b/slpkg/sbo/check.py @@ -35,7 +35,7 @@ from slpkg.sbo.greps import SBoGrep def sbo_upgrade(skip, flag): - """Return packages for upgrade + """Returns packages for upgrade """ msg = Msg() black = BlackList() @@ -58,7 +58,7 @@ def sbo_upgrade(skip, flag): def sbo_list(): - """Return all SBo packages + """Returns all SBo packages """ for pkg in os.listdir(_meta_.pkg_path): if pkg.endswith("_SBo"): diff --git a/slpkg/sbo/compressed.py b/slpkg/sbo/compressed.py index 4f5ce454..a2ba6fd1 100644 --- a/slpkg/sbo/compressed.py +++ b/slpkg/sbo/compressed.py @@ -23,12 +23,10 @@ class SBoLink: - """Create slackbuild tar.gz archive from url + """Creates slackbuild tar.gz archive from url """ def __init__(self, sbo_url): self.sbo_url = sbo_url def tar_gz(self): - """Return link slackbuild tar.gz archive - """ return f"{self.sbo_url[:-1]}.tar.gz" diff --git a/slpkg/sbo/dependency.py b/slpkg/sbo/dependency.py index ce666319..4278e557 100644 --- a/slpkg/sbo/dependency.py +++ b/slpkg/sbo/dependency.py @@ -44,7 +44,7 @@ class Requires(BlackList): @lru_cache def sbo(self, name): - """Build all dependencies of a package + """Builds all dependencies of a package """ if (self.meta.rsl_deps in ["on", "ON"] and "--resolve-off" not in self.flag): @@ -53,8 +53,8 @@ class Requires(BlackList): requires = SBoGrep(name).requires() if requires: for req in requires: - # avoid to add %README% as dependency and - # if require in blacklist + # avoids adding %README% as dependency and if + # requires in the blacklist if "%README%" not in req and req not in self.blacklist: dependencies.append(req) self.deep_check(tuple(dependencies)) @@ -64,7 +64,7 @@ class Requires(BlackList): @lru_cache def deep_check(self, dependencies): - """Checking if dependencies are finnished + """Checking if dependencies are finished """ if dependencies: self.dep_results.append(dependencies) diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 611f4322..0fea5411 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -28,7 +28,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class SBoGrep(Utils): - """Grab data from SLACKBUILDS.TXT file + """Grabs data from sbo database """ def __init__(self, name): self.name = name @@ -53,7 +53,7 @@ class SBoGrep(Utils): return list(self._names_grabbing()) def source(self): - """Grab sources downloads links + """Grabs sources downloads links """ source, source64 = self.cur.execute("""SELECT download, download64 FROM sbo @@ -62,7 +62,7 @@ class SBoGrep(Utils): return self._sorting_arch(source, source64) def requires(self): - """Grab package requirements + """Grabs package requirements """ requires = self.cur.execute("""SELECT requires FROM sbo @@ -71,7 +71,7 @@ class SBoGrep(Utils): return requires[0].split() def version(self): - """Grab package version + """Grabs package version """ version = self.cur.execute("""SELECT version FROM sbo @@ -80,7 +80,7 @@ class SBoGrep(Utils): return version[0] def checksum(self): - """Grab checksum string + """Grabs checksum string """ md5sum, md5sum64, = [], [] mds5, md5s64 = self.cur.execute("""SELECT md5sum, md5sum64 @@ -94,7 +94,7 @@ class SBoGrep(Utils): return self._sorting_arch(md5sum, md5sum64) def description(self): - """Grab package description + """Grabs package description """ desc = self.cur.execute("""SELECT short_desc FROM sbo @@ -103,7 +103,7 @@ class SBoGrep(Utils): return desc[0] def files(self): - """Grab files + """Grabs files """ files = self.cur.execute("""SELECT files FROM sbo @@ -112,8 +112,8 @@ class SBoGrep(Utils): return files[0] def _sorting_arch(self, arch, arch64): - """Return sources by arch + """Returns sources by arch """ if self.meta.arch == self.arch64 and arch64: return arch64 - return arch + return arch \ No newline at end of file diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py index e18a16c0..75ce1ddf 100644 --- a/slpkg/sbo/network.py +++ b/slpkg/sbo/network.py @@ -49,7 +49,7 @@ from slpkg.slack.slack_version import slack_ver class SBoNetwork(BlackList, Utils): - """View SBo site in terminal and also read, build or + """View SBo site in the terminal and also read, build or install packages """ def __init__(self, name, flag): @@ -224,7 +224,7 @@ class SBoNetwork(BlackList, Utils): raise SystemExit() def choice_install(self): - """Download, build and install package + """Download, build and install the package """ pkg_security([self.name]) if not find_package(self.prgnam, self.meta.pkg_path): @@ -313,7 +313,7 @@ class SBoNetwork(BlackList, Utils): pydoc.pager(text) def fill_pager(self, page): - """Fix pager spaces + """Fixes pager spaces """ tty_size = os.popen("stty size", "r").read().split() rows = int(tty_size[0]) - 1 @@ -326,8 +326,8 @@ class SBoNetwork(BlackList, Utils): return "" def error_uns(self): - """Check if package supported by arch - before proceed to install + """Check if the package is supported by an arch + before proceeding to install """ self.FAULT = "" UNST = ["UNSUPPORTED", "UNTESTED"] @@ -335,7 +335,7 @@ class SBoNetwork(BlackList, Utils): self.FAULT = "".join(self.source_dwn) def build(self): - """Only build and create Slackware package + """Builds slackware package """ pkg_security([self.name]) self.error_uns() @@ -363,7 +363,7 @@ class SBoNetwork(BlackList, Utils): slack_package(self.prgnam) # check if build def install(self): - """Install SBo package found in /tmp directory. + """Installs SBo package found in /tmp directory. """ binary = slack_package(self.prgnam) print(f"[ {self.green}Installing{self.endc} ] --> {self.name}") diff --git a/slpkg/sbo/queue.py b/slpkg/sbo/queue.py index 433be96a..dc2aad93 100644 --- a/slpkg/sbo/queue.py +++ b/slpkg/sbo/queue.py @@ -40,7 +40,7 @@ from slpkg.sbo.slack_find import slack_package class QueuePkgs(Utils): - """Manage SBo packages, add or remove for building or + """Manages SBo packages, add or removes for building or installation """ def __init__(self): @@ -57,7 +57,7 @@ class QueuePkgs(Utils): """Creating the directories and the queue file """ queue_file = [ - "# In this file you can create a list of\n", + "# In this file, you can create a list of\n", "# packages you want to build or install.\n", "#\n"] if not os.path.exists(self.meta.lib_path): @@ -71,7 +71,7 @@ class QueuePkgs(Utils): self.queued = self.read_file(self.queue_list) def packages(self): - """Return queue list from /var/lib/queue/queue_list + """Returns queue list from /var/lib/queue/queue_list file. """ for read in self.queued.splitlines(): @@ -80,7 +80,7 @@ class QueuePkgs(Utils): yield read.replace("\n", "") def listed(self): - """Print packages from queue + """Prints packages from queue """ print("Packages in the queue:") for pkg in self.packages(): @@ -88,7 +88,7 @@ class QueuePkgs(Utils): print() def add(self, pkgs): - """Add packages in queue if not exist + """Adds packages in queue if not exist """ queue_list = list(self.packages()) pkgs = list(OrderedDict.fromkeys(pkgs)) @@ -104,7 +104,7 @@ class QueuePkgs(Utils): print() def remove(self, pkgs): - """Remove packages from queue + """Removes packages from the queue """ print("Remove packages from the queue:") with open(self.queue_list, "w") as queue: @@ -116,7 +116,7 @@ class QueuePkgs(Utils): print() def build(self): - """Build packages from queue + """Builds packages from the queue """ sources = [] packages = list(self.packages()) @@ -146,7 +146,7 @@ class QueuePkgs(Utils): "building\n") def install(self): - """Install packages from queue + """Installs packages from the queue """ packages = list(self.packages()) if packages: diff --git a/slpkg/sbo/search.py b/slpkg/sbo/search.py index f9c8f53a..0eefeeaa 100644 --- a/slpkg/sbo/search.py +++ b/slpkg/sbo/search.py @@ -38,12 +38,12 @@ def sbo_search_pkg(name): con = sqlite3.connect(f"{lib_path}{db}") cur = con.cursor() - loc = cur.execute("""SELECT location - FROM sbo - WHERE name = '{}'""".format(name)).fetchone() + location = cur.execute("""SELECT location + FROM sbo + WHERE name = '{}'""".format(name)).fetchone() repo = Repo() sbo = repo.default_repository()["sbo"] sbo_url = f"{sbo}{slack_ver()}/" - return f"{sbo_url}{loc[0][2:]}/" + return f"{sbo_url}{location[0][2:]}/" From caafd78aeff2cd8d722df28f00a0f93cf126c483 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 21:33:06 +0300 Subject: [PATCH 15/23] Fixed typos --- slpkg/blacklist.py | 12 +++++------ slpkg/clean.py | 2 +- slpkg/dialog_box.py | 2 +- slpkg/downloader.py | 8 ++++---- slpkg/file_size.py | 2 +- slpkg/graph.py | 8 ++++---- slpkg/grep_md5.py | 2 +- slpkg/health.py | 8 ++++---- slpkg/init.py | 18 ++++++++-------- slpkg/load.py | 6 +++--- slpkg/log_deps.py | 4 ++-- slpkg/main.py | 48 +++++++++++++++++++++---------------------- slpkg/messages.py | 33 ----------------------------- slpkg/new_config.py | 20 +++++++++--------- slpkg/pkg_find.py | 7 +++---- slpkg/remove.py | 4 ++-- slpkg/repoenable.py | 6 +++--- slpkg/repoinfo.py | 4 ++-- slpkg/repositories.py | 10 ++++----- slpkg/security.py | 2 +- slpkg/sizes.py | 2 +- slpkg/slpkg_update.py | 3 +-- slpkg/splitting.py | 3 +-- slpkg/status_deps.py | 6 +++--- slpkg/superuser.py | 4 ++-- slpkg/tracking.py | 14 ++++++------- slpkg/url_read.py | 2 +- slpkg/utils.py | 14 ++++++------- slpkg/version.py | 2 +- 29 files changed, 110 insertions(+), 146 deletions(-) diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index dcc8f751..534a7e44 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -30,7 +30,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class BlackList(Utils): - """Blacklist class to add, remove or listed packages + """Blacklist class to add, remove or list packages in blacklist file.""" def __init__(self): self.green = _meta_.color["GREEN"] @@ -56,8 +56,8 @@ class BlackList(Utils): yield black def black_filter(self): - """Return all the installed files that start - by the name* + """Returns all the installed files that start + by the name """ for read in self.black_conf.splitlines(): read = read.lstrip() @@ -65,7 +65,7 @@ class BlackList(Utils): yield read.replace("\n", "") def black_listed(self): - """Print blacklist packages + """Prints blacklist packages """ print("Packages in the blacklist:") for black in list(self.black_filter()): @@ -74,7 +74,7 @@ class BlackList(Utils): print() def black_add(self, pkgs): - """Add blacklist packages if not exist + """Adds blacklist packages if not exist """ blacklist = list(self.black_filter()) pkgs = set(pkgs) @@ -87,7 +87,7 @@ class BlackList(Utils): print() def black_remove(self, pkgs): - """Remove packages from blacklist + """Removes packages from blacklist """ print("Remove packages from the blacklist:") with open(self.blackfile, "w") as remove: diff --git a/slpkg/clean.py b/slpkg/clean.py index e33772e3..d9a2323b 100644 --- a/slpkg/clean.py +++ b/slpkg/clean.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def clean_tmp(): - """Delete packages and sources from tmp/ directory + """Deletes packages and sources from tmp/ directory """ tmps = [_meta_.tmp_path, # /tmp/slpkg/ _meta_.build_path, # /tmp/slpkg/build/ diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index eb9a513a..9a44fdb7 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -28,7 +28,7 @@ import os class DialogUtil: - """Create dialog checklist + """Creates dialog checklist """ def __init__(self, *args): self.imp_dialog() diff --git a/slpkg/downloader.py b/slpkg/downloader.py index db0b2653..d4e2b18c 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -51,7 +51,7 @@ class Download(Utils): self.downder_options = self.meta.downder_options def start(self): - """Download files using wget or other downloader. + """Download files using wget or other downloaders. Optional curl, aria2c and httpie """ dwn_count = 1 @@ -82,7 +82,7 @@ class Download(Utils): dwn_count += 1 def _make_tarfile(self, output_filename, source_dir): - """Create .tar.gz file + """Creates .tar.gz file """ with tarfile.open(output_filename, "w:gz") as tar: tar.add(source_dir, arcname=os.path.basename(source_dir)) @@ -96,7 +96,7 @@ class Download(Utils): self.dir_prefix = "--dir=" def _check_if_downloaded(self): - """Check if file downloaded + """Checks if file downloaded """ if not os.path.isfile(self.path + self.file_name): print() @@ -109,7 +109,7 @@ class Download(Utils): raise SystemExit() def _check_certificate(self): - """Check for certificates options for wget + """Checks for certificates options for wget """ if (self.file_name.startswith("jdk-") and self.repo == "sbo" and self.downder == "wget"): diff --git a/slpkg/file_size.py b/slpkg/file_size.py index 314b6695..bff73ea4 100644 --- a/slpkg/file_size.py +++ b/slpkg/file_size.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class FileSize: - """Check local or remote file size + """Checks local or remote file size """ def __init__(self, registry): self.meta = _meta_ diff --git a/slpkg/graph.py b/slpkg/graph.py index 671eda3a..5974462b 100644 --- a/slpkg/graph.py +++ b/slpkg/graph.py @@ -47,7 +47,7 @@ class Graph: ] def dependencies(self, deps_dict): - """Generate graph file with depenndencies map tree + """Generates graph file with dependencies map tree """ try: import pygraphviz as pgv @@ -75,7 +75,7 @@ class Graph: raise SystemExit() def check_file(self): - """Check for file format and type + """Checks for file format and type """ try: image_type = f".{self.image.split('.')[1]}" @@ -87,7 +87,7 @@ class Graph: raise SystemExit("slpkg: Error: Image file suffix missing") def graph_easy(self): - """Draw ascii diagram. graph-easy perl module require + """Drawing ascii diagram. graph-easy perl module requires """ if not os.path.isfile("/usr/bin/graph-easy"): print("Require 'graph-easy': Install with 'slpkg -s sbo" @@ -99,7 +99,7 @@ class Graph: raise SystemExit(1) def remove_dot(self): - """Remove .dot files + """Removes .dot files """ if os.path.isfile(f"{self.image}.dot"): os.remove(f"{self.image}.dot") diff --git a/slpkg/grep_md5.py b/slpkg/grep_md5.py index f701a83f..78087a2a 100644 --- a/slpkg/grep_md5.py +++ b/slpkg/grep_md5.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def pkg_checksum(binary, repo): - """Return checksum from CHECKSUMS.md5 file by repository + """Returns checksum from CHECKSUMS.md5 file by repository """ md5 = "None" if repo == "slack_patches" and _meta_.slack_rel == "stable": diff --git a/slpkg/health.py b/slpkg/health.py index 77fc5cc4..566b2d44 100644 --- a/slpkg/health.py +++ b/slpkg/health.py @@ -31,7 +31,7 @@ from slpkg.pkg.find import find_package class PackageHealth: - """Health check installed packages + """Health check for the installed packages """ def __init__(self, mode): self.mode = mode @@ -46,7 +46,7 @@ class PackageHealth: self.cn = 0 def packages(self): - """Get all installed packages from /var/log/packages/ path + """Gets all installed packages from /var/log/packages/ path """ self.installed = find_package("", self.pkg_path) @@ -67,7 +67,7 @@ class PackageHealth: raise SystemExit("\n") def test(self): - """Get started test each package and read file list + """Starts testing each package and reading the file list """ self.packages() self.cf = 0 @@ -86,7 +86,7 @@ class PackageHealth: self.results() def results(self): - """Print results + """Prints results """ print() per = int(round((float(self.cf) / (self.cf + self.cn)) * 100)) diff --git a/slpkg/init.py b/slpkg/init.py index 8e404959..08e06265 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -38,8 +38,8 @@ from slpkg.slack.slack_version import slack_ver class Initialization(Utils): - """Slpkg initialization start all from here. Create local - package lists and update or upgrade these. + """Slpkg initialization starts all from here. + Creates local package lists and updates or upgrades these. """ def __init__(self, check): self.check = check @@ -97,7 +97,7 @@ class Initialization(Utils): os.makedirs(p) def custom(self, name): - """Creating user select repository local library + """Creating user custom repository local library """ repo = Repo().custom_repository()[name] log = self.log_path + name + "/" @@ -599,14 +599,14 @@ class Initialization(Utils): FILELIST_TXT, repo_name) def down(self, path, link, repo): - """Download files + """Downloads files """ filename = link.split("/")[-1] if not os.path.isfile(path + filename): Download(path, link.split(), repo).start() def remote(self, *args): - """Remove and recreate files + """Removes and recreates files """ log_path = args[0] ChangeLog_txt = args[1] @@ -642,7 +642,7 @@ class Initialization(Utils): self.con.commit() def merge(self, path, outfile, infiles): - """Merge files + """Merging files """ code = "utf-8" with open(path + outfile, 'w', encoding=code) as out_f: @@ -655,7 +655,7 @@ class Initialization(Utils): out_f.write(line) def file_remove(self, path, filename): - """Check if filename exists and remove + """Checks if filename exists and removes """ if os.path.isfile(path + filename): os.remove(path + filename) @@ -718,7 +718,7 @@ class Update: self.error = f"{self.red}Error{self.endc}\n" def run(self, repos): - """Update repositories lists + """Updates repositories lists """ print("\nCheck and update repositories:\n") default = self.meta.default_repositories @@ -772,7 +772,7 @@ def check_exists_repositories(repo): def check_for_local_repos(repo): - """Check if repository is local + """Checks if repository is local """ repos_dict = Repo().default_repository() if repo in repos_dict: diff --git a/slpkg/load.py b/slpkg/load.py index 65f8e455..24ed58c2 100644 --- a/slpkg/load.py +++ b/slpkg/load.py @@ -32,7 +32,7 @@ from slpkg.pkg.find import find_package def library(repo): - """Load packages from slpkg library and from local + """Loads packages from slpkg library and from local """ utils = Utils() pkg_list, packages = [], "" @@ -59,7 +59,7 @@ def library(repo): class Regex: - """Grap packages with simple regex using asterisk * + """Graps packages with simple regex using asterisk * with options: starts with string* ends with *string include *string* @@ -90,7 +90,7 @@ class Regex: return lib def add(self, repo, pkg): - """Split packages by repository + """Splits packages by repository """ if repo == "sbo": return pkg diff --git a/slpkg/log_deps.py b/slpkg/log_deps.py index 482d3118..9c89964a 100644 --- a/slpkg/log_deps.py +++ b/slpkg/log_deps.py @@ -30,8 +30,8 @@ from slpkg.pkg.find import find_package def write_deps(deps_dict): - """Write dependencies in a log file - into directory `/var/log/slpkg/dep/` + """Writes dependencies in a log file + into the directory `/var/log/slpkg/dep/` """ for name, dependencies in deps_dict.items(): if find_package(f"{name}-", _meta_.pkg_path): diff --git a/slpkg/main.py b/slpkg/main.py index ebc40bdd..33b79eda 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -25,12 +25,12 @@ import os import sys -from slpkg.clean import clean_tmp from slpkg.load import Regex from slpkg.desc import PkgDesc from slpkg.messages import Msg from slpkg.config import Config from slpkg.checks import Updates +from slpkg.clean import clean_tmp from slpkg.repoinfo import RepoInfo from slpkg.repolist import RepoList from slpkg.repositories import Repo @@ -99,7 +99,7 @@ class ArgParse(BlackList): "-f", "--find" ] - # checking if repositories exists + # checking if the repositories exist enabled_repos = _meta_.repositories if len(self.args) > 1: @@ -126,7 +126,7 @@ class ArgParse(BlackList): usage("", 1) def command_update(self): - """Update package lists repositories + """Updates package lists repositories """ update = Update() @@ -143,7 +143,7 @@ class ArgParse(BlackList): usage("", 1) def command_upgrade(self): - """Recreate repositories package lists + """Recreates repositories package lists """ upgrade = Upgrade() @@ -185,7 +185,7 @@ class ArgParse(BlackList): usage("", 1) def command_repo_add(self): - """Add custom repositories + """Adds custom repositories """ if len(self.args) == 3 and self.args[0] == "repo-add": Repo().add(self.args[1], self.args[2]) @@ -193,7 +193,7 @@ class ArgParse(BlackList): usage("", 1) def command_repo_remove(self): - """Remove custom repositories + """Removes custom repositories """ if len(self.args) == 2 and self.args[0] == "repo-remove": Repo().remove(self.args[1]) @@ -214,7 +214,7 @@ class ArgParse(BlackList): usage("", 1) def command_health(self): - """Check package health + """Checks package health """ if len(self.args) == 1 and self.args[0] == "health": PackageHealth(mode="").test() @@ -225,7 +225,7 @@ class ArgParse(BlackList): usage("", 1) def command_deps_status(self): - """Print dependencies status + """Prints dependencies status """ image = "" @@ -247,7 +247,7 @@ class ArgParse(BlackList): usage("", 1) def command_new_config(self): - """Manage .new configuration files + """Manages .new configuration files """ if len(self.args) == 1 and self.args[0] == "new-config": NewConfig().run() @@ -307,7 +307,7 @@ class ArgParse(BlackList): usage("", 1) def pkg_upgrade(self): - """Check and upgrade packages by repository + """Checks and upgrade packages by repository """ options = [ "-c", @@ -322,7 +322,7 @@ class ArgParse(BlackList): ] flag, skip = self.__pkg_upgrade_flags(flags) - # Remove --checklist flag from args so that works with + # Removes --checklist flag from args so that works with # both conditions # if flags[3] in self.args: # self.args.remove(flags[3]) @@ -351,7 +351,7 @@ class ArgParse(BlackList): usage("", 1) def __pkg_upgrade_flags(self, flags): - """Manage flags for package upgrade option + """Manages flags for the package upgrade option """ # Check for typos or unssuported flags for arg in self.args[2:]: @@ -373,7 +373,7 @@ class ArgParse(BlackList): return flag, skip def pkg_install(self): - """Install packages by repository + """Installs packages by repository """ flag = [] options = [ @@ -451,7 +451,7 @@ class ArgParse(BlackList): usage("", 1) def sbo_network(self): - """View slackbuilds packages + """Views slackbuilds packages """ flag = [] options = [ @@ -479,7 +479,7 @@ class ArgParse(BlackList): usage("sbo", 1) def pkg_blacklist(self): - """Manage blacklist packages + """Manages blacklist packages """ options = [ "-b", @@ -509,7 +509,7 @@ class ArgParse(BlackList): usage("", 1) def pkg_queue(self): - """Manage packages in queue + """Manages packages in queue """ queue = QueuePkgs() options = [ @@ -555,7 +555,7 @@ class ArgParse(BlackList): usage("", 1) def bin_install(self): - """Install Slackware binary packages + """Installs Slackware binary packages """ packages = self.args[1:] options = [ @@ -583,7 +583,7 @@ class ArgParse(BlackList): usage("", 1) def bin_upgrade(self): - """Install-upgrade Slackware binary packages + """Installs, upgrades Slackware binary packages """ packages = self.args[1:] options = [ @@ -651,7 +651,7 @@ class ArgParse(BlackList): usage("", 1) def bin_find(self): - """Find installed packages + """Finds installed packages """ flag = [] options = [ @@ -681,7 +681,7 @@ class ArgParse(BlackList): usage("", 1) def pkg_desc(self): - """Print slack-desc by repository + """Prints slack-desc by repository """ options = [ "-p", @@ -722,7 +722,7 @@ class ArgParse(BlackList): usage("", 1) def pkg_find(self): - """Find packages from all enabled repositories + """Finds packages from all the enabled repositories """ flag = [] options = [ @@ -743,7 +743,7 @@ class ArgParse(BlackList): usage("", 1) def pkg_contents(self): - """Print packages contents + """Prints packages contents """ packages = self.args[1:] options = [ @@ -757,7 +757,7 @@ class ArgParse(BlackList): usage("", 1) def congiguration(self): - """Manage slpkg configuration file + """Manages slpkg configuration file """ options = [ "-g", @@ -782,7 +782,7 @@ class ArgParse(BlackList): usage("", 1) def auto_detect(self, args): - """Check for already Slackware binary packages exist + """Checks for already Slackware binary packages """ suffixes = [ ".tgz", diff --git a/slpkg/messages.py b/slpkg/messages.py index ba487e5d..b6d49ec3 100644 --- a/slpkg/messages.py +++ b/slpkg/messages.py @@ -39,23 +39,15 @@ class Msg: self.endc = _meta_.color["ENDC"] def pkg_not_found(self, bol, pkg, message, eol): - """Print message when package not found - """ print(f"{bol}No such package {pkg}: {message}{eol}") def pkg_found(self, prgnam): - """Print message when package found - """ print(f"| Package {prgnam} is already installed") def pkg_installed(self, pkg): - """Print message when package installed - """ print(f"| Package {pkg} installed") def build_FAILED(self, prgnam): - """Print error message if build failed - """ self.template(78) print(f"| Some error on the package {prgnam} " f"[ {self.red}FAILED{self.endc} ]") @@ -67,59 +59,41 @@ class Msg: print() # new line at end def template(self, max_len): - """Print template - """ print("+" + "=" * max_len) def checking(self): - """Message checking - """ print(f"{self.grey}Checking...{self.endc} ", end="", flush=True) def reading(self): - """Message reading - """ print(f"{self.grey}Reading package lists...{self.endc} ", end="", flush=True) def resolving(self): - """Message resolving - """ print(f"{self.grey}Resolving dependencies...{self.endc} ", end="", flush=True) def done(self): - """Message done - """ print(f"\b{self.green}Done{self.endc}\n", end="") def pkg(self, count): - """Print singular plural - """ message = "package" if count > 1: message = message + "s" return message def not_found(self, if_upgrade): - """Message not found packages - """ if if_upgrade: print("\nNot found packages for upgrade\n") else: print("\nNot found packages for installation\n") def upg_inst(self, if_upgrade): - """Message installing or upgrading - """ if not if_upgrade: print("Installing:") else: print("Upgrading:") def answer(self): - """Message answer - """ if self.meta.default_answer in ["y", "Y"]: answer = self.meta.default_answer else: @@ -130,8 +104,6 @@ class Msg: return answer def security_pkg(self, pkg): - """Warning message for some special reasons - """ print() self.template(78) print(f"| {' ' * 27}{self.red}*** WARNING ***{self.endc}") @@ -143,9 +115,6 @@ class Msg: print() def reference(self, install, upgrade): - """Reference list with packages installed - and upgraded - """ self.template(78) print(f"| Total {len(install)} {self.pkg(len(install))} installed and " f"{len(upgrade)} {self.pkg(len(upgrade))} upgraded") @@ -159,8 +128,6 @@ class Msg: print() def matching(self, packages): - """Message for matching packages - """ print(f"\nNot found package with the name " f"[ {self.cyan}{''.join(packages)}{self.endc} ]. " "Matching packages:\nNOTE: Not dependencies are resolved\n") diff --git a/slpkg/new_config.py b/slpkg/new_config.py index 2161a693..229b9180 100644 --- a/slpkg/new_config.py +++ b/slpkg/new_config.py @@ -32,7 +32,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class NewConfig(Utils): - """Manage .new configuration files + """Manages .new configuration files """ def __init__(self): self.meta = _meta_ @@ -47,7 +47,7 @@ class NewConfig(Utils): self.news = [] def run(self): - """print .new configuration files + """prints .new configuration files """ self.find_new() for n in self.news: @@ -59,7 +59,7 @@ class NewConfig(Utils): self.choices() def find_new(self): - """Find all '.new' files from /etc/ folder + """Finds all '.new' files from /etc/ folder and subfolders """ print("Search for .new configuration files:\n") @@ -97,14 +97,14 @@ class NewConfig(Utils): self.prompt() def overwrite_all(self): - """Overwrite all .new files and keep + """Overwrites all .new files and keep old with suffix .old """ for n in self.news: self._overwrite(n) def remove_all(self): - """Remove all .new files + """Removes all .new files """ for n in self.news: self._remove(n) @@ -131,7 +131,7 @@ class NewConfig(Utils): raise SystemExit("\n") def question(self, n): - """Choose what do to file by file + """Chooses what do to file by file """ print() prompt_ask = input(f"{n} [K/O/R/D/M/Q]? ") @@ -151,7 +151,7 @@ class NewConfig(Utils): self.quit() def _remove(self, n): - """Remove one single file + """Removes one single file """ if os.path.isfile(n): os.remove(n) @@ -159,7 +159,7 @@ class NewConfig(Utils): print(f"File '{n}' removed") def _overwrite(self, n): - """Overwrite old file with new and keep file with suffix .old + """Overwrites old file with new and keep file with suffix .old """ if os.path.isfile(n[:-4]): shutil.copy2(n[:-4], n[:-4] + ".old") @@ -174,7 +174,7 @@ class NewConfig(Utils): pass def diff(self, n): - """Print the differences between the two files + """Prints the differences between the two files """ if os.path.isfile(n[:-4]): diff1 = self.read_file(n[:-4]).splitlines() @@ -203,7 +203,7 @@ class NewConfig(Utils): lines.append(a) def merge(self, n): - """Merge new file into old + """Merges new file into old """ if os.path.isfile(n[:-4]): old = self.read_file(n[:-4]).splitlines() diff --git a/slpkg/pkg_find.py b/slpkg/pkg_find.py index 54b692db..ab8947bc 100644 --- a/slpkg/pkg_find.py +++ b/slpkg/pkg_find.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class FindFromRepos: - """Find packages from all enabled repositories + """Finds packages from all enabled repositories """ def __init__(self): self.cache = "" @@ -44,7 +44,7 @@ class FindFromRepos: self.endc = self.meta.color["ENDC"] def find(self, pkg, flag): - """Start to find packages and print + """Starts to find packages and print """ print(f"Packages with name matching [ {self.cyan}" f"{', '.join(pkg)}{self.endc} ]\n") @@ -78,8 +78,7 @@ class FindFromRepos: f"{self.count_repo} repositories.{self.endc}\n") def sbo_version(self, repo, find): - """ - Add version to SBo packages + """Adds version to SBo packages """ ver = "" if repo == "sbo": diff --git a/slpkg/remove.py b/slpkg/remove.py index 3f9d22df..4f527d69 100644 --- a/slpkg/remove.py +++ b/slpkg/remove.py @@ -30,7 +30,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def delete_package(path, packages): - """Delete downloaded packages + """Deletes downloaded packages """ if _meta_.del_all in ["on", "ON"]: for pkg in packages: @@ -38,7 +38,7 @@ def delete_package(path, packages): def delete_folder(folder): - """Delete folder with all files. + """Deletes folder with all files. """ if _meta_.del_folder in ["on", "ON"] and os.path.exists(folder): shutil.rmtree(folder) diff --git a/slpkg/repoenable.py b/slpkg/repoenable.py index 17949cfc..1cfcd333 100644 --- a/slpkg/repoenable.py +++ b/slpkg/repoenable.py @@ -31,7 +31,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class RepoEnable(Utils): - """Read repositories.conf file and update with new enabled or + """Reads repositories.conf file and update with new enabled or disabled repositories """ def __init__(self): @@ -77,7 +77,7 @@ Keys: SPACE select or deselect the highlighted repositories, self.reference() def read_enabled(self): - """Read enable repositories + """Reads enabled repositories """ for line in self.conf.splitlines(): line = line.lstrip() @@ -89,7 +89,7 @@ Keys: SPACE select or deselect the highlighted repositories, self.tag_line = False def read_disabled(self): - """Read disable repositories + """Reads disabled repositories """ for line in self.conf.splitlines(): line = line.lstrip() diff --git a/slpkg/repoinfo.py b/slpkg/repoinfo.py index 15c0c459..7069c19b 100644 --- a/slpkg/repoinfo.py +++ b/slpkg/repoinfo.py @@ -57,7 +57,7 @@ class RepoInfo(Utils): def view(self, repo): """ - View repository information + Views repository information """ status = f"{self.red}disabled{self.endc}" self.form["Status:"] = status @@ -109,7 +109,7 @@ class RepoInfo(Utils): print(f"{self.green}{key}{self.endc} {value}") def repository_data(self, repo): - """Grap data packages + """Graps data packages """ sum_pkgs, size, unsize, last_upd = 0, [], [], "" f = f"{self.meta.lib_path}{repo}_repo/PACKAGES.TXT" diff --git a/slpkg/repositories.py b/slpkg/repositories.py index d7ee25bc..9e0608c0 100644 --- a/slpkg/repositories.py +++ b/slpkg/repositories.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class Repo(Utils): - """Manage repositories configuration files + """Manages repositories configuration files """ def __init__(self): self.meta = _meta_ @@ -43,7 +43,7 @@ class Repo(Utils): self.default_repository() def add(self, repo, url): - """Write custom repository name and url in a file + """Writes custom repository name and url in a file """ repo_name = [] if not url.endswith("/"): @@ -67,7 +67,7 @@ class Repo(Utils): print(f"\nRepository '{repo}' successfully added\n") def remove(self, repo): - """Remove custom repository + """Removes custom repository """ rem_repo = False with open(self.custom_repo_file, "w") as repos: @@ -83,7 +83,7 @@ class Repo(Utils): print(f"\nRepository '{repo}' doesn't exist\n") def custom_repository(self): - """Return dictionary with repo name and url (used external) + """Returns dictionary with repo name and url (used external) """ custom_dict_repo = {} for line in self.custom_repositories_list.splitlines(): @@ -93,7 +93,7 @@ class Repo(Utils): return custom_dict_repo def default_repository(self): - """Return dictionary with default repo name and url + """Returns dictionary with default repo name and url """ default_dict_repo = {} for line in self.default_repositories_list.splitlines(): diff --git a/slpkg/security.py b/slpkg/security.py index 5eb066bd..655c1983 100644 --- a/slpkg/security.py +++ b/slpkg/security.py @@ -27,7 +27,7 @@ from slpkg.messages import Msg def pkg_security(pkgs): - """Check packages before install or upgrade for security + """Checks packages before installing or upgrading for security reasons. Configuration file in the /etc/slpkg/pkg_security""" packages, msg, utils = [], Msg(), Utils() security_packages = utils.read_file("/etc/slpkg/pkg_security") diff --git a/slpkg/sizes.py b/slpkg/sizes.py index 54914350..d0f8426e 100644 --- a/slpkg/sizes.py +++ b/slpkg/sizes.py @@ -23,7 +23,7 @@ def units(comp_sum, uncomp_sum): - """Calculate package size + """Calculates package size """ compressed = round((sum(map(float, comp_sum)) / 1024), 2) uncompressed = round((sum(map(float, uncomp_sum)) / 1024), 2) diff --git a/slpkg/slpkg_update.py b/slpkg/slpkg_update.py index ccef7604..e6a8d3c3 100644 --- a/slpkg/slpkg_update.py +++ b/slpkg/slpkg_update.py @@ -35,8 +35,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def it_self_update(): - """Check from GitLab slpkg repository if new version is available - download and update itself + """Checks from GitLab slpkg repository if a new version is available """ __new_version__ = "" repository = "gitlab" diff --git a/slpkg/splitting.py b/slpkg/splitting.py index b6e4e255..5c393b04 100644 --- a/slpkg/splitting.py +++ b/slpkg/splitting.py @@ -23,8 +23,7 @@ def split_package(package): - """ - Split package in name, version + """Splits package in name, version arch and build tag. """ name = ver = arch = build = [] diff --git a/slpkg/status_deps.py b/slpkg/status_deps.py index cf930ebd..5492925f 100644 --- a/slpkg/status_deps.py +++ b/slpkg/status_deps.py @@ -34,7 +34,7 @@ from slpkg.pkg.find import find_package class DependenciesStatus(Utils): - """Print dependencies status used by packages + """Prints dependencies status used by packages """ def __init__(self, image): self.image = image @@ -53,7 +53,7 @@ class DependenciesStatus(Utils): self.installed = find_package("", self.meta.pkg_path) def data(self): - """Check all installed packages and create + """Checks all installed packages and create dictionary database """ for pkg in self.installed: @@ -72,7 +72,7 @@ class DependenciesStatus(Utils): self.count_packages() def count_packages(self): - """Count dependencies and packages + """Counts dependencies and packages """ packages = [] for pkg in self.dmap.values(): diff --git a/slpkg/superuser.py b/slpkg/superuser.py index 123e3c38..1e2da766 100644 --- a/slpkg/superuser.py +++ b/slpkg/superuser.py @@ -27,14 +27,14 @@ import getpass def s_user(): - """Check for root user + """Checks for root user """ if getpass.getuser() != "root": raise SystemExit("\nslpkg: Error: Must have root privileges\n") def virtual_env(): - """Check if a virtual enviroment exists + """Checks if a virtual enviroment exists """ if "VIRTUAL_ENV" in os.environ.keys(): raise SystemExit("\nslpkg: Error: Please exit from virtual " diff --git a/slpkg/tracking.py b/slpkg/tracking.py index ca80e4c7..ec8771c7 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -39,9 +39,9 @@ from slpkg.binary.dependency import Dependencies class TrackingDeps(BlackList, Utils): - """View tree of dependencies and also - highlight packages with color green - if already installed and color red + """Views tree of dependencies and also + highlights packages with the colour green + if already installed and the colour red if not installed. """ def __init__(self, name, repo, flag): @@ -71,7 +71,7 @@ class TrackingDeps(BlackList, Utils): self.flag[i] = "--graph=" def run(self): - """Run tracking dependencies + """Runs tracking dependencies """ self.msg.resolving() self.repositories() @@ -124,7 +124,7 @@ class TrackingDeps(BlackList, Utils): raise SystemExit("\nNo package was found to match\n") def repositories(self): - """Get dependencies by repositories + """Gets dependencies by repositories """ if self.repo == "sbo": self.sbo_case_insensitive() @@ -169,7 +169,7 @@ class TrackingDeps(BlackList, Utils): Graph(self.image).dependencies(self.deps_dict) def check_used(self, pkg): - """Check if dependencies used + """Checks if dependencies used """ used = [] dep_path = f"{self.meta.log_path}dep/" @@ -197,7 +197,7 @@ class TrackingDeps(BlackList, Utils): self.deps_dict[dep] = self.dimensional_list(deps) def deps_used(self, pkg, used): - """Create dependencies dictionary + """Creates dependencies dictionary """ if find_package(f"{pkg}-", self.meta.pkg_path): if pkg not in self.deps_dict.values(): diff --git a/slpkg/url_read.py b/slpkg/url_read.py index 18fc8c33..3c0fca25 100644 --- a/slpkg/url_read.py +++ b/slpkg/url_read.py @@ -41,7 +41,7 @@ class URL: self.http = urllib3.PoolManager() def get_request(self): - """Open url and read + """Opens url and read """ try: f = self.http.request('GET', self.link) diff --git a/slpkg/utils.py b/slpkg/utils.py index 39e33ed5..275dea63 100644 --- a/slpkg/utils.py +++ b/slpkg/utils.py @@ -29,7 +29,7 @@ from slpkg.splitting import split_package class Utils: - """Class with usefull utilities + """Class with useful utilities """ def case_sensitive(self, lst): """Create dictionary from list with key in lower case @@ -41,7 +41,7 @@ class Utils: return dictionary def dimensional_list(self, lists): - """Create one dimensional list + """Creates one dimensional list """ one_list = [] for lst in lists: @@ -49,7 +49,7 @@ class Utils: return one_list def remove_dbs(self, double): - """Remove double item from list + """Removes double item from list """ return list(OrderedDict.fromkeys(double)) @@ -71,7 +71,7 @@ class Utils: yield split_package(line[14:].strip())[0] def check_downloaded(self, path, downloaded): - """Check if files downloaded and return downloaded + """Checks if files downloaded and return downloaded packages """ for pkg in downloaded: @@ -79,8 +79,8 @@ class Utils: yield pkg def read_config(self, config): - """Read config file and returns first uncomment line - and stop. Used for Slackware mirrors + """Reads config file and returns first uncomment line + and stops. Used for Slackware mirrors """ for line in config.splitlines(): line = line.lstrip() @@ -107,6 +107,6 @@ class Utils: return "ISO-8859-1" def debug(self, test): - """Function used for print some stuff for debugging + """A function used for print some stuff for debugging """ print(test) diff --git a/slpkg/version.py b/slpkg/version.py index 6bcd049d..eed320f7 100644 --- a/slpkg/version.py +++ b/slpkg/version.py @@ -26,7 +26,7 @@ from slpkg.__metadata__ import MetaData as m def prog_version(): - """Print version, license and email + """Prints version, license and email """ print(f"Version : {m.__version__}\n" f"Licence : {m.__license__}\n" From c59dbc0b81ed5e2fd9e666b83e24ce62b4770e17 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 21:49:03 +0300 Subject: [PATCH 16/23] Fixed typos --- slpkg/__metadata__.py | 28 +++++++++++-------------- slpkg/auto_pkg.py | 4 ++-- slpkg/binary/dependency.py | 2 +- slpkg/binary/greps.py | 4 ++-- slpkg/binary/install.py | 19 ++++++++--------- slpkg/binary/repo_init.py | 2 +- slpkg/binary/search.py | 2 +- slpkg/pkg/build.py | 28 +++++++++++-------------- slpkg/pkg/installed.py | 6 +++--- slpkg/pkg/manager.py | 43 +++++++++++++++++++------------------- slpkg/utils.py | 2 +- 11 files changed, 65 insertions(+), 75 deletions(-) diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index 11728094..e47b395f 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -31,8 +31,7 @@ CURRENT = "current" def remove_repositories(repositories, default_repositories): - """ - Remove no default repositories + """Removes no default repositories """ for repo in repositories: if repo in default_repositories: @@ -40,8 +39,7 @@ def remove_repositories(repositories, default_repositories): def update_repositories(repositories, conf_path): - """ - Upadate with user custom repositories + """Upadate with user custom repositories """ repo_file = f"{conf_path}custom-repositories" if os.path.isfile(repo_file): @@ -56,8 +54,7 @@ def update_repositories(repositories, conf_path): def grab_sub_repo(repositories, repos): - """ - Grab SUB_REPOSITORY + """Grabs SUB_REPOSITORY """ for i, repo in enumerate(repositories): if repos in repo: @@ -68,8 +65,7 @@ def grab_sub_repo(repositories, repos): def select_slack_release(slack_rel): - """ - Warning message if Slackware release not defined or + """Warning message if Slackware release not defined or defined wrong """ if slack_rel not in [STABLE, CURRENT]: @@ -137,7 +133,7 @@ class MetaData: "slonly", "ktown", "multi", "slacke", "salix", "slackl", "rested", "msb", "csb", "connos", "mles"] - # read value from configuration file + # reads values from the configuration file repositories = [] for files in ["slpkg.conf", "repositories.conf"]: if os.path.isfile(f"{conf_path}{files}"): @@ -152,7 +148,7 @@ class MetaData: elif files == "repositories.conf": repositories.append(line) - # Set values from configuration file + # Sets values from the configuration file slack_rel = _conf_slpkg["RELEASE"] slackware_version = _conf_slpkg["SLACKWARE_VERSION"] comp_arch = _conf_slpkg["COMP_ARCH"] @@ -183,22 +179,22 @@ class MetaData: # SBo downloading sources path SBo_SOURCES = build_path + "_SOURCES/" - # Remove any gaps + # Removes any gaps repositories = [repo.strip() for repo in repositories] - # Check Slackware release + # Checks Slackware release slack_rel = select_slack_release(slack_rel) - # Grap sub repositories + # Grabs sub repositories ktown_kde_repo = grab_sub_repo(repositories, "ktown") slacke_sub_repo = grab_sub_repo(repositories, "slacke") msb_sub_repo = grab_sub_repo(repositories, "msb") mles_sub_repo = grab_sub_repo(repositories, "mles") - # remove no default repositories + # removes no default repositories repositories = list(remove_repositories(repositories, default_repositories)) - # add custom repositories + # adds custom repositories update_repositories(repositories, conf_path) color = { @@ -250,7 +246,7 @@ class MetaData: else: arch = comp_arch - # get sbo OUTPUT enviroment variable + # gets sbo OUTPUT enviroment variable try: output = os.environ["OUTPUT"] except KeyError: diff --git a/slpkg/auto_pkg.py b/slpkg/auto_pkg.py index 00cab8cc..61071ba0 100644 --- a/slpkg/auto_pkg.py +++ b/slpkg/auto_pkg.py @@ -29,7 +29,7 @@ from slpkg.pkg.manager import PackageManager class AutoInstall: - """Select Slackware command to install packages + """Select the Slackware command to install packages """ def __init__(self, packages): self.packages = packages @@ -69,7 +69,7 @@ class AutoInstall: self.execute() def execute(self): - """Execute Slackware command + """Executes Slackware command """ if self.choice in self.commands.keys(): if self.choice == "i": diff --git a/slpkg/binary/dependency.py b/slpkg/binary/dependency.py index f22416b6..5b3ee40d 100644 --- a/slpkg/binary/dependency.py +++ b/slpkg/binary/dependency.py @@ -40,7 +40,7 @@ class Dependencies: self.meta = _meta_ def binary(self, name, flag): - """Build all dependencies of a package + """Builds all dependencies of a package """ if self.meta.rsl_deps in ["on", "ON"] and "--resolve-off" not in flag: sys.setrecursionlimit(10000) diff --git a/slpkg/binary/greps.py b/slpkg/binary/greps.py index b1404e78..ba2f5939 100644 --- a/slpkg/binary/greps.py +++ b/slpkg/binary/greps.py @@ -31,7 +31,7 @@ from slpkg.slack.slack_version import slack_ver def repo_data(PACKAGES_TXT, repo, flag): - """Grap data packages + """Grabs data packages """ (name, location, size, unsize, rname, rlocation, rsize, runsize) = ([] for i in range(8)) @@ -180,7 +180,7 @@ class Requires: self.repo = repo def get_deps(self): - """Grap package requirements from repositories + """Grabs package requirements from repositories """ if self.repo == "rlw": dependencies = {} diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index 41580973..f3fd72c2 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -49,7 +49,7 @@ from slpkg.binary.dependency import Dependencies class BinaryInstall(BlackList, Utils): - """Install binaries packages with all dependencies from + """Installs binaries packages with all dependencies from repository """ def __init__(self, packages, repo, flag): @@ -94,8 +94,7 @@ class BinaryInstall(BlackList, Utils): self.tmp_path += "/" def start(self, is_upgrade): - """ - Install packages from official Slackware distribution + """Installs packages from official Slackware distribution """ self.case_insensitive() # fix if packages is for upgrade @@ -175,7 +174,7 @@ class BinaryInstall(BlackList, Utils): raise SystemExit(1) def if_all_installed(self): - """Check if all packages is already installed + """Checks if all packages is already installed """ count_inst = 0 for inst in (self.dep_install + self.install): @@ -200,7 +199,7 @@ class BinaryInstall(BlackList, Utils): self.packages[index] = value def update_deps(self): - """Update dependencies dictionary with all package + """Updates dependencies dictionary with all package """ for dep in self.dependencies: deps = self.dimensional_list(Dependencies( @@ -219,7 +218,7 @@ class BinaryInstall(BlackList, Utils): self.packages = packages def install_packages(self): - """Install or upgrade packages + """Installs or upgrades packages """ installs, upgraded = [], [] for inst in (self.dep_install + self.install): @@ -259,7 +258,7 @@ class BinaryInstall(BlackList, Utils): check_md5(pkg_checksum(install, self.repo), self.tmp_path + install) def resolving_deps(self): - """Return package dependencies + """Returns package dependencies """ requires = [] if (self.meta.rsl_deps in ["on", "ON"] and @@ -274,7 +273,7 @@ class BinaryInstall(BlackList, Utils): return self.remove_dbs(requires) def _fix_deps_repos(self, dependencies): - """Fix store deps include in repository + """Fixes store deps include in the repository """ for dep in dependencies: if dep in self.repo_pkg_names: @@ -311,7 +310,7 @@ class BinaryInstall(BlackList, Utils): return [pkg_sum, res_sum, upg_sum, uni_sum] def top_view(self): - """Print packages status bar + """Prints packages status bar """ self.msg.template(78) print(f"| Package{' ' * 17}New Version{' ' * 8}Arch{' ' * 4}" @@ -319,7 +318,7 @@ class BinaryInstall(BlackList, Utils): self.msg.template(78) def store(self, packages): - """Store and return packages for install + """Stores and returns packages for install """ dwn, install, comp_sum, uncomp_sum = ([] for i in range(4)) # name = data[0] diff --git a/slpkg/binary/repo_init.py b/slpkg/binary/repo_init.py index 241615c8..b1370978 100644 --- a/slpkg/binary/repo_init.py +++ b/slpkg/binary/repo_init.py @@ -31,7 +31,7 @@ from slpkg.slack.slack_version import slack_ver class RepoInit(Utils): - """Return PACKAGES.TXT and mirror by repository + """Returns PACKAGES.TXT and mirror by repository """ def __init__(self, repo): self.repo = repo diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py index b42379a4..e55e3a7d 100644 --- a/slpkg/binary/search.py +++ b/slpkg/binary/search.py @@ -28,7 +28,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def search_pkg(name, repo): - """Search if package exists in PACKAGES.TXT file + """Searching if the package exists in PACKAGES.TXT file and return the name. """ utils = Utils() diff --git a/slpkg/pkg/build.py b/slpkg/pkg/build.py index 241e749a..007450f8 100644 --- a/slpkg/pkg/build.py +++ b/slpkg/pkg/build.py @@ -41,7 +41,7 @@ from slpkg.sbo.greps import SBoGrep class BuildPackage(Utils): - """Build SBo packages from source + """Builds SBo packages from source """ def __init__(self, script, sources, path, auto): self.script = script @@ -66,10 +66,9 @@ class BuildPackage(Utils): os.mkdir(self.build_logs) def build(self): - """ - Build package from source and create log + """Builds package from source and creates log file in path /var/log/slpkg/sbo/build_logs/. - Also check md5sum calculates. + Also checks the md5sum calculation. """ try: self._delete_dir() @@ -115,7 +114,7 @@ class BuildPackage(Utils): self.msg.pkg_not_found("\n", self.prgnam, "Wrong file", "\n") def _check_sources(self): - """Fix filenames with char + + """Fixes filenames with char + """ new_sources = [] for src in self.sources: @@ -123,7 +122,7 @@ class BuildPackage(Utils): self.sources = new_sources def _create_md5_dict(self): - """Create md5 dictionary per source + """Creates md5 dictionary per source """ self.sbo_md5 = {} md5_lists = SBoGrep(self.prgnam).checksum() @@ -131,7 +130,7 @@ class BuildPackage(Utils): self.sbo_md5[src] = md5 def _makeflags(self): - """Set variable MAKEFLAGS with the numbers of + """Sets variable MAKEFLAGS with the numbers of processors """ if self.meta.makeflags in ["on", "ON"]: @@ -139,7 +138,7 @@ class BuildPackage(Utils): os.environ["MAKEFLAGS"] = f"-j{cpus}" def _pass_variable(self): - """Return enviroment variables + """Returns enviroment variables """ pass_var = [] for var in os.environ.keys(): @@ -149,21 +148,20 @@ class BuildPackage(Utils): return pass_var def _delete_sbo_tar_gz(self): - """Delete slackbuild tar.gz file after untar + """Deletes slackbuild tar.gz file after untar """ if not self.auto and os.path.isfile(self.meta.build_path + self.script): os.remove(self.meta.build_path + self.script) def _delete_dir(self): - """Delete old folder if exists before start build + """Deletes old folder if exists before start build """ if not self.auto and os.path.isdir(self.meta.build_path + self.prgnam): shutil.rmtree(self.meta.build_path + self.prgnam) def log_head(path, log_file, log_time): - """ - write headers to log file + """Writes headers to log file """ with open(path + log_file, "w") as log: log.write("#" * 79 + "\n\n") @@ -175,8 +173,7 @@ def log_head(path, log_file, log_time): def log_end(path, log_file, sum_time): - """ - append END tag to a log file + """Appends END tag to a log file """ with open(path + log_file, "a") as log: log.seek(2) @@ -188,8 +185,7 @@ def log_end(path, log_file, sum_time): def build_time(start_time): - """ - Calculate build time per package + """Calculates build time per package """ diff_time = round(time.time() - start_time, 2) if diff_time <= 59.99: diff --git a/slpkg/pkg/installed.py b/slpkg/pkg/installed.py index 5a3cd845..99c34961 100644 --- a/slpkg/pkg/installed.py +++ b/slpkg/pkg/installed.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ class GetFromInstalled: - """Find and return version and package name from + """Finds and returns version and package name from already installed packages """ def __init__(self, package): @@ -42,14 +42,14 @@ class GetFromInstalled: self.find = file def version(self): - """Return version from installed packages + """Returns version from installed packages """ if self.find: return split_package(self.find)[1] return self.find def name(self): - """Return installed package name + """Returns installed package name """ if self.find: return self.package diff --git a/slpkg/pkg/manager.py b/slpkg/pkg/manager.py index 0fd1261b..94bfdd3c 100644 --- a/slpkg/pkg/manager.py +++ b/slpkg/pkg/manager.py @@ -58,7 +58,7 @@ class PackageManager(Utils): self.unit = "Kb" def install(self, flag): - """Install Slackware binary packages + """Installs Slackware binary packages """ for pkg in self.binary: try: @@ -73,7 +73,7 @@ class PackageManager(Utils): raise SystemExit(1) def upgrade(self, flag): - """Upgrade Slackware binary packages with new + """Upgrades Slackware binary packages with new """ for pkg in self.binary: try: @@ -95,7 +95,7 @@ class PackageManager(Utils): self.msg.pkg_not_found(bol, pkg, message, eol) def remove(self, flag, extra): - """Remove Slackware binary packages + """Removes Slackware binary packages """ self.flag = flag self.extra = extra @@ -120,10 +120,9 @@ class PackageManager(Utils): if remove_pkg in ["y", "Y"]: self._check_if_used(self.binary) for rmv in self.removed: - ''' - If package build and install with "slpkg -s sbo " - then look log file for dependencies in /var/log/slpkg/dep, - read and remove all else remove only the package. + '''If package build and install with "slpkg -s sbo " + then looks in the log file for dependencies "/var/log/slpkg/dep", + reads and removes all but remove only the package. ''' if (os.path.isfile(self.dep_path + rmv) and self.meta.del_deps in ["on", "ON"] or @@ -141,7 +140,7 @@ class PackageManager(Utils): self._reference_rmvs(rmv_list) def _rmv_deps_answer(self): - """Remove dependencies answer + """Removes dependencies answer """ if self.meta.remove_deps_answer in ["y", "Y"]: remove_dep = self.meta.remove_deps_answer @@ -156,7 +155,7 @@ class PackageManager(Utils): return remove_dep def _get_removed(self): - """Manage removed packages by extra options + """Manages removed packages by extra options """ extra = self.extra removed, packages, pkg = [], [], "" @@ -195,7 +194,7 @@ class PackageManager(Utils): return removed, packages def _view_removed(self): - """View packages before removed + """Views packages before removed """ print("Packages with name matching [ {0}{1}{2} ]\n".format( self.cyan, ", ".join(self.binary), self.endc)) @@ -248,7 +247,7 @@ class PackageManager(Utils): self.grey, round(self.size, 2), self.unit, self.endc)) def _view_deps(self, path, package): - """View dependencies before remove + """Views dependencies before remove """ self.size = 0 packages = [] @@ -297,7 +296,7 @@ class PackageManager(Utils): raise SystemExit(er) def _rmv_deps(self, dependencies, package): - """Remove dependencies + """Removes dependencies """ removes = [] dependencies.append(package) @@ -310,7 +309,7 @@ class PackageManager(Utils): return removes def _rmv_pkg(self, package): - """Remove one signle package + """Removes one signle package """ removes = [] if GetFromInstalled(package).name() and package not in self.skip: @@ -335,7 +334,7 @@ class PackageManager(Utils): self.removed.remove(s) def _check_if_used(self, removes): - """Check package if dependencies for another package + """Checks package if dependencies for another package before removed""" if "--check-deps" in self.extra: package, dependency, pkg_dep = [], [], [] @@ -387,7 +386,7 @@ class PackageManager(Utils): print() # new line at end def find(self, flag): - """Find installed Slackware packages + """Finds installed Slackware packages """ matching, packages = 0, [] pkg_cache, match_cache = "", "" @@ -447,7 +446,7 @@ class PackageManager(Utils): break def display(self): - """Print the Slackware packages contents + """Prints the Slackware packages contents """ for pkg in self.binary: name = GetFromInstalled(pkg).name() @@ -502,7 +501,7 @@ class PackageManager(Utils): raise SystemExit(1) def _splitting_packages(self, pkg, repo, name): - """Return package name from repositories + """Returns package name from repositories """ if name and repo != "sbo": pkg = split_package(pkg)[0] @@ -511,7 +510,7 @@ class PackageManager(Utils): return pkg def list_greps(self, repo, packages): - """Grep packages + """Grabs packages """ pkg_list, pkg_size = [], [] for line in packages.splitlines(): @@ -529,7 +528,7 @@ class PackageManager(Utils): return pkg_list, pkg_size def list_lib(self, repo): - """Return package lists + """Returns package lists """ packages = "" if repo == "sbo": @@ -545,7 +544,7 @@ class PackageManager(Utils): return packages def list_color_tag(self, pkg): - """Tag with color installed packages + """Tag with colour installed packages """ name = GetFromInstalled(pkg).name() find = f"{name}-" @@ -556,7 +555,7 @@ class PackageManager(Utils): return pkg def list_of_installed(self, repo, name): - """Return installed packages + """Returns installed packages """ all_installed_names = [] all_installed_packages = find_package("", self.meta.pkg_path) @@ -573,7 +572,7 @@ class PackageManager(Utils): def alien_filter(packages, sizes): - """This filter avoid list double packages from + """This filter avoids listing double packages from alien repository """ cache, npkg, nsize = [], [], [] diff --git a/slpkg/utils.py b/slpkg/utils.py index 275dea63..51e07b5d 100644 --- a/slpkg/utils.py +++ b/slpkg/utils.py @@ -107,6 +107,6 @@ class Utils: return "ISO-8859-1" def debug(self, test): - """A function used for print some stuff for debugging + """A function used to print some stuff for debugging """ print(test) From 354d6f9f3546211777a5fb3a1f67147d552267d6 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 21:54:29 +0300 Subject: [PATCH 17/23] Fixed typos --- slpkg/slack/mirrors.py | 2 +- slpkg/slack/patches.py | 18 +++++++++--------- slpkg/slack/slack_version.py | 3 +-- slpkg/slack/slackware_repo.py | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/slpkg/slack/mirrors.py b/slpkg/slack/mirrors.py index f9e3d475..0498d23c 100644 --- a/slpkg/slack/mirrors.py +++ b/slpkg/slack/mirrors.py @@ -29,7 +29,7 @@ from slpkg.slack.slack_version import slack_ver def mirrors(name, location): - """Select Slackware official mirror packages + """Selects Slackware official mirror packages based architecture and version. """ rel = _meta_.slack_rel diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py index f92e5ac0..94890f03 100644 --- a/slpkg/slack/patches.py +++ b/slpkg/slack/patches.py @@ -53,7 +53,7 @@ from slpkg.slack.slack_version import slack_ver class Patches(BlackList, Utils): - """Upgrade distribution from official Slackware mirrors + """Upgrades distribution from the official Slackware mirrors """ def __init__(self, skip, flag): super().__init__() @@ -85,7 +85,7 @@ class Patches(BlackList, Utils): self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "")).get_request() def start(self): - """Install new patches from official Slackware mirrors + """Installs new patches from official Slackware mirrors """ self.store() self.msg.done() @@ -132,7 +132,7 @@ class Patches(BlackList, Utils): f" distribution is up to date!\n") def store(self): - """Store and return packages for upgrading + """Stores and returns packages for upgrading """ data = repo_data(self.PACKAGES_TXT, "slack", self.flag) black = list(self.get_black()) @@ -169,7 +169,7 @@ class Patches(BlackList, Utils): return self.count_upg def dialog_checklist(self): - """Create checklist to choose packages for upgrade + """Creates checklist to choose packages for upgrade """ data = [] for upg in self.upgrade_all: @@ -214,7 +214,7 @@ class Patches(BlackList, Utils): f"{' ' * (7-len(pkg_repo[3]))}Slack{size:>12} K") def upgrade(self): - """Upgrade packages + """Upgrades packages """ for pkg in self.upgrade_all: check_md5(pkg_checksum(pkg, "slack_patches"), @@ -233,8 +233,8 @@ class Patches(BlackList, Utils): self.installed.append(pkg_ver) def kernel(self): - """Check if kernel upgraded if true - then reinstall "lilo" + """Checks if kernel upgraded if true + then reinstall boot loader """ for core in self.upgrade_all: if "kernel" in core: @@ -264,7 +264,7 @@ class Patches(BlackList, Utils): break def slackpkg_update(self): - """This replace slackpkg ChangeLog.txt file with new + """This replace slackpkg ChangeLog.txt file with new one from Slackware official mirrors after update distribution. """ NEW_ChangeLog_txt = URL(mirrors("ChangeLog.txt", "")).get_request() @@ -278,7 +278,7 @@ class Patches(BlackList, Utils): log.write(NEW_ChangeLog_txt) def update_lists(self): - """Update packages list and ChangeLog.txt file after + """Updates packages list and ChangeLog.txt file after upgrade distribution """ print(f"{self.green}Update the package lists ?{self.endc}") diff --git a/slpkg/slack/slack_version.py b/slpkg/slack/slack_version.py index 23940232..aafe1e47 100644 --- a/slpkg/slack/slack_version.py +++ b/slpkg/slack/slack_version.py @@ -29,8 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def slack_ver(): - """ - Open file and read Slackware version + """Opens the file and read Slackware version """ utils = Utils() if _meta_.slackware_version in ["off", "OFF"]: diff --git a/slpkg/slack/slackware_repo.py b/slpkg/slack/slackware_repo.py index 639e3c94..48b24551 100644 --- a/slpkg/slack/slackware_repo.py +++ b/slpkg/slack/slackware_repo.py @@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_ def slackware_repository(): - """Return all official Slackware packages + """Returns all official Slackware packages """ utils = Utils() slack_repo, packages, names = [], [], [] From e8dbcd5a6dddba9fbedd627074abb518b880db2a Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 21:56:49 +0300 Subject: [PATCH 18/23] Fixed typos --- slpkg/binary/check.py | 2 +- slpkg/desc.py | 4 ++-- slpkg/dialog_box.py | 8 ++++---- slpkg/repoenable.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slpkg/binary/check.py b/slpkg/binary/check.py index 5336665d..014874dd 100644 --- a/slpkg/binary/check.py +++ b/slpkg/binary/check.py @@ -65,6 +65,6 @@ def pkg_upgrade(repo, skip, flag): def installed(): - """Return all installed packages + """Returns all installed packages """ return find_package("", _meta_.pkg_path) diff --git a/slpkg/desc.py b/slpkg/desc.py index 8c81afa9..cccc1a66 100644 --- a/slpkg/desc.py +++ b/slpkg/desc.py @@ -30,7 +30,7 @@ from slpkg.sbo.greps import SBoGrep class PkgDesc(Utils): - """Print package description from the repository + """Prints package description from the repository """ def __init__(self, name, repo, paint): self.name = name @@ -51,7 +51,7 @@ class PkgDesc(Utils): self.lib = f"{self.meta.lib_path}{self.repo}_repo/PACKAGES.TXT" def view(self): - """Print package description by repository + """Prints package description by repository """ description, count = "", 0 if self.repo == "sbo": diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index 9a44fdb7..ddba6836 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -48,7 +48,7 @@ class DialogUtil: self.d = Dialog(dialog="dialog", autowidgetsize=True) def checklist(self): - """Run dialog checklist + """Runs dialog checklist """ choice = [] for item in self.data: @@ -63,7 +63,7 @@ class DialogUtil: self.exit() def buildlist(self, enabled): - """Run dialog buildlist + """Runs dialog buildlist """ choice = [] for item in self.data: @@ -81,7 +81,7 @@ class DialogUtil: self.exit() def exit(self): - """Exit from dialog + """Exits from dialog """ self.clear_screen() raise SystemExit() @@ -92,7 +92,7 @@ class DialogUtil: os.system("clear") def unicode_to_string(self): - """Convert unicode in string + """Converts unicode in string """ for tag in self.tags: self.ununicode.append(str(tag)) diff --git a/slpkg/repoenable.py b/slpkg/repoenable.py index 1cfcd333..ca25b8a2 100644 --- a/slpkg/repoenable.py +++ b/slpkg/repoenable.py @@ -101,7 +101,7 @@ Keys: SPACE select or deselect the highlighted repositories, self.tag_line = False def update_repos(self): - """Update repositories.conf file with enabled or disabled + """Updates repositories.conf file with enabled or disabled repositories """ with open(f"{self.meta.conf_path}" From 830c525d2be00d45222836b98b964c2f60230321 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 22:24:23 +0300 Subject: [PATCH 19/23] Fixed comments --- slpkg/repoinfo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/slpkg/repoinfo.py b/slpkg/repoinfo.py index 7069c19b..ddca8ae9 100644 --- a/slpkg/repoinfo.py +++ b/slpkg/repoinfo.py @@ -56,8 +56,7 @@ class RepoInfo(Utils): del RepoList().all_repos def view(self, repo): - """ - Views repository information + """Views repository information """ status = f"{self.red}disabled{self.endc}" self.form["Status:"] = status From 3f3b69f2d65257fefdf39721e9018a2ef8133ae4 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 22:57:07 +0300 Subject: [PATCH 20/23] BugFixed package not found --- slpkg/sbo/greps.py | 2 +- slpkg/sbo/network.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 0fea5411..9a9c8d81 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -116,4 +116,4 @@ class SBoGrep(Utils): """ if self.meta.arch == self.arch64 and arch64: return arch64 - return arch \ No newline at end of file + return arch diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py index 75ce1ddf..27ab1d4a 100644 --- a/slpkg/sbo/network.py +++ b/slpkg/sbo/network.py @@ -58,6 +58,8 @@ class SBoNetwork(BlackList, Utils): self.flag = flag self.meta = _meta_ self.msg = Msg() + self.data = SBoGrep(name="").names() + self.check_pkg_exist() self.arch = SBoArch().get() self.comp_tar = ".tar.gz" self.choice = "" @@ -71,7 +73,6 @@ class SBoNetwork(BlackList, Utils): self.build_folder = self.meta.build_path self._SOURCES = self.meta.SBo_SOURCES self.msg.reading() - self.data = SBoGrep(name="").names() self.case_insensitive() if "--checklist" in self.flag: self.with_checklist() @@ -88,6 +89,11 @@ class SBoNetwork(BlackList, Utils): if "--checklist" not in self.flag or not self.sbo_url and self.name: self.msg.done() + def check_pkg_exist(self): + if self.name not in self.data: + self.msg.pkg_not_found("\n", self.name, "can't find", "\n") + raise SystemExit(1) + def view(self): """View SlackBuild package, read or install them from slackbuilds.org @@ -326,7 +332,7 @@ class SBoNetwork(BlackList, Utils): return "" def error_uns(self): - """Check if the package is supported by an arch + """Checks if the package supported by an arch before proceeding to install """ self.FAULT = "" From 83c99d50d090809432e989f3fada14666af56673 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 23:05:16 +0300 Subject: [PATCH 21/23] BugFixed command --- slpkg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slpkg/main.py b/slpkg/main.py index 33b79eda..fef51f6c 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -770,7 +770,7 @@ class ArgParse(BlackList): ] conf = Config() if (len(self.args) == 2 and self.args[0] in options - and self.args[1] in options): + and self.args[1] in command): if self.args[1] == command[0]: conf.view() From 5c1c7fa8306e47361780f094204c50b354932016 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 23:18:07 +0300 Subject: [PATCH 22/23] Test passed --- tests/test_sbo_grep.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_sbo_grep.py b/tests/test_sbo_grep.py index b160862e..d976ba88 100644 --- a/tests/test_sbo_grep.py +++ b/tests/test_sbo_grep.py @@ -11,30 +11,30 @@ class TestSBoGreps(unittest.TestCase): """Test package source """ source = self.grep.source() - flask_source = ('https://files.pythonhosted.org/packages/4e/0b/' - 'cb02268c90e67545a0e3a37ea1ca3d45de3aca43ceb7dbf' - '1712fb5127d5d/Flask-1.1.2.tar.gz') + flask_source = ('https://files.pythonhosted.org/packages/source/f' + '/flask/Flask-2.1.2.tar.gz') self.assertEqual(source, flask_source) def test_requires(self): """Test package requires """ requires = self.grep.requires() - flask_dep = ['werkzeug', 'python3-itsdangerous', 'click'] + flask_dep = ['werkzeug', 'python3-itsdangerous', + 'click', 'python-importlib_metadata'] self.assertListEqual(requires, flask_dep) def test_version(self): """Test package version """ version = self.grep.version() - flask_ver = '1.1.2' + flask_ver = '2.1.2' self.assertEqual(version, flask_ver) def test_checksum(self): """Test package checksum """ checksum = self.grep.checksum() - flask_md5 = ['0da4145d172993cd28a6c619630cc19c'] + flask_md5 = ['93f1832e5be704ef6ff2a4124579cd85'] self.assertListEqual(checksum, flask_md5) def test_description(self): From bfbc00f7568c19cdeae5c8351c28765cabe3ad2d Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 29 May 2022 23:24:40 +0300 Subject: [PATCH 23/23] Test passed --- tests/test_split_package.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_split_package.py b/tests/test_split_package.py index aac0aa4d..04c6b402 100644 --- a/tests/test_split_package.py +++ b/tests/test_split_package.py @@ -12,13 +12,13 @@ class TestSplitting(unittest.TestCase): pkg_3 = ''.join(list(searching('autoconf-archive', path))) pkg_4 = ''.join(list(searching('bind', path))) - self.assertListEqual(['slpkg', '3.9.6', 'x86_64', '1'], + self.assertListEqual(['slpkg', '3.9.9', 'x86_64', '1'], split_package(pkg_1)) self.assertListEqual(['akonadi-mime', '21.12.1', 'x86_64', '1'], split_package(pkg_2)) self.assertListEqual(['autoconf-archive', '2021.02.19', 'noarch', '1'], split_package(pkg_3)) - self.assertListEqual(['bind', '9.16.27', 'x86_64', '1'], + self.assertListEqual(['bind', '9.16.29', 'x86_64', '1'], split_package(pkg_4))