diff --git a/ChangeLog.txt b/ChangeLog.txt index a0edf413..311902d8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,11 @@ +4.2.3 - 28/10/2022 +Updated: +- Creating all necessary paths from the config file +- Logs cleaning view dependencies +Added: +- Check if database file exists +- Check if the package exists in the database before upgrade + 4.2.2 - 20/10/2022 Updated: - Removed version for skip installed option diff --git a/README.rst b/README.rst index 82f0a21c..f5233117 100644 --- a/README.rst +++ b/README.rst @@ -30,8 +30,8 @@ Install from the official third-party `SBo repository /dev/null || true # Install configuration files and creating lib directory -mkdir -p $PKG/etc/$PRGNAM $PKG/var/lib/$PRGNAM/database $PKG/var/lib/$PRGNAM/repository +mkdir -p $PKG/etc/$PRGNAM install -D -m0644 configs/slpkg.yml $PKG/etc/slpkg/slpkg.yml.new install -D -m0645 configs/blacklist.yml $PKG/etc/slpkg/blacklist.yml.new diff --git a/slpkg/checks.py b/slpkg/checks.py index 4a701292..f57e9413 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -14,10 +14,11 @@ class Check: ''' Some checks before proceed. ''' log_packages: str = Configs.log_packages sbo_repo_tag: str = Configs.sbo_repo_tag + db_path: str = Configs.db_path + database_name: str = Configs.database def exists(self, slackbuilds: list): ''' Checking if the slackbuild exists in the repository. ''' - self.database() packages = [] for sbo in slackbuilds: @@ -59,6 +60,7 @@ class Check: def database(self): ''' Checking for empty table ''' - if not SBoQueries('').names(): + db = f'{self.db_path}/{self.database_name}' + if not SBoQueries('').names() or not os.path.isfile(db): raise SystemExit('\nYou need to update the package lists first.\n' 'Please run slpkg update.\n') diff --git a/slpkg/configs.py b/slpkg/configs.py index d79dab7f..170bfc22 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -44,15 +44,11 @@ class Configs: removepkg: str = 'removepkg' # Cli menu colors configs - colors: str = 'on' + colors: str = 'off' # Wget options wget_options = '-c -N' - # Creating the build path - if not os.path.isdir(build_path): - os.makedirs(build_path) - ''' Overwrite with user configuration. ''' config_file: str = f'{etc_path}/{prog_name}.yml' if os.path.isfile(config_file): @@ -95,6 +91,19 @@ class Configs: except KeyError: pass + # Creating the paths if they doesn't exists + paths = [tmp_slpkg, + build_path, + download_only, + sbo_repo_path, + lib_path, + etc_path, + db_path] + + for path in paths: + if not os.path.isdir(path): + os.makedirs(path) + @classmethod def colour(cls): color = { diff --git a/slpkg/main.py b/slpkg/main.py index fc2c49a3..4ca2d99f 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -67,6 +67,8 @@ class Argparse: def upgrade(self): if len(self.args) == 1: + self.check.database() + upgrade = Upgrade() packages = list(upgrade.packages()) @@ -83,6 +85,7 @@ class Argparse: if len(self.args) >= 2 and '--reinstall' not in self.flags: packages = list(set(self.args[1:])) + self.check.database() self.check.exists(packages) self.check.unsupported(packages) @@ -95,6 +98,7 @@ class Argparse: if len(self.args) >= 2: packages = list(set(self.args[1:])) + self.check.database() self.check.exists(packages) self.check.unsupported(packages) @@ -110,6 +114,7 @@ class Argparse: if len(self.args) >= 2: packages = list(set(self.args[1:])) + self.check.database() self.check.exists(packages) download = Download(self.flags) download.packages(packages) @@ -123,6 +128,9 @@ class Argparse: if len(self.args) >= 2: packages = list(set(self.args[1:])) + + self.check.database() + packages = self.check.blacklist(packages) self.check.installed(packages) @@ -135,6 +143,9 @@ class Argparse: def view(self): if len(self.args) >= 2 and not self.flags: packages = list(set(self.args[1:])) + + self.check.database() + packages = self.check.blacklist(packages) self.check.exists(packages) @@ -147,6 +158,9 @@ class Argparse: def search(self): if len(self.args) >= 2 and not self.flags: packages = list(set(self.args[1:])) + + self.check.database() + packages = self.check.blacklist(packages) search = SearchPackage() @@ -157,6 +171,9 @@ class Argparse: def find(self): if len(self.args) >= 2 and not self.flags: packages = list(set(self.args[1:])) + + self.check.database() + packages = self.check.blacklist(packages) find = FindInstalled() @@ -169,6 +186,8 @@ class Argparse: usage(1) if len(self.args) == 1: + self.check.database() + logs = CleanLogsDependencies(self.flags) logs.clean() raise SystemExit() diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 9045bda7..a9aa11be 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -16,11 +16,18 @@ class Upgrade: def packages(self): ''' Compares version of packages and returns the maximum. ''' + print("Do not forget to run 'slpkg update' before.") + + repo_packages = SBoQueries('').names() + for pkg in os.listdir(self.log_packages): if pkg.endswith(self.sbo_repo_tag): - name = '-'.join(pkg.split('-')[:-3]) - installed_ver = pkg.replace(name + '-', '').split('-')[0] - repo_ver = SBoQueries(name).version() + inst_pkg_name = '-'.join(pkg.split('-')[:-3]) - if LooseVersion(repo_ver) > LooseVersion(installed_ver): - yield name + if inst_pkg_name in repo_packages: + installed_ver = pkg.replace( + inst_pkg_name + '-', '').split('-')[0] + repo_ver = SBoQueries(inst_pkg_name).version() + + if LooseVersion(repo_ver) > LooseVersion(installed_ver): + yield inst_pkg_name diff --git a/slpkg/version.py b/slpkg/version.py index 6ad1682f..8af1e7c9 100644 --- a/slpkg/version.py +++ b/slpkg/version.py @@ -10,7 +10,7 @@ from slpkg.configs import Configs @dataclass class Version: prog_name: str = Configs.prog_name - version_info: tuple = (4, 2, 2) + version_info: tuple = (4, 2, 3) version: str = '{0}.{1}.{2}'.format(*version_info) license: str = 'MIT License' author: str = 'dslackw' diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 6b0f7f39..e0ef8079 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -116,6 +116,10 @@ class ViewMessage: self.arch = 'noarch' if installed: + + if '--reinstall' not in self.flags: + install = 'installed' + print(f'[{set_color} {install} {color["ENDC"]}] -> ' f'{sbo}-{version} {set_color}' f'({installed.split(self.arch)[0][:-1].split("-")[-1]})' @@ -166,8 +170,8 @@ class ViewMessage: for dep in dependencies: print(f'{color["CYAN"]}{dep[0]}{color["ENDC"]}') - print('Dependencies:') - print(f'{color["CYAN"]} {dep[1]}{color["ENDC"]}\n') + print(' |') + print(f' +->{color["CYAN"]} {dep[1]}{color["ENDC"]}\n') print('Note: After cleaning you should remove them one by one.') def question(self):