mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-25 09:58:41 +01:00
Updated for sub menu
This commit is contained in:
parent
dab5391252
commit
4de6e2a59e
5 changed files with 121 additions and 105 deletions
|
@ -113,7 +113,7 @@ Tracking the packages dependencies.
|
|||
.P
|
||||
.B -y, --yes
|
||||
.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,)
|
||||
.RE
|
||||
.P
|
||||
|
|
|
@ -17,12 +17,11 @@ from slpkg.models.models import (Base, engine, LogsDependencies,
|
|||
class Cleanings(Configs):
|
||||
""" Cleans the logs from packages. """
|
||||
|
||||
def __init__(self, flags: list):
|
||||
def __init__(self):
|
||||
super(Configs, self).__init__()
|
||||
self.flags: list = flags
|
||||
self.session = Session
|
||||
|
||||
self.view = ViewMessage(flags)
|
||||
self.view = ViewMessage()
|
||||
self.repos = Repositories()
|
||||
self.utils = Utilities()
|
||||
|
||||
|
|
211
slpkg/main.py
211
slpkg/main.py
|
@ -34,7 +34,7 @@ from slpkg.remove_packages import RemovePackages
|
|||
from slpkg.update_repository import UpdateRepository
|
||||
|
||||
|
||||
class Argparse(Configs):
|
||||
class Menu(Configs):
|
||||
|
||||
def __init__(self, args: list):
|
||||
super(Configs).__init__()
|
||||
|
@ -45,7 +45,6 @@ class Argparse(Configs):
|
|||
self.dialogbox = DialogBox()
|
||||
self.utils = Utilities()
|
||||
self.usage = Usage()
|
||||
self.form_configs = FormConfigs()
|
||||
self.repos = Repositories()
|
||||
|
||||
self.repository: str = self.repos.default_repository
|
||||
|
@ -163,14 +162,8 @@ class Argparse(Configs):
|
|||
self.flag_short_repository
|
||||
],
|
||||
'configs': [],
|
||||
'clean-logs': [
|
||||
self.flag_yes,
|
||||
self.flag_short_yes
|
||||
],
|
||||
'clean-data': [
|
||||
self.flag_yes,
|
||||
self.flag_short_yes
|
||||
],
|
||||
'clean-logs': [],
|
||||
'clean-data': [],
|
||||
'clean-tmp': [],
|
||||
'build': [
|
||||
self.flag_yes,
|
||||
|
@ -525,18 +518,6 @@ class Argparse(Configs):
|
|||
|
||||
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:
|
||||
if len(self.args) == 1:
|
||||
update = UpdateRepository(self.flags, self.repository)
|
||||
|
@ -545,7 +526,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def upgrade(self) -> None:
|
||||
command: str = Argparse.upgrade.__name__
|
||||
command: str = Menu.upgrade.__name__
|
||||
|
||||
if len(self.args) == 1:
|
||||
self.load_database()
|
||||
|
@ -587,35 +568,8 @@ class Argparse(Configs):
|
|||
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:
|
||||
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:
|
||||
command: str = Argparse.build.__name__
|
||||
command: str = Menu.build.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -643,7 +597,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def install(self) -> None:
|
||||
command: str = Argparse.install.__name__
|
||||
command: str = Menu.install.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -669,7 +623,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def download(self) -> None:
|
||||
command: str = Argparse.download.__name__
|
||||
command: str = Menu.download.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -689,7 +643,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def remove(self) -> None:
|
||||
command: str = Argparse.remove.__name__
|
||||
command: str = Menu.remove.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
packages: list = self.is_file_list_packages()
|
||||
|
@ -705,7 +659,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def find(self) -> None:
|
||||
command: str = Argparse.find.__name__
|
||||
command: str = Menu.find.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -724,7 +678,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def view(self) -> None:
|
||||
command: str = Argparse.view.__name__
|
||||
command: str = Menu.view.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -749,7 +703,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def search(self) -> None:
|
||||
command: str = Argparse.search.__name__
|
||||
command: str = Menu.search.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -768,7 +722,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def dependees(self) -> None:
|
||||
command: str = Argparse.dependees.__name__
|
||||
command: str = Menu.dependees.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -789,7 +743,7 @@ class Argparse(Configs):
|
|||
self.usage.help_short(1)
|
||||
|
||||
def tracking(self) -> None:
|
||||
command: str = Argparse.tracking.__name__
|
||||
command: str = Menu.tracking.__name__
|
||||
|
||||
if len(self.args) >= 2:
|
||||
self.load_database()
|
||||
|
@ -824,53 +778,110 @@ class Argparse(Configs):
|
|||
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:
|
||||
args: list = sys.argv
|
||||
args.pop(0)
|
||||
|
||||
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] = {
|
||||
'-h': argparse.help,
|
||||
'--help': argparse.help,
|
||||
'-v': argparse.version,
|
||||
'--version': argparse.version,
|
||||
'help': argparse.help_for_commands,
|
||||
'update': argparse.update,
|
||||
'-u': argparse.update,
|
||||
'upgrade': argparse.upgrade,
|
||||
'-U': argparse.upgrade,
|
||||
'check-updates': argparse.check_updates,
|
||||
'-c': argparse.check_updates,
|
||||
'repo-info': argparse.repo_info,
|
||||
'-I': argparse.repo_info,
|
||||
'configs': argparse.edit_configs,
|
||||
'-g': argparse.edit_configs,
|
||||
'clean-logs': argparse.clean_logs,
|
||||
'-L': argparse.clean_logs,
|
||||
'clean-data': argparse.clean_data,
|
||||
'-T': argparse.clean_data,
|
||||
'clean-tmp': argparse.clean_tmp,
|
||||
'-D': argparse.clean_tmp,
|
||||
'build': argparse.build,
|
||||
'-b': argparse.build,
|
||||
'install': argparse.install,
|
||||
'-i': argparse.install,
|
||||
'download': argparse.download,
|
||||
'-d': argparse.download,
|
||||
'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
|
||||
'help': menu.help_for_commands,
|
||||
'update': menu.update,
|
||||
'-u': menu.update,
|
||||
'upgrade': menu.upgrade,
|
||||
'-U': menu.upgrade,
|
||||
'check-updates': menu.check_updates,
|
||||
'-c': menu.check_updates,
|
||||
'repo-info': menu.repo_info,
|
||||
'-I': menu.repo_info,
|
||||
'build': menu.build,
|
||||
'-b': menu.build,
|
||||
'install': menu.install,
|
||||
'-i': menu.install,
|
||||
'download': menu.download,
|
||||
'-d': menu.download,
|
||||
'remove': menu.remove,
|
||||
'-R': menu.remove,
|
||||
'view': menu.view,
|
||||
'-w': menu.view,
|
||||
'find': menu.find,
|
||||
'-f': menu.find,
|
||||
'search': menu.search,
|
||||
'-s': menu.search,
|
||||
'dependees': menu.dependees,
|
||||
'-e': menu.dependees,
|
||||
'tracking': menu.tracking,
|
||||
'-t': menu.tracking
|
||||
}
|
||||
|
||||
try:
|
||||
|
|
|
@ -15,6 +15,10 @@ class Help(Configs):
|
|||
self.flags.reverse() # Put first the short options.
|
||||
|
||||
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.",
|
||||
'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.",
|
||||
|
|
|
@ -14,8 +14,10 @@ from slpkg.views.asciibox import AsciiBox
|
|||
|
||||
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__()
|
||||
if flags is None:
|
||||
flags: list = []
|
||||
self.flags: list = flags
|
||||
self.repository = repository
|
||||
self.data: dict = data
|
||||
|
|
Loading…
Reference in a new issue