slpkg/slpkg/upgrade.py
Dimitris Zlatanidis 93a0059757 Fixed: upgrade fails with python trackback message #145
Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
2022-10-29 19:49:35 +03:00

32 lines
969 B
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from dataclasses import dataclass
from distutils.version import LooseVersion
from slpkg.configs import Configs
from slpkg.queries import SBoQueries
@dataclass
class Upgrade:
log_packages: str = Configs.log_packages
sbo_repo_tag: str = Configs.sbo_repo_tag
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])
if name in repo_packages:
installed_ver = pkg.replace(name + '-', '').split('-')[0]
repo_ver = SBoQueries(name).version()
if LooseVersion(repo_ver) > LooseVersion(installed_ver):
yield name