From e38314906d5661afeb6eca80dc2dd6ffef72b534 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sat, 24 Dec 2022 21:07:09 +0200 Subject: [PATCH] Added pythondialog for upgrade --- README.rst | 1 + requirements.txt | 1 + setup.cfg | 1 + slpkg/main.py | 2 +- slpkg/upgrade.py | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 21ce44ce..e611ab8c 100644 --- a/README.rst +++ b/README.rst @@ -21,6 +21,7 @@ Requirements .. code-block:: bash SQLAlchemy >= 1.4.36 + pythondialog >= 3.5.3 toml >= 0.10.2 Install diff --git a/requirements.txt b/requirements.txt index 4c37dd2f..f9280475 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ SQLAlchemy>=1.4.36 +pythondialog>=3.5.3 toml>=0.10.2 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 8adc8964..c1fd9a5f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,7 @@ packages = python_requires = >=3.7 install_requires = SQLAlchemy >= 1.4.36 + pythondialog >= 3.5.3 toml >= 0.10.2 include_package_data = True diff --git a/slpkg/main.py b/slpkg/main.py index 62bf9f46..6e9c135b 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -82,7 +82,7 @@ class Argparse: self.check.database() upgrade = Upgrade() - packages = list(upgrade.packages()) + packages = upgrade.packages() if not packages: print('\nEverything is up-to-date.\n') diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index d2681caa..dbd26960 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -2,22 +2,31 @@ # -*- coding: utf-8 -*- import os +import locale +from dialog import Dialog from distutils.version import LooseVersion from slpkg.configs import Configs +from slpkg.views.version import Version from slpkg.queries import SBoQueries from slpkg.utilities import Utilities from slpkg.blacklist import Blacklist +# This is almost always a good thing to do at the beginning of your programs. +locale.setlocale(locale.LC_ALL, '') + + class Upgrade: """ Upgrade the installed packages. """ def __init__(self): self.configs = Configs self.utils = Utilities() + self.d = Dialog(dialog="dialog") + self.d.set_background_title(f'{self.configs.prog_name} {Version().version}') - def packages(self): + def search(self): """ Compares version of packages and returns the maximum. """ repo_packages = SBoQueries('').sbos() black = Blacklist().get() @@ -34,3 +43,26 @@ class Upgrade: if LooseVersion(repo_ver) > LooseVersion(installed_ver): yield inst_pkg_name + + def packages(self): + """ Choose packages for upgrade. """ + choices = [] + packages = self.search() + + for package in packages: + pkg = self.utils.is_installed(package) + version = self.utils.split_installed_pkg(pkg)[1] + choices += [(package, version, False)] + + code, tags = self.d.checklist(f'There are {len(choices)} packages for upgrade:', + title='Choose packages you want to upgrade', + height=10, width=70, list_height=0, choices=choices) + + if code == self.d.OK: + os.system('clear') + if not tags: + raise SystemExit() + return tags + + os.system('clear') + raise SystemExit()