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