Updated for sub menu

This commit is contained in:
Dimitris Zlatanidis 2023-05-22 17:18:20 +03:00
parent dab5391252
commit 4de6e2a59e
5 changed files with 121 additions and 105 deletions

View file

@ -113,7 +113,7 @@ Tracking the packages dependencies.
.P .P
.B -y, --yes .B -y, --yes
.RS .RS
Answer Yes to all questions. (to be used with: -u, update, -U, upgrade, -L, clean-logs, -b, build, Answer Yes to all questions. (to be used with: -u, update, -U, upgrade, -b, build,
-i, install, -R, remove, -d, download,) -i, install, -R, remove, -d, download,)
.RE .RE
.P .P

View file

@ -17,12 +17,11 @@ from slpkg.models.models import (Base, engine, LogsDependencies,
class Cleanings(Configs): class Cleanings(Configs):
""" Cleans the logs from packages. """ """ Cleans the logs from packages. """
def __init__(self, flags: list): def __init__(self):
super(Configs, self).__init__() super(Configs, self).__init__()
self.flags: list = flags
self.session = Session self.session = Session
self.view = ViewMessage(flags) self.view = ViewMessage()
self.repos = Repositories() self.repos = Repositories()
self.utils = Utilities() self.utils = Utilities()

View file

@ -34,7 +34,7 @@ from slpkg.remove_packages import RemovePackages
from slpkg.update_repository import UpdateRepository from slpkg.update_repository import UpdateRepository
class Argparse(Configs): class Menu(Configs):
def __init__(self, args: list): def __init__(self, args: list):
super(Configs).__init__() super(Configs).__init__()
@ -45,7 +45,6 @@ class Argparse(Configs):
self.dialogbox = DialogBox() self.dialogbox = DialogBox()
self.utils = Utilities() self.utils = Utilities()
self.usage = Usage() self.usage = Usage()
self.form_configs = FormConfigs()
self.repos = Repositories() self.repos = Repositories()
self.repository: str = self.repos.default_repository self.repository: str = self.repos.default_repository
@ -163,14 +162,8 @@ class Argparse(Configs):
self.flag_short_repository self.flag_short_repository
], ],
'configs': [], 'configs': [],
'clean-logs': [ 'clean-logs': [],
self.flag_yes, 'clean-data': [],
self.flag_short_yes
],
'clean-data': [
self.flag_yes,
self.flag_short_yes
],
'clean-tmp': [], 'clean-tmp': [],
'build': [ 'build': [
self.flag_yes, self.flag_yes,
@ -525,18 +518,6 @@ class Argparse(Configs):
return packages return packages
def help(self) -> None:
if len(self.args) == 1:
self.usage.help(0)
self.usage.help_short(1)
def version(self) -> None:
if len(self.args) == 1:
version = Version()
version.view()
raise SystemExit()
self.usage.help_short(1)
def update(self) -> None: def update(self) -> None:
if len(self.args) == 1: if len(self.args) == 1:
update = UpdateRepository(self.flags, self.repository) update = UpdateRepository(self.flags, self.repository)
@ -545,7 +526,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def upgrade(self) -> None: def upgrade(self) -> None:
command: str = Argparse.upgrade.__name__ command: str = Menu.upgrade.__name__
if len(self.args) == 1: if len(self.args) == 1:
self.load_database() self.load_database()
@ -587,35 +568,8 @@ class Argparse(Configs):
raise SystemExit() raise SystemExit()
self.usage.help_short(1) self.usage.help_short(1)
def edit_configs(self) -> None:
if len(self.args) == 1:
self.form_configs.edit()
raise SystemExit()
self.usage.help_short(1)
def clean_logs(self) -> None:
if len(self.args) == 1:
clean = Cleanings(self.flags)
clean.logs_dependencies()
raise SystemExit()
self.usage.help_short(1)
def clean_tmp(self) -> None:
if len(self.args) == 1:
clean = Cleanings(self.flags)
clean.tmp()
raise SystemExit()
self.usage.help_short(1)
def clean_data(self) -> None:
if len(self.args) == 1:
clean = Cleanings(self.flags)
clean.db_tables()
raise SystemExit()
self.usage.help_short(1)
def build(self) -> None: def build(self) -> None:
command: str = Argparse.build.__name__ command: str = Menu.build.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -643,7 +597,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def install(self) -> None: def install(self) -> None:
command: str = Argparse.install.__name__ command: str = Menu.install.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -669,7 +623,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def download(self) -> None: def download(self) -> None:
command: str = Argparse.download.__name__ command: str = Menu.download.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -689,7 +643,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def remove(self) -> None: def remove(self) -> None:
command: str = Argparse.remove.__name__ command: str = Menu.remove.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
packages: list = self.is_file_list_packages() packages: list = self.is_file_list_packages()
@ -705,7 +659,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def find(self) -> None: def find(self) -> None:
command: str = Argparse.find.__name__ command: str = Menu.find.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -724,7 +678,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def view(self) -> None: def view(self) -> None:
command: str = Argparse.view.__name__ command: str = Menu.view.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -749,7 +703,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def search(self) -> None: def search(self) -> None:
command: str = Argparse.search.__name__ command: str = Menu.search.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -768,7 +722,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def dependees(self) -> None: def dependees(self) -> None:
command: str = Argparse.dependees.__name__ command: str = Menu.dependees.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -789,7 +743,7 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
def tracking(self) -> None: def tracking(self) -> None:
command: str = Argparse.tracking.__name__ command: str = Menu.tracking.__name__
if len(self.args) >= 2: if len(self.args) >= 2:
self.load_database() self.load_database()
@ -824,53 +778,110 @@ class Argparse(Configs):
self.usage.help_short(1) self.usage.help_short(1)
class SubMenu:
""" Sub menu that separate from the main menu because of
have no options to manage here. """
def __init__(self, args: list):
self.args: list = args
self.usage = Usage()
self.form_configs = FormConfigs()
self.clean = Cleanings()
def help(self) -> None:
if len(self.args) == 1:
self.usage.help(0)
self.usage.help_short(1)
def version(self) -> None:
if len(self.args) == 1:
version = Version()
version.view()
raise SystemExit()
self.usage.help_short(1)
def edit_configs(self) -> None:
if len(self.args) == 1:
self.form_configs.edit()
raise SystemExit()
self.usage.help_short(1)
def clean_logs(self) -> None:
if len(self.args) == 1:
self.clean.logs_dependencies()
raise SystemExit()
self.usage.help_short(1)
def clean_tmp(self) -> None:
if len(self.args) == 1:
self.clean.tmp()
raise SystemExit()
self.usage.help_short(1)
def clean_data(self) -> None:
if len(self.args) == 1:
self.clean.db_tables()
raise SystemExit()
self.usage.help_short(1)
def main() -> None: def main() -> None:
args: list = sys.argv args: list = sys.argv
args.pop(0) args.pop(0)
usage = Usage() usage = Usage()
argparse = Argparse(args)
sub_menu = SubMenu(args)
arguments_no_options: dict[str] = {
'-h': sub_menu.help,
'--help': sub_menu.help,
'-v': sub_menu.version,
'--version': sub_menu.version,
'configs': sub_menu.edit_configs,
'-g': sub_menu.edit_configs,
'clean-logs': sub_menu.clean_logs,
'-L': sub_menu.clean_logs,
'clean-data': sub_menu.clean_data,
'-T': sub_menu.clean_data,
'clean-tmp': sub_menu.clean_tmp,
'-D': sub_menu.clean_tmp
}
try:
arguments_no_options[args[0]]()
except (KeyError, IndexError):
pass
except KeyboardInterrupt:
raise SystemExit(1)
menu = Menu(args)
arguments: dict[str] = { arguments: dict[str] = {
'-h': argparse.help, 'help': menu.help_for_commands,
'--help': argparse.help, 'update': menu.update,
'-v': argparse.version, '-u': menu.update,
'--version': argparse.version, 'upgrade': menu.upgrade,
'help': argparse.help_for_commands, '-U': menu.upgrade,
'update': argparse.update, 'check-updates': menu.check_updates,
'-u': argparse.update, '-c': menu.check_updates,
'upgrade': argparse.upgrade, 'repo-info': menu.repo_info,
'-U': argparse.upgrade, '-I': menu.repo_info,
'check-updates': argparse.check_updates, 'build': menu.build,
'-c': argparse.check_updates, '-b': menu.build,
'repo-info': argparse.repo_info, 'install': menu.install,
'-I': argparse.repo_info, '-i': menu.install,
'configs': argparse.edit_configs, 'download': menu.download,
'-g': argparse.edit_configs, '-d': menu.download,
'clean-logs': argparse.clean_logs, 'remove': menu.remove,
'-L': argparse.clean_logs, '-R': menu.remove,
'clean-data': argparse.clean_data, 'view': menu.view,
'-T': argparse.clean_data, '-w': menu.view,
'clean-tmp': argparse.clean_tmp, 'find': menu.find,
'-D': argparse.clean_tmp, '-f': menu.find,
'build': argparse.build, 'search': menu.search,
'-b': argparse.build, '-s': menu.search,
'install': argparse.install, 'dependees': menu.dependees,
'-i': argparse.install, '-e': menu.dependees,
'download': argparse.download, 'tracking': menu.tracking,
'-d': argparse.download, '-t': menu.tracking
'remove': argparse.remove,
'-R': argparse.remove,
'view': argparse.view,
'-w': argparse.view,
'find': argparse.find,
'-f': argparse.find,
'search': argparse.search,
'-s': argparse.search,
'dependees': argparse.dependees,
'-e': argparse.dependees,
'tracking': argparse.tracking,
'-t': argparse.tracking
} }
try: try:

View file

@ -15,6 +15,10 @@ class Help(Configs):
self.flags.reverse() # Put first the short options. self.flags.reverse() # Put first the short options.
help_commands: dict = { help_commands: dict = {
'-h': "Show this message and exit.",
'--help': "Show this message and exit.",
'-v': "Print version and exit.",
'--version': "Print version and exit.",
'update': "Updates the package list and the database.", 'update': "Updates the package list and the database.",
'upgrade': "Upgrade all the installed packages if the newer version exists in the repository.", 'upgrade': "Upgrade all the installed packages if the newer version exists in the repository.",
'check-updates': "Check if there is any news on the repositories ChangeLog.txt file.", 'check-updates': "Check if there is any news on the repositories ChangeLog.txt file.",

View file

@ -14,8 +14,10 @@ from slpkg.views.asciibox import AsciiBox
class ViewMessage(Configs): class ViewMessage(Configs):
def __init__(self, flags: list, repository=None, data=None): def __init__(self, flags=None, repository=None, data=None):
super(Configs, self).__init__() super(Configs, self).__init__()
if flags is None:
flags: list = []
self.flags: list = flags self.flags: list = flags
self.repository = repository self.repository = repository
self.data: dict = data self.data: dict = data