From 7caa495f78da5d96bd85c9a0359ad781fb9e892d Mon Sep 17 00:00:00 2001 From: AbdelwahabAdam Date: Mon, 28 Nov 2022 23:37:43 -0800 Subject: [PATCH] fix: jans-cli DocString and removing unused imports (ref: #2572) --- .../cli_tui/plugins/010_oxauth/main.py | 4 -- .../plugins/060_scripts/edit_script_dialog.py | 66 +++++++++++-------- .../cli_tui/plugins/060_scripts/main.py | 52 ++++++--------- .../plugins/070_users/edit_user_dialog.py | 57 ++++++++-------- .../cli_tui/plugins/070_users/main.py | 33 ++++------ jans-cli-tui/cli_tui/plugins/999_jans/main.py | 21 +----- 6 files changed, 102 insertions(+), 131 deletions(-) diff --git a/jans-cli-tui/cli_tui/plugins/010_oxauth/main.py b/jans-cli-tui/cli_tui/plugins/010_oxauth/main.py index 75d05c4ea6d..59f89370afb 100755 --- a/jans-cli-tui/cli_tui/plugins/010_oxauth/main.py +++ b/jans-cli-tui/cli_tui/plugins/010_oxauth/main.py @@ -5,8 +5,6 @@ from typing import Any, Optional from prompt_toolkit.application.current import get_app from prompt_toolkit.eventloop import get_event_loop -from prompt_toolkit.key_binding import KeyBindings -from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous from prompt_toolkit.layout.containers import ( HSplit, VSplit, @@ -24,7 +22,6 @@ ) from prompt_toolkit.lexers import PygmentsLexer, DynamicLexer from utils.static import DialogResult -from cli import config_cli from utils.utils import DialogUtils from wui_components.jans_nav_bar import JansNavBar from wui_components.jans_vetrical_nav import JansVerticalNav @@ -36,7 +33,6 @@ from prompt_toolkit.buffer import Buffer from prompt_toolkit.application import Application from utils.multi_lang import _ -import cli_style class Plugin(DialogUtils): """This is a general class for plugins diff --git a/jans-cli-tui/cli_tui/plugins/060_scripts/edit_script_dialog.py b/jans-cli-tui/cli_tui/plugins/060_scripts/edit_script_dialog.py index f16c7c83f1f..04ed9f9458f 100755 --- a/jans-cli-tui/cli_tui/plugins/060_scripts/edit_script_dialog.py +++ b/jans-cli-tui/cli_tui/plugins/060_scripts/edit_script_dialog.py @@ -1,17 +1,11 @@ -import re - -from asyncio import ensure_future from functools import partial - from prompt_toolkit.layout.dimension import D from prompt_toolkit.layout.containers import ( HSplit, VSplit, - DynamicContainer, Window ) from prompt_toolkit.widgets import ( - Box, Button, Label, TextArea, @@ -19,38 +13,22 @@ Button, Dialog, ) -from prompt_toolkit.application.current import get_app - from prompt_toolkit.lexers import PygmentsLexer from pygments.lexers.python import PythonLexer from pygments.lexers.jvm import JavaLexer - -from cli import config_cli from utils.static import DialogResult from wui_components.jans_dialog_with_nav import JansDialogWithNav -from wui_components.jans_side_nav_bar import JansSideNavBar from wui_components.jans_cli_dialog import JansGDialog from wui_components.jans_drop_down import DropDownWidget -from wui_components.jans_data_picker import DateSelectWidget from utils.utils import DialogUtils from wui_components.jans_vetrical_nav import JansVerticalNav from wui_components.jans_spinner import Spinner -from prompt_toolkit.layout.containers import ( - AnyContainer, -) from prompt_toolkit.formatted_text import AnyFormattedText -from prompt_toolkit.layout.dimension import AnyDimension -from typing import Optional, Sequence, Union -from typing import TypeVar, Callable - +from typing import Optional, Sequence +from typing import Callable from typing import Any, Optional - - -from view_uma_dialog import ViewUMADialog - from utils.multi_lang import _ - class EditScriptDialog(JansGDialog, DialogUtils): """This Script editing dialog """ @@ -64,8 +42,9 @@ def __init__( )-> Dialog: """init for `EditScriptDialog`, inherits from two diffrent classes `JansGDialog` and `DialogUtils` + JansGDialog (dialog): This is the main dialog Class Widget for all Jans-cli-tui dialogs except custom dialogs like dialogs with navbar DialogUtils (methods): Responsable for all `make data from dialog` and `check required fields` in the form for any Edit or Add New - + Args: parent (widget): This is the parent widget for the dialog, to access `Pageup` and `Pagedown` title (str): The Main dialog title @@ -83,6 +62,8 @@ def __init__( self.script = self.data.get('script','') def save(self) -> None: + """method to invoked when saving the dialog (Save button is pressed) + """ data = {} @@ -131,6 +112,9 @@ def save(self) -> None: self.future.set_result(DialogResult.ACCEPT) def cancel(self) -> None: + """method to invoked when canceling changes in the dialog (Cancel button is pressed) + """ + self.future.set_result(DialogResult.CANCEL) def create_window(self) -> None: @@ -317,27 +301,35 @@ def create_window(self) -> None: width=self.myparent.dialog_width, ) - def get_help(self, **kwargs: Any): + """This method get focused field Description to display on statusbar + """ # schema = self.app.cli_object.get_schema_from_reference('#/components/schemas/{}'.format(str(kwargs['scheme']))) if kwargs['scheme'] == 'Properties': self.myparent.status_bar_text= kwargs['data'][0] - - - def script_lang_changed( self, value: str, ) -> None: + """Change the script lang + + Args: + value (str): lang to change to (python, java) + """ self.cur_lang = value def set_location_widget_state( self, state: bool, ) -> None: + """This method check the state of the location to save script + + Args: + state (bool): state is changed or not + """ self.location_widget.me.read_only = not state self.location_widget.me.focusable = state if not state: @@ -347,10 +339,17 @@ def script_location_changed( self, redio_button: RadioList, ) -> None: + """Location to save Script + + Args: + redio_button (RadioList): Where to save the scripts (Database, Filesystem) + """ state = redio_button.current_value == 'file' self.set_location_widget_state(state) def edit_property(self, **kwargs: Any) -> None: + """This method for editing the properties + """ if kwargs['jans_name'] == 'moduleProperties': key, val = kwargs.get('data', ('','')) @@ -389,12 +388,16 @@ def add_property(dialog: Dialog) -> None: self.myparent.show_jans_dialog(dialog) def delete_config_property(self, **kwargs: Any) -> None: + """This method for deleting the coniguration of properties + """ if kwargs['jans_name'] == 'configurationProperties': self.config_properties_container.remove_item(kwargs['selected']) else: self.module_properties_container.remove_item(kwargs['selected']) def edit_script_dialog(self) -> None: + """This method shows the script itself and let the user view or edit it + """ text_editor = TextArea( text=self.script, @@ -415,5 +418,10 @@ def modify_script(arg) -> None: self.myparent.show_jans_dialog(dialog) def __pt_container__(self)-> Dialog: + """The container for the dialog itself + + Returns: + Dialog: The Edit Script Dialog + """ return self.dialog diff --git a/jans-cli-tui/cli_tui/plugins/060_scripts/main.py b/jans-cli-tui/cli_tui/plugins/060_scripts/main.py index dcc44894f33..a3c8e19d789 100755 --- a/jans-cli-tui/cli_tui/plugins/060_scripts/main.py +++ b/jans-cli-tui/cli_tui/plugins/060_scripts/main.py @@ -1,13 +1,6 @@ -import os -import sys - from functools import partial import asyncio - -import prompt_toolkit from prompt_toolkit.application.current import get_app -from prompt_toolkit.key_binding import KeyBindings -from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous from prompt_toolkit.layout.containers import ( HSplit, VSplit, @@ -17,32 +10,16 @@ ) from prompt_toolkit.layout.dimension import D from prompt_toolkit.widgets import ( - Box, Button, - Label, - Frame, Dialog ) from typing import Any, Optional from prompt_toolkit.buffer import Buffer - from utils.static import DialogResult - -from cli import config_cli -from wui_components.jans_nav_bar import JansNavBar -from wui_components.jans_side_nav_bar import JansSideNavBar from wui_components.jans_vetrical_nav import JansVerticalNav -from wui_components.jans_dialog import JansDialog -from wui_components.jans_dialog_with_nav import JansDialogWithNav -from wui_components.jans_drop_down import DropDownWidget -from wui_components.jans_data_picker import DateSelectWidget - from edit_script_dialog import EditScriptDialog from prompt_toolkit.application import Application - from utils.multi_lang import _ -import cli_style - class Plugin(): """This is a general class for plugins @@ -51,10 +28,10 @@ def __init__( self, app: Application ) -> None: - """init for Plugin class "oxauth" + """init for Plugin class "scripts" Args: - app (_type_): _description_ + app (Generic): The main Application class """ self.app = app self.pid = 'scripts' @@ -87,12 +64,17 @@ def scripts_prepare_containers(self) -> None: DynamicContainer(lambda: self.scripts_list_container) ],style='class:outh_containers_scopes') - def get_scripts( self, start_index: Optional[int]= 1, pattern: Optional[str]= '', ) -> None: + """Get the current Scripts from server + + Args: + start_index (Optional[int], optional): This is flag for the Scripts pages. Defaults to 0. + pattern (Optional[str], optional):endpoint arguments for the Scripts. Defaults to ''. + """ endpoint_args ='limit:{},startIndex:{}'.format(self.app.entries_per_page, start_index) if pattern: @@ -116,7 +98,6 @@ async def coroutine(): asyncio.ensure_future(coroutine()) - def scripts_update_list( self, pattern: Optional[str]= '', @@ -124,7 +105,7 @@ def scripts_update_list( """Updates Scripts data from server Args: - start_index (int, optional): add Button("Prev") to the layout. Defaults to 0. + pattern (Optional[str], optional):endpoint arguments for the Scripts. Defaults to ''. """ data =[] @@ -175,17 +156,20 @@ def scripts_update_list( self.app.layout.focus(self.scripts_listbox) get_app().invalidate() - def get_help(self, **kwargs: Any): + """This method get focused field Description to display on statusbar + """ # schema = self.app.cli_object.get_schema_from_reference('#/components/schemas/{}'.format(str(kwargs['scheme']))) - if kwargs['scheme'] == 'Scripts': self.app.status_bar_text= kwargs['data'][2] - - def search_scripts(self, tbuffer:Buffer) -> None: + """This method handel the search for scripts + + Args: + tbuffer (Buffer): Buffer returned from the TextArea widget > GetTitleText + """ if not len(tbuffer.text) > 2: self.app.show_message(_("Error!"), _("Search string should be at least three characters"), tobefocused=self.scripts_main_area) return @@ -212,7 +196,7 @@ def save_script(self, dialog: Dialog) -> None: dialog (_type_): the main dialog to save data in Returns: - _type_: bool value to check the status code response + bool : value to check the status code response """ async def coroutine(): @@ -231,6 +215,8 @@ async def coroutine(): asyncio.ensure_future(coroutine()) def delete_script(self, **kwargs: Any) -> None: + """This method for the deletion of the Scripts + """ def do_delete_script(): diff --git a/jans-cli-tui/cli_tui/plugins/070_users/edit_user_dialog.py b/jans-cli-tui/cli_tui/plugins/070_users/edit_user_dialog.py index d63cca5394f..1c50760bac4 100644 --- a/jans-cli-tui/cli_tui/plugins/070_users/edit_user_dialog.py +++ b/jans-cli-tui/cli_tui/plugins/070_users/edit_user_dialog.py @@ -1,49 +1,30 @@ -import re - -from typing import Optional, Sequence, Union, TypeVar, Callable +from typing import Optional, Sequence, Callable import asyncio from functools import partial - - from prompt_toolkit.layout.dimension import D from prompt_toolkit.layout.containers import ( HSplit, VSplit, DynamicContainer, Window, - AnyContainer ) from prompt_toolkit.widgets import ( - Box, Button, Label, - TextArea, - RadioList, CheckboxList, - Button, Dialog, ) from prompt_toolkit.eventloop import get_event_loop - -from cli import config_cli from utils.static import DialogResult from wui_components.jans_dialog_with_nav import JansDialogWithNav -from wui_components.jans_side_nav_bar import JansSideNavBar from wui_components.jans_cli_dialog import JansGDialog -from wui_components.jans_drop_down import DropDownWidget -from wui_components.jans_data_picker import DateSelectWidget from utils.utils import DialogUtils, common_data from wui_components.jans_vetrical_nav import JansVerticalNav from prompt_toolkit.formatted_text import AnyFormattedText - from typing import Any, Optional from prompt_toolkit.layout import ScrollablePane - - - from utils.multi_lang import _ - class EditUserDialog(JansGDialog, DialogUtils): """This user editing dialog """ @@ -57,13 +38,14 @@ def __init__( )-> Dialog: """init for `EditUserDialog`, inherits from two diffrent classes `JansGDialog` and `DialogUtils` + JansGDialog (dialog): This is the main dialog Class Widget for all Jans-cli-tui dialogs except custom dialogs like dialogs with navbar DialogUtils (methods): Responsable for all `make data from dialog` and `check required fields` in the form for any Edit or Add New - + Args: parent (widget): This is the parent widget for the dialog, to access `Pageup` and `Pagedown` title (str): The Main dialog title data (list): selected line data - button_functions (list, optional): Dialog main buttons with their handlers. Defaults to []. + buttons (list, optional): Dialog main buttons with their handlers. Defaults to []. save_handler (method, optional): handler invoked when closing the dialog. Defaults to None. """ super().__init__(parent, title, buttons) @@ -76,10 +58,21 @@ def __init__( self.create_window() def cancel(self) -> None: - self.future.set_result(DialogResult.CANCEL) + """method to invoked when canceling changes in the dialog (Cancel button is pressed) + """ + self.future.set_result(DialogResult.CANCEL) def get_claim_properties(self, claim): + """This method for getting claims properties + + Args: + claim (str): Claim + + Returns: + _type_: properties + """ + ret_val = {} for tmp in common_data.users.claims: if tmp['name'] == claim: @@ -183,8 +176,9 @@ def get_custom_attribute(attribute, multi=False): width=self.app.dialog_width, ) - def get_admin_ui_roles(self) -> None: + """This method for getting admin ui roles + """ async def coroutine(): cli_args = {'operation_id': 'get-all-adminui-roles'} self.app.start_progressing(_("Retreiving admin UI roles from server...")) @@ -195,6 +189,8 @@ async def coroutine(): asyncio.ensure_future(coroutine()) def add_admin_ui_role(self) -> None: + """This method for adding new admin ui roles + """ if not self.admin_ui_roles: self.get_admin_ui_roles() return @@ -218,13 +214,14 @@ def add_role(dialog) -> None: dialog = JansGDialog(self.app, title=_("Select Admin-UI"), body=body, buttons=buttons, width=self.app.dialog_width-20) self.app.show_jans_dialog(dialog) - def delete_admin_ui_role(self, **kwargs: Any) -> None: + """This method for deleting admin ui roles + """ self.admin_ui_roles_container.remove_item(kwargs['selected']) - - def add_claim(self) -> None: + """This method for adding new claim + """ cur_claims = [] for w in self.edit_user_content: if hasattr(w, 'me'): @@ -260,5 +257,11 @@ def add_claim(dialog) -> None: self.app.show_jans_dialog(dialog) def __pt_container__(self)-> Dialog: + """The container for the dialog itself + + Returns: + Dialog: The Edit User Dialog + """ + return self.dialog diff --git a/jans-cli-tui/cli_tui/plugins/070_users/main.py b/jans-cli-tui/cli_tui/plugins/070_users/main.py index f6d589318ef..2eefaa6434b 100755 --- a/jans-cli-tui/cli_tui/plugins/070_users/main.py +++ b/jans-cli-tui/cli_tui/plugins/070_users/main.py @@ -1,22 +1,14 @@ -import os -import sys import asyncio - from functools import partial from types import SimpleNamespace -from typing import Sequence, Any, Optional - +from typing import Any, Optional from prompt_toolkit.buffer import Buffer from prompt_toolkit.application import Application -from prompt_toolkit.layout.containers import HSplit, VSplit, Window, DynamicContainer, HorizontalAlign +from prompt_toolkit.layout.containers import HSplit, VSplit, DynamicContainer, HorizontalAlign from prompt_toolkit.layout.dimension import D -from prompt_toolkit.widgets import Button, Label, Frame, Dialog -from prompt_toolkit.formatted_text import HTML -from wui_components.jans_drop_down import DropDownWidget -from wui_components.jans_cli_dialog import JansGDialog +from prompt_toolkit.widgets import Button, Dialog from wui_components.jans_vetrical_nav import JansVerticalNav from edit_user_dialog import EditUserDialog - from utils.utils import DialogUtils, common_data from utils.static import DialogResult from utils.multi_lang import _ @@ -33,7 +25,7 @@ def __init__( """init for Plugin class "users" Args: - app (_type_): _description_ + app (Generic): The main Application class """ self.app = app self.pid = 'users' @@ -41,8 +33,6 @@ def __init__( self.users = {} self.widgets_ready = False - - def process(self) -> None: pass @@ -71,7 +61,6 @@ def set_center_frame(self) -> None: DynamicContainer(lambda: self.nav_buttons), ],style='class:outh_containers_scopes') - def update_user_list_container(self, pattern: Optional[str]='') -> None: """User management list """ @@ -114,7 +103,6 @@ def update_user_list_container(self, pattern: Optional[str]='') -> None: self.app.invalidate() - def get_users(self, start_index: int=1, pattern: Optional[str]='') -> None: """Gets Users from server. """ @@ -141,7 +129,6 @@ async def coroutine(): asyncio.ensure_future(coroutine()) - def edit_user_dialog(self, **kwargs: Any) -> None: """Method to display the edit user dialog """ @@ -155,8 +142,9 @@ def edit_user_dialog(self, **kwargs: Any) -> None: edit_user_dialog = EditUserDialog(self.app, title=title, data=data, save_handler=self.save_user) self.app.show_jans_dialog(edit_user_dialog) - def delete_user(self, **kwargs: Any) -> None: + """This method for the deletion of the User + """ def do_delete_user(): for user in self.users['entries']: @@ -182,7 +170,6 @@ async def coroutine(): tobefocused=self.user_list_container ) - def save_user(self, dialog: Dialog) -> None: """This method to save user data to server @@ -255,8 +242,9 @@ async def coroutine(): asyncio.ensure_future(coroutine()) - def get_claims(self) -> None: + """This method for getting claims + """ if hasattr(common_data.users, 'claims'): return async def coroutine(): @@ -270,6 +258,11 @@ async def coroutine(): asyncio.ensure_future(coroutine()) def search_user(self, tbuffer:Buffer) -> None: + """This method handel the search for Users + + Args: + tbuffer (Buffer): Buffer returned from the TextArea widget > GetTitleText + """ if not len(tbuffer.text) > 2: self.app.show_message(_("Error!"), _("Search string should be at least three characters"), tobefocused=self.app.center_container) return diff --git a/jans-cli-tui/cli_tui/plugins/999_jans/main.py b/jans-cli-tui/cli_tui/plugins/999_jans/main.py index bce9958198c..5b877812fae 100755 --- a/jans-cli-tui/cli_tui/plugins/999_jans/main.py +++ b/jans-cli-tui/cli_tui/plugins/999_jans/main.py @@ -1,23 +1,11 @@ -import os -import sys import asyncio - -from typing import Sequence - - from prompt_toolkit.application import Application -from prompt_toolkit.layout.containers import HSplit, VSplit, Window, Float +from prompt_toolkit.layout.containers import HSplit from prompt_toolkit.layout.dimension import D -from prompt_toolkit.widgets import Button, Label, Frame -from prompt_toolkit.formatted_text import HTML -from prompt_toolkit.widgets import Shadow -from prompt_toolkit.layout.controls import FormattedTextControl - - +from prompt_toolkit.widgets import Button, Frame from utils.multi_lang import _ from cli import config_cli - class Plugin: """This is a general class for plugins """ @@ -28,7 +16,7 @@ def __init__( """init for Plugin class "Jans CLI Menu" Args: - app (_type_): _description_ + app (Generic): The main Application class """ self.app = app self.pid = 'jans-menu' @@ -45,7 +33,6 @@ def __init__( height=D() ) - def process(self) -> None: pass @@ -55,13 +42,11 @@ def set_center_frame(self) -> None: self.app.center_container = self.menu_container - def exit_cli(self) -> None: """Exits """ self.app.exit(result=False) - def logout_exit_cli(self) -> None: """Removes auth token and exits """