mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-29 10:26:12 +01:00
Updated for cleans
This commit is contained in:
parent
4c0af1c7ca
commit
4b7b672380
6 changed files with 104 additions and 88 deletions
|
@ -1,30 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from slpkg.views.views import ViewMessage
|
|
||||||
from slpkg.models.models import LogsDependencies
|
|
||||||
from slpkg.models.models import session as Session
|
|
||||||
|
|
||||||
|
|
||||||
class CleanLogsDependencies:
|
|
||||||
""" Cleans the logs from packages. """
|
|
||||||
|
|
||||||
def __init__(self, flags: list):
|
|
||||||
__slots__ = 'flags'
|
|
||||||
self.flags: list = flags
|
|
||||||
self.session = Session
|
|
||||||
|
|
||||||
def clean(self) -> None:
|
|
||||||
""" Deletes the log table from the database. """
|
|
||||||
dependencies: list = self.session.query(
|
|
||||||
LogsDependencies.name, LogsDependencies.requires).all() # type: ignore
|
|
||||||
|
|
||||||
if dependencies:
|
|
||||||
view = ViewMessage(self.flags)
|
|
||||||
view.logs_packages(dependencies)
|
|
||||||
view.question()
|
|
||||||
|
|
||||||
self.session.query(LogsDependencies).delete()
|
|
||||||
self.session.commit()
|
|
||||||
else:
|
|
||||||
print('\nNothing to clean.\n')
|
|
92
slpkg/cleanings.py
Normal file
92
slpkg/cleanings.py
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from pathlib import PosixPath
|
||||||
|
|
||||||
|
from slpkg.configs import Configs
|
||||||
|
from slpkg.utilities import Utilities
|
||||||
|
from slpkg.views.views import ViewMessage
|
||||||
|
from slpkg.repositories import Repositories
|
||||||
|
from slpkg.models.models import session as Session
|
||||||
|
from slpkg.models.models import (Base, engine, LogsDependencies,
|
||||||
|
SBoTable, PonceTable, BinariesTable,
|
||||||
|
LastRepoUpdated)
|
||||||
|
|
||||||
|
|
||||||
|
class Cleanings(Configs):
|
||||||
|
""" Cleans the logs from packages. """
|
||||||
|
|
||||||
|
def __init__(self, flags: list):
|
||||||
|
__slots__ = 'flags'
|
||||||
|
super(Configs, self).__init__()
|
||||||
|
self.flags: list = flags
|
||||||
|
self.session = Session
|
||||||
|
|
||||||
|
self.view = ViewMessage(flags)
|
||||||
|
self.repos = Repositories()
|
||||||
|
self.utils = Utilities()
|
||||||
|
|
||||||
|
def tmp(self):
|
||||||
|
print('Deleting of local data:\n')
|
||||||
|
|
||||||
|
for file in self.tmp_slpkg.glob('*'):
|
||||||
|
print(f" {self.bred}>{self.endc} '{file}'")
|
||||||
|
|
||||||
|
print(f"\n{self.prog_name}: {self.blink}{self.bold}{self.bred}WARNING!{self.endc}: All the files and "
|
||||||
|
f"folders will delete!")
|
||||||
|
|
||||||
|
views = ViewMessage(self.flags)
|
||||||
|
views.question()
|
||||||
|
|
||||||
|
self.utils.remove_folder_if_exists(self.tmp_slpkg)
|
||||||
|
self.utils.create_directory(self.build_path)
|
||||||
|
print(f'{self.byellow}Successfully cleared!{self.endc}\n')
|
||||||
|
|
||||||
|
def logs_deps(self) -> None:
|
||||||
|
""" Deletes the log table from the database. """
|
||||||
|
dependencies: list = self.session.query(
|
||||||
|
LogsDependencies.name, LogsDependencies.requires).all() # type: ignore
|
||||||
|
|
||||||
|
if dependencies:
|
||||||
|
self.view.logs_packages(dependencies)
|
||||||
|
self.view.question()
|
||||||
|
|
||||||
|
self.session.query(LogsDependencies).delete()
|
||||||
|
self.session.commit()
|
||||||
|
else:
|
||||||
|
print('\nNothing to clean.\n')
|
||||||
|
|
||||||
|
def db_tables(self) -> None:
|
||||||
|
""" Drop all the tables from the database. """
|
||||||
|
print('Deleting repositories of local data and the database:\n')
|
||||||
|
for repo, values in self.repos.repositories.items():
|
||||||
|
if values[1].exists() and isinstance(values[1], PosixPath):
|
||||||
|
print(f" {self.bred}>{self.endc} '{values[1]}'")
|
||||||
|
|
||||||
|
print(f'\n{self.prog_name}: {self.blink}{self.bold}{self.bred}WARNING!{self.endc}: '
|
||||||
|
f'All the data from the database will be deleted!')
|
||||||
|
self.view.question()
|
||||||
|
|
||||||
|
tables: list = [
|
||||||
|
PonceTable.__table__,
|
||||||
|
SBoTable.__table__,
|
||||||
|
BinariesTable.__table__,
|
||||||
|
LastRepoUpdated.__table__
|
||||||
|
]
|
||||||
|
|
||||||
|
Base.metadata.drop_all(bind=engine, tables=tables)
|
||||||
|
|
||||||
|
# Deletes local downloaded data.
|
||||||
|
self.delete_repositories_data()
|
||||||
|
|
||||||
|
print(f"{self.byellow}Successfully cleared!{self.endc}\n\n"
|
||||||
|
"You need to update the package lists now:\n\n"
|
||||||
|
" $ slpkg update\n"
|
||||||
|
" $ slpkg update --bin-repo=[repo_name]\n")
|
||||||
|
|
||||||
|
def delete_repositories_data(self):
|
||||||
|
""" Deletes local folders with the repository downloaded data. """
|
||||||
|
for repo, values in self.repos.repositories.items():
|
||||||
|
if values[1].exists() and isinstance(values[1], PosixPath):
|
||||||
|
shutil.rmtree(values[1])
|
|
@ -13,12 +13,12 @@ from slpkg.tracking import Tracking
|
||||||
from slpkg.repo_info import RepoInfo
|
from slpkg.repo_info import RepoInfo
|
||||||
from slpkg.dependees import Dependees
|
from slpkg.dependees import Dependees
|
||||||
from slpkg.utilities import Utilities
|
from slpkg.utilities import Utilities
|
||||||
|
from slpkg.cleanings import Cleanings
|
||||||
from slpkg.search import SearchPackage
|
from slpkg.search import SearchPackage
|
||||||
from slpkg.views.cli_menu import Usage
|
from slpkg.views.cli_menu import Usage
|
||||||
from slpkg.dialog_box import DialogBox
|
from slpkg.dialog_box import DialogBox
|
||||||
from slpkg.views.version import Version
|
from slpkg.views.version import Version
|
||||||
from slpkg.download_only import Download
|
from slpkg.download_only import Download
|
||||||
from slpkg.views.views import ViewMessage
|
|
||||||
from slpkg.sbos.queries import SBoQueries
|
from slpkg.sbos.queries import SBoQueries
|
||||||
from slpkg.views.help_commands import Help
|
from slpkg.views.help_commands import Help
|
||||||
from slpkg.repositories import Repositories
|
from slpkg.repositories import Repositories
|
||||||
|
@ -31,7 +31,6 @@ from slpkg.logging_config import LoggingConfig
|
||||||
from slpkg.find_installed import FindInstalled
|
from slpkg.find_installed import FindInstalled
|
||||||
from slpkg.views.view_package import ViewPackage
|
from slpkg.views.view_package import ViewPackage
|
||||||
from slpkg.remove_packages import RemovePackages
|
from slpkg.remove_packages import RemovePackages
|
||||||
from slpkg.clean_logs import CleanLogsDependencies
|
|
||||||
from slpkg.update_repository import UpdateRepository
|
from slpkg.update_repository import UpdateRepository
|
||||||
|
|
||||||
|
|
||||||
|
@ -579,33 +578,22 @@ class Argparse(Configs):
|
||||||
def clean_logs(self) -> None:
|
def clean_logs(self) -> None:
|
||||||
if len(self.args) == 1:
|
if len(self.args) == 1:
|
||||||
self.check.is_empty_database(self.binary_repo)
|
self.check.is_empty_database(self.binary_repo)
|
||||||
|
clean = Cleanings(self.flags)
|
||||||
logs = CleanLogsDependencies(self.flags)
|
clean.logs_deps()
|
||||||
logs.clean()
|
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
self.usage.help_short(1)
|
self.usage.help_short(1)
|
||||||
|
|
||||||
def clean_tmp(self) -> None:
|
def clean_tmp(self) -> None:
|
||||||
if len(self.args) == 1:
|
if len(self.args) == 1:
|
||||||
|
clean = Cleanings(self.flags)
|
||||||
print(f"\n{self.prog_name}: {self.blink}{self.bold}{self.bred}WARNING!{self.endc}: All the files in the "
|
clean.tmp()
|
||||||
f"'{Path(self.tmp_path, self.prog_name)}' "
|
|
||||||
f"folder will delete!")
|
|
||||||
|
|
||||||
views = ViewMessage(self.flags)
|
|
||||||
views.question()
|
|
||||||
|
|
||||||
self.utils.remove_folder_if_exists(Path(self.tmp_path, self.prog_name))
|
|
||||||
self.utils.create_directory(self.build_path)
|
|
||||||
print(f"The folder '{Path(self.tmp_path, self.prog_name)}' was cleaned!")
|
|
||||||
|
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
self.usage.help_short(1)
|
self.usage.help_short(1)
|
||||||
|
|
||||||
def clean_data(self) -> None:
|
def clean_data(self) -> None:
|
||||||
if len(self.args) == 1:
|
if len(self.args) == 1:
|
||||||
update = UpdateRepository(self.flags, self.binary_repo)
|
clean = Cleanings(self.flags)
|
||||||
update.drop_the_tables()
|
clean.db_tables()
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
self.usage.help_short(1)
|
self.usage.help_short(1)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from multiprocessing import Process, Queue
|
from multiprocessing import Process, Queue
|
||||||
|
|
||||||
|
@ -15,9 +14,8 @@ from slpkg.install_data import InstallData
|
||||||
from slpkg.repositories import Repositories
|
from slpkg.repositories import Repositories
|
||||||
from slpkg.check_updates import CheckUpdates
|
from slpkg.check_updates import CheckUpdates
|
||||||
from slpkg.models.models import session as Session
|
from slpkg.models.models import session as Session
|
||||||
from slpkg.models.models import (Base, engine, SBoTable,
|
from slpkg.models.models import (SBoTable, PonceTable,
|
||||||
PonceTable, BinariesTable,
|
BinariesTable, LastRepoUpdated)
|
||||||
LastRepoUpdated)
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateRepository(Configs):
|
class UpdateRepository(Configs):
|
||||||
|
@ -30,7 +28,7 @@ class UpdateRepository(Configs):
|
||||||
self.repo: str = repo
|
self.repo: str = repo
|
||||||
|
|
||||||
self.session = Session
|
self.session = Session
|
||||||
self.view = ViewMessage(self.flags)
|
self.view = ViewMessage(flags)
|
||||||
self.repos = Repositories()
|
self.repos = Repositories()
|
||||||
self.progress = ProgressBar()
|
self.progress = ProgressBar()
|
||||||
self.utils = Utilities()
|
self.utils = Utilities()
|
||||||
|
@ -595,35 +593,3 @@ class UpdateRepository(Configs):
|
||||||
""" Deletes the last updated date. """
|
""" Deletes the last updated date. """
|
||||||
self.session.query(LastRepoUpdated).where(LastRepoUpdated.repo == repo).delete()
|
self.session.query(LastRepoUpdated).where(LastRepoUpdated.repo == repo).delete()
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
|
||||||
def drop_the_tables(self) -> None:
|
|
||||||
""" Drop all the tables from the database. """
|
|
||||||
print(f'\n{self.prog_name}: {self.blink}{self.bold}{self.bred}WARNING!{self.endc}: '
|
|
||||||
f'All the data from the database will be deleted!')
|
|
||||||
self.view.question()
|
|
||||||
|
|
||||||
tables: list = [
|
|
||||||
PonceTable.__table__,
|
|
||||||
SBoTable.__table__,
|
|
||||||
BinariesTable.__table__,
|
|
||||||
LastRepoUpdated.__table__
|
|
||||||
]
|
|
||||||
|
|
||||||
Base.metadata.drop_all(bind=engine, tables=tables)
|
|
||||||
|
|
||||||
# Deletes local downloaded data.
|
|
||||||
self.delete_repositories_data()
|
|
||||||
|
|
||||||
print("Successfully cleared!\n\nYou need to run 'slpkg update' now.")
|
|
||||||
|
|
||||||
def delete_repositories_data(self):
|
|
||||||
""" Deletes local folders with the repository downloaded data. """
|
|
||||||
for repo in self.repos.repositories.keys():
|
|
||||||
|
|
||||||
repo_path: Path = Path(self.repos.repositories_path, repo)
|
|
||||||
|
|
||||||
if repo_path.exists():
|
|
||||||
shutil.rmtree(repo_path)
|
|
||||||
print(f"Deleted: '{repo_path}'")
|
|
||||||
|
|
||||||
print()
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class Utilities(Configs):
|
||||||
|
|
||||||
def finished_time(self, elapsed_time: float) -> None:
|
def finished_time(self, elapsed_time: float) -> None:
|
||||||
""" Printing the elapsed time. """
|
""" Printing the elapsed time. """
|
||||||
print(f'\n{self.yellow}Finished Successfully:{self.endc}',
|
print(f'\n{self.yellow}Finished successfully:{self.endc}',
|
||||||
time.strftime(f'{self.cyan}%H:%M:%S{self.endc}',
|
time.strftime(f'{self.cyan}%H:%M:%S{self.endc}',
|
||||||
time.gmtime(elapsed_time)))
|
time.gmtime(elapsed_time)))
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class ViewMessage(Configs):
|
||||||
|
|
||||||
def view_skipping_packages(self, package: str, version: str) -> None:
|
def view_skipping_packages(self, package: str, version: str) -> None:
|
||||||
""" Print the skipping packages. """
|
""" Print the skipping packages. """
|
||||||
print(f'[{self.yellow}Skipping{self.endc}] {package}-{version} {self.red}(already installed){self.endc}')
|
print(f'{self.yellow}Skipping{self.endc}: {package}-{version} {self.red}(already installed){self.endc}')
|
||||||
|
|
||||||
def build_packages(self, slackbuilds: list, dependencies: list) -> None:
|
def build_packages(self, slackbuilds: list, dependencies: list) -> None:
|
||||||
""" View packages for build only. """
|
""" View packages for build only. """
|
||||||
|
|
Loading…
Reference in a new issue