mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Fixed view removed
This commit is contained in:
parent
8b717bfa69
commit
e0d11fe3dc
3 changed files with 65 additions and 44 deletions
|
@ -2,12 +2,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from slpkg.configs import Configs
|
||||
|
||||
from dataclasses import dataclass
|
||||
from slpkg.blacklist import Blacklist
|
||||
from slpkg.views.views import ViewMessage
|
||||
from slpkg.models.models import LogsDependencies
|
||||
from slpkg.models.models import session as Session
|
||||
|
@ -19,31 +17,19 @@ class RemovePackages:
|
|||
packages: str
|
||||
flags: list
|
||||
session: str = Session
|
||||
black: list = Blacklist()
|
||||
log_packages: str = Configs.log_packages
|
||||
repo_tag: str = Configs.repo_tag
|
||||
removepkg: str = Configs.removepkg
|
||||
color: str = Configs.colour
|
||||
|
||||
def remove(self):
|
||||
''' Remove package with dependencies. '''
|
||||
self.installed_packages = []
|
||||
view = ViewMessage()
|
||||
view.remove_packages()
|
||||
self.dependencies = []
|
||||
|
||||
for pkg in self.packages:
|
||||
self.view_installed_packages(pkg)
|
||||
view = ViewMessage(self.flags)
|
||||
|
||||
self.dependencies = self.session.query(
|
||||
LogsDependencies.requires).filter(
|
||||
LogsDependencies.name == pkg).first()
|
||||
self.installed_packages, self.dependencies = view.remove_packages(
|
||||
self.packages)
|
||||
|
||||
if self.dependencies and '--resolve-off' not in self.flags:
|
||||
print('\nDependencies:')
|
||||
for dep in self.dependencies[0].split():
|
||||
self.view_installed_packages(dep)
|
||||
|
||||
view.question(self.flags)
|
||||
view.question()
|
||||
|
||||
self.remove_packages()
|
||||
self.delete_main_logs()
|
||||
|
@ -70,15 +56,3 @@ class RemovePackages:
|
|||
self.session.query(LogsDependencies).filter(
|
||||
LogsDependencies.name == pkg).delete()
|
||||
self.session.commit()
|
||||
|
||||
def view_installed_packages(self, name: str):
|
||||
''' View and creates list with packages for remove. '''
|
||||
installed = os.listdir(self.log_packages)
|
||||
color = self.color()
|
||||
|
||||
for package in installed:
|
||||
black = package.split('-')[0]
|
||||
if (package.startswith(name) and self.repo_tag in package and
|
||||
black not in self.black.get()):
|
||||
self.installed_packages.append(package)
|
||||
print(f'[{color["RED"]} delete {color["ENDC"]}] -> {package}')
|
||||
|
|
|
@ -54,7 +54,7 @@ class Slackbuilds:
|
|||
|
||||
def view_before_build(self):
|
||||
''' View slackbuilds before proceed. '''
|
||||
view = ViewMessage()
|
||||
view = ViewMessage(self.flags)
|
||||
|
||||
if self.install:
|
||||
view.install_packages(self.slackbuilds, self.dependencies)
|
||||
|
@ -63,7 +63,7 @@ class Slackbuilds:
|
|||
|
||||
del self.dependencies # no more needed
|
||||
|
||||
view.question(self.flags)
|
||||
view.question()
|
||||
|
||||
def creating_dictionary(self):
|
||||
''' Dictionary with the main slackbuilds and dependencies. '''
|
||||
|
|
|
@ -1,16 +1,26 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
from slpkg.queries import SBoQueries
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.utilities import Utilities
|
||||
from slpkg.models.models import LogsDependencies
|
||||
from slpkg.models.models import session as Session
|
||||
from slpkg.blacklist import Blacklist
|
||||
|
||||
|
||||
@dataclass
|
||||
class ViewMessage:
|
||||
flags: list
|
||||
colors: str = Configs.colour
|
||||
log_packages: str = Configs.log_packages
|
||||
repo_tag: str = Configs.repo_tag
|
||||
session: str = Session
|
||||
utils: str = Utilities()
|
||||
black: list = Blacklist()
|
||||
|
||||
def build_packages(self, slackbuilds: list, dependencies: list):
|
||||
print('The following packages will be build:\n')
|
||||
|
@ -20,12 +30,12 @@ class ViewMessage:
|
|||
self._view_build(sbo, version)
|
||||
|
||||
if dependencies:
|
||||
print('Dependencies:')
|
||||
print('\nDependencies:')
|
||||
for sbo in dependencies:
|
||||
version = SBoQueries(sbo).version()
|
||||
self._view_build(sbo, version)
|
||||
|
||||
self._view_total(slackbuilds, dependencies, method='build')
|
||||
self._view_total(slackbuilds, dependencies, option='build')
|
||||
|
||||
def install_packages(self, slackbuilds: list, dependencies: list):
|
||||
print('The following packages will be installed or upgraded:\n')
|
||||
|
@ -35,12 +45,35 @@ class ViewMessage:
|
|||
self._view_install(sbo, version)
|
||||
|
||||
if dependencies:
|
||||
print('Dependencies:')
|
||||
print('\nDependencies:')
|
||||
for sbo in dependencies:
|
||||
version = SBoQueries(sbo).version()
|
||||
self._view_install(sbo, version)
|
||||
|
||||
self._view_total(slackbuilds, dependencies, method='install')
|
||||
self._view_total(slackbuilds, dependencies, option='install')
|
||||
|
||||
def remove_packages(self, packages: list):
|
||||
print('The following packages will be removed:\n')
|
||||
self.installed_packages = []
|
||||
slackbuilds, dependencies, = [], []
|
||||
|
||||
for pkg in packages:
|
||||
self._view_installed_packages(pkg)
|
||||
slackbuilds.append(pkg)
|
||||
|
||||
self.dependencies = self.session.query(
|
||||
LogsDependencies.requires).filter(
|
||||
LogsDependencies.name == pkg).first()
|
||||
|
||||
if self.dependencies and '--resolve-off' not in self.flags:
|
||||
print('\nDependencies:')
|
||||
for dep in self.dependencies[0].split():
|
||||
self._view_installed_packages(dep)
|
||||
dependencies.append(dep)
|
||||
|
||||
self._view_total(slackbuilds, dependencies, option='remove')
|
||||
|
||||
return self.installed_packages, self.dependencies
|
||||
|
||||
def _view_build(self, sbo: str, version: str):
|
||||
color = self.colors()
|
||||
|
@ -62,7 +95,19 @@ class ViewMessage:
|
|||
print(f'[{color["CYAN"]} install {color["ENDC"]}] -> '
|
||||
f'{sbo}-{version}')
|
||||
|
||||
def _view_total(self, slackbuilds: list, dependencies: list, method):
|
||||
def _view_installed_packages(self, name: str):
|
||||
''' View and creates list with packages for remove. '''
|
||||
installed = os.listdir(self.log_packages)
|
||||
color = self.colors()
|
||||
|
||||
for package in installed:
|
||||
black = package.split('-')[0]
|
||||
if (package.startswith(name) and self.repo_tag in package and
|
||||
black not in self.black.get()):
|
||||
self.installed_packages.append(package)
|
||||
print(f'[{color["RED"]} delete {color["ENDC"]}] -> {package}')
|
||||
|
||||
def _view_total(self, slackbuilds: list, dependencies: list, option: str):
|
||||
color = self.colors()
|
||||
|
||||
slackbuilds.extend(dependencies)
|
||||
|
@ -75,15 +120,17 @@ class ViewMessage:
|
|||
else:
|
||||
installed += 1
|
||||
|
||||
if method == 'install':
|
||||
if option == 'install':
|
||||
print(f'\n{color["GREY"]}Total {installed} will be installed and '
|
||||
f'{upgraded} will be upgraded.{color["ENDC"]}')
|
||||
else:
|
||||
|
||||
elif option == 'build':
|
||||
print(f'\n{color["GREY"]}Total {installed + upgraded} packages '
|
||||
f'will be build.{color["ENDC"]}')
|
||||
|
||||
def remove_packages(self):
|
||||
print('The following packages will be removed:\n')
|
||||
elif option == 'remove':
|
||||
print(f'\n{color["GREY"]}Total {installed + upgraded} packages '
|
||||
f'will be removed.{color["ENDC"]}')
|
||||
|
||||
def logs_packages(self, dependencies):
|
||||
print('The following logs will be removed:\n')
|
||||
|
@ -95,8 +142,8 @@ class ViewMessage:
|
|||
print(f'{color["CYAN"]} {dep[1]}{color["ENDC"]}\n')
|
||||
print('Note: After cleaning you should remove them one by one.')
|
||||
|
||||
def question(self, flags: list):
|
||||
if '--yes' not in flags:
|
||||
def question(self):
|
||||
if '--yes' not in self.flags:
|
||||
answer = input('\nDo you want to continue [y/N]: ')
|
||||
print()
|
||||
if answer not in ['Y', 'y']:
|
||||
|
|
Loading…
Reference in a new issue