Best Python code snippet using lettuce_webdriver_python
serviceset_screen.py
Source:serviceset_screen.py
1# Core modules - Developers only2import py_cui3import os4import shutil5import sys6sys.path.insert(1, '..')7import i18n8i18n.load_path.append('./locales/')9i18n.set('filename_format', '{namespace}.{format}')10# Local modules - Developers only11import cui.screen_manager12import tasks.logr as LOG13import tasks.dev as DEV14import tasks.config as CONFIG15import tasks.serviceset as TASKS16import tasks.ansible as ANSIBLE17import tasks.choice as CHOICE18# Functions - Developers only19class ServiceSettings_Screen(cui.screen_manager.ScreenManager):20# ServiceSettings Screen Class21 def initialize_screen_elements(self):22 # ServiceSettings Screen widget23 serviceset_widget_set = self.manager.root.create_new_widget_set(8, 8)24 self.page_heading = serviceset_widget_set.add_label(i18n.t('serviceset.screen.page_heading'), 0, 2, column_span=4)25 self.page_heading.set_selectable(False)26 self.option_list = serviceset_widget_set.add_scroll_menu(i18n.t('serviceset.screen.option_list_title'), 1, 1, row_span=5, column_span=2)27 self.option_list.add_key_command(py_cui.keys.KEY_E_UPPER, self.servicesetting_change)28 self.option_list.add_key_command(py_cui.keys.KEY_E_LOWER, self.servicesetting_change)29 self.option_list.add_key_command(py_cui.keys.KEY_ENTER, self.get_servicesettings_desc)30 self.option_list.add_text_color_rule('?', py_cui.YELLOW_ON_BLACK,'startswith', selected_color=py_cui.YELLOW_ON_WHITE)31 self.option_list.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith', selected_color=py_cui.BLACK_ON_WHITE)32 self.option_list.set_focus_border_color(color=py_cui.GREEN_ON_BLACK)33 self.option_list.set_focus_text(i18n.t('serviceset.screen.option_list_keys'))34 self.option_desc = serviceset_widget_set.add_block_label(i18n.t('serviceset.screen.option_desc_placeholder'), 1, 3, row_span=4, column_span=3, padx=5, center=0)35 self.main_menu_popup = serviceset_widget_set.add_button(i18n.t('base.screen.main_menu'), 7, 1, row_span=1, column_span=1, command=self.main_menu_popup)36 self.main_menu_popup.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith')37 self.accept_parameters = serviceset_widget_set.add_button(i18n.t('serviceset.screen.accept_parameters'), 7, 3, row_span=1, column_span=2, command=self.accept_changes)38 self.accept_parameters.set_color(color=py_cui.CYAN_ON_BLACK)39 self.accept_parameters.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith')40 return serviceset_widget_set41 def main_menu_choice(self, menu_item):42 # ServiceSet Screen Main Menu Choices43 if menu_item == i18n.t('base.main_menu.service_update').format(DEV.service_selection):44 # Updates the specified service45 self.service_update()46 elif menu_item == i18n.t('base.main_menu.service_restart').format(DEV.service_selection):47 # Restarts the specified service48 self.service_restart()49 elif menu_item == i18n.t('base.main_menu.service_customize').format(DEV.service_selection):50 # Restarts the specified service51 self.service_customize()52 elif menu_item == i18n.t('base.main_menu.service_stop').format(DEV.service_selection):53 # Restarts the specified service54 self.service_stop()55 elif menu_item == i18n.t('base.main_menu.service_remove').format(DEV.service_selection):56 # Restarts the specified service57 self.service_remove()58 elif menu_item == i18n.t('base.main_menu.service_reset').format(DEV.service_selection):59 # Restarts the specified service60 self.service_reset()61 elif menu_item == i18n.t('base.main_menu.service_info'):62 # Gets the Service Info Screen63 DEV.prev_screen = 'serviceset'64 self.manager.get_serviceinfo_screen()65 elif menu_item == i18n.t('base.main_menu.back_to_start'):66 # Goes back to start, closes and re-encrypts config67 LOG.write(i18n.t('log.choicesc.move_to_start').format(DEV.current_configfile))68 CONFIG.encrypt_config()69 CHOICE.get_configs()70 self.manager.get_choice_screen()71 elif menu_item == i18n.t('base.main_menu.get_about_screen'):72 # Gets the About Screen73 DEV.prev_screen = 'serviceset'74 self.manager.get_about_screen()75 else:76 pass77 def main_menu_popup(self):78 # Main Menu Popup79 menu_choices = [i18n.t('base.main_menu.service_update').format(DEV.service_selection),80 i18n.t('base.main_menu.service_restart').format(DEV.service_selection),81 i18n.t('base.main_menu.service_customize').format(DEV.service_selection),82 i18n.t('base.main_menu.service_stop').format(DEV.service_selection),83 i18n.t('base.main_menu.service_remove').format(DEV.service_selection),84 i18n.t('base.main_menu.service_reset').format(DEV.service_selection),85 "---",86 i18n.t('base.main_menu.service_info'),87 i18n.t('base.main_menu.back_to_start'),88 i18n.t('base.main_menu.get_about_screen')89 ]90 self.manager.root.show_menu_popup(i18n.t('base.screen.main_menu'), menu_choices, self.main_menu_choice)91 def accept_changes(self):92 # Return to operations screen with settings changed93 self.option_list.clear()94 self.manager.get_operations_screen()95 def service_customize(self):96 # Create a temporary dockerfile for specified service97 if not os.path.isdir(DEV.override_path + DEV.service_key):98 os.mkdir(DEV.override_path + DEV.service_key)99 os.chmod(DEV.override_path + DEV.service_key, 0o755)100 if os.path.exists(DEV.override_path + DEV.service_key + '/docker-compose.override.yml.j2'):101 os.remove(DEV.override_path + DEV.service_key + '/docker-compose.override.yml.j2')102 shutil.copy(DEV.rolespath + DEV.service_key + '/templates/docker-compose.' + DEV.service_key + '.yml.j2',103 DEV.override_path + DEV.service_key + '/docker-compose.override.yml.j2')104 os.chmod(DEV.override_path + DEV.service_key + '/docker-compose.override.yml.j2', 0o755) # Sets new permissions105 self.manager.root.show_message_popup('', i18n.t('serviceset.popup.override_create')106 .format(DEV.service_selection, DEV.override_path + DEV.service_key))107 LOG.write(i18n.t('log.servicesetsc.override_create').format(DEV.service_selection))108 def service_update(self):109 # Update specified service110 self.option_list.clear()111 self.manager.root.stop()112 ANSIBLE.run_update()113 self.manager.get_operations_screen()114 self.manager.root.start()115 def service_restart(self):116 # Restart specified service117 self.option_list.clear()118 self.manager.root.stop()119 ANSIBLE.run_restart()120 self.manager.get_operations_screen()121 self.manager.root.start()122 def service_stop(self):123 # Stop specified service124 self.option_list.clear()125 self.manager.root.stop()126 ANSIBLE.run_stop()127 self.manager.get_operations_screen()128 self.manager.root.start()129 def service_remove(self):130 # Remove specified service131 self.option_list.clear()132 self.manager.root.stop()133 ANSIBLE.run_remove()134 self.manager.get_operations_screen()135 self.manager.root.start()136 def service_reset(self):137 # Reset specified service138 self.option_list.clear()139 self.manager.root.stop()140 ANSIBLE.run_reset()141 self.manager.get_operations_screen()142 self.manager.root.start()143 def set_servicesettingkey(self):144 # Sets the settings key, related to the service145 k_pos = self.option_list.get()146 settingkey = str(k_pos)147 return settingkey148 def get_servicesettings_desc(self):149 # List all editable settings for selected service150 DEV.servicesetting_key = self.set_servicesettingkey()151 self.option_desc.set_title('\n' + i18n.t('serviceset.screen.current_value') \152 + ' ' + str(TASKS.get_prev_value()) + '\n\n\n' \153 + i18n.t('serviceset.screen.option_title') + '\n' \154 + i18n.t('serviceset_tooltips.' + DEV.servicesetting_key[1:]) \155 + '\n\n' + i18n.t('serviceset_tooltips.see_tooltip')156 )157 LOG.write(i18n.t('log.servicesetsc.desc_given')158 .format(DEV.service_key, DEV.servicesetting_key[1:]))159 def servicesetting_change(self):160 # Popup for settings change161 DEV.servicesetting_key = self.set_servicesettingkey()162 pop_up = TASKS.which_popup(DEV.servicesetting_key[1:])163 if pop_up == 'yn':164 self.manager.root.show_yes_no_popup(i18n.t('serviceset.popup.yesno')165 .format(' /' + DEV.service_key + DEV.servicesetting_key),166 self.set_usersettings_yesno167 )168 else:169 self.manager.root.show_text_box_popup(i18n.t('serviceset.popup.textbox')170 .format(' /' + DEV.service_key + DEV.servicesetting_key),171 self.set_usersettings_text172 )173 def set_usersettings_yesno(self, yn_set):174 # Writes new setting to config file, if changed175 if yn_set:176 LOG.write(i18n.t('log.servicesetsc.set_to')177 .format(DEV.servicesetting_key[1:], str('true')))178 TASKS.set_newvalue(True)179 self.manager.root.close_popup()180 self.manager.root.move_focus(self.option_list)181 else:182 LOG.write(i18n.t('log.servicesetsc.set_to')183 .format(DEV.servicesetting_key[1:], str('false')))184 TASKS.set_newvalue(False)185 self.manager.root.close_popup()186 self.manager.root.move_focus(self.option_list)187 def set_usersettings_text(self, text_set):188 # Writes new setting to config file, if changed189 if text_set:190 if DEV.check_specialchars(text_set) == False:191 LOG.write(i18n.t('log.servicesetsc.set_to')192 .format(DEV.servicesetting_key[1:], str(text_set)))193 TASKS.set_newvalue(text_set)194 else:195 LOG.write(i18n.t('log.servicesetsc.changes_non'))196 self.manager.root.move_focus(self.option_list)197 else:198 LOG.write(i18n.t('log.servicesetsc.changes_non'))...
coreset_screen.py
Source:coreset_screen.py
1# Core modules - Developers only2import py_cui3import sys4sys.path.insert(1, '..')5import i18n6i18n.load_path.append('./locales/')7i18n.set('filename_format', '{namespace}.{format}')8# Local modules - Developers only9import cui.screen_manager10import tasks.logr as LOG11import tasks.dev as DEV12import tasks.config as CONFIG13import tasks.coreset as TASKS14import tasks.ssh as SSH15import tasks.ansible as ANSIBLE16import tasks.choice as CHOICE17# Functions - Developers only18class CoreSettings_Screen(cui.screen_manager.ScreenManager):19# CoreSettings Screen Class20 def initialize_screen_elements(self):21 # CoreSettings Screen widget22 coreset_widget_set = self.manager.root.create_new_widget_set(8, 8)23 self.page_heading = coreset_widget_set.add_label(i18n.t('coreset.screen.page_heading'), 0, 2, column_span=4)24 self.page_heading.set_selectable(False)25 self.coreset_list = coreset_widget_set.add_scroll_menu(i18n.t('coreset.screen.coreset_list_title'), 1, 1, row_span=5, column_span=2)26 self.coreset_list.add_key_command(py_cui.keys.KEY_E_UPPER, self.coreset_change)27 self.coreset_list.add_key_command(py_cui.keys.KEY_E_LOWER, self.coreset_change)28 self.coreset_list.add_key_command(py_cui.keys.KEY_ENTER, self.get_coreset_desc)29 self.coreset_list.add_text_color_rule('?', py_cui.YELLOW_ON_BLACK,'startswith', selected_color=py_cui.YELLOW_ON_WHITE)30 self.coreset_list.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith', selected_color=py_cui.BLACK_ON_WHITE)31 self.coreset_list.set_focus_border_color(color=py_cui.GREEN_ON_BLACK)32 self.coreset_list.set_focus_text(i18n.t('coreset.screen.coreset_list_keys'))33 self.coreset_desc = coreset_widget_set.add_block_label(i18n.t('coreset.screen.coreset_desc_placeholder'), 1, 3, row_span=4, column_span=4, padx=5, center=0)34 self.main_menu_popup = coreset_widget_set.add_button(i18n.t('base.screen.main_menu'), 7, 1, row_span=1, column_span=1, command=self.main_menu_popup)35 self.main_menu_popup.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith')36 self.accept_parameters = coreset_widget_set.add_button(i18n.t('coreset.screen.accept_parameters'), 7, 3, row_span=1, column_span=2, command=self.accept_changes)37 self.accept_parameters.set_color(color=py_cui.CYAN_ON_BLACK)38 self.accept_parameters.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith')39 return coreset_widget_set40 def main_menu_choice(self, menu_item):41 # Coreset Screen Main Menu Choices42 if menu_item == i18n.t('base.main_menu.test_ssh'):43 # Sets up passwordless SSH keys44 self.test_ssh()45 if menu_item == i18n.t('base.main_menu.setup_ssh'):46 # Sets up passwordless SSH keys47 self.setup_ssh()48 if menu_item == i18n.t('base.main_menu.test_ssh'):49 # Sets up passwordless SSH keys50 self.test_ssh()51 elif menu_item == i18n.t('base.main_menu.setup_bastion'):52 # Gets the Bastion Screen53 self.setup_bastion()54 elif menu_item == i18n.t('base.main_menu.service_info'):55 # Gets the Service Info Screen56 DEV.prev_screen = 'coreset'57 self.manager.get_serviceinfo_screen()58 elif menu_item == i18n.t('base.main_menu.back_to_start'):59 # Goes back to start, closes and re-encrypts config60 LOG.write(i18n.t('log.choicesc.move_to_start').format(DEV.current_configfile))61 CONFIG.encrypt_config()62 CHOICE.get_configs()63 self.manager.get_choice_screen()64 elif menu_item == i18n.t('base.main_menu.get_about_screen'):65 # Gets the About Screen66 DEV.prev_screen = 'coreset'67 self.manager.get_about_screen()68 else:69 pass70 def main_menu_popup(self):71 # Main Menu Popup72 menu_choices = [i18n.t('base.main_menu.test_ssh'),73 i18n.t('base.main_menu.setup_ssh'),74 i18n.t('base.main_menu.setup_bastion'),75 "---",76 i18n.t('base.main_menu.service_info'),77 i18n.t('base.main_menu.back_to_start'),78 i18n.t('base.main_menu.get_about_screen')79 ]80 self.manager.root.show_menu_popup(i18n.t('base.screen.main_menu'), menu_choices, self.main_menu_choice)81 def accept_changes(self):82 # Return to operations screen83 LOG.write(i18n.t('log.coresetsc.confval_create').format(DEV.coreset_key))84 self.manager.root.stop()85 ANSIBLE.run_deploy()86 self.coreset_list.clear()87 self.manager.get_operations_screen()88 self.manager.root.start()89 LOG.write(i18n.t('log.coresetsc.confval_set').format(DEV.coreset_key))90 def setup_ssh(self):91 # Sets up SSH keys92 self.manager.root.stop()93 SSH.setup_sshkey()94 self.manager.root.show_yes_no_popup(i18n.t('coreset.popup.setupssh_done')95 .format(DEV.vlab_ssh_key),96 self.set_createdssh_yesno97 )98 self.manager.root.start()99 def test_ssh(self):100 # Tests SSH connections101 pass_status = SSH.test_ssh_pass()102 pubkey_status = SSH.test_ssh_pkey()103 self.manager.root.show_message_popup('', i18n.t('coreset.popup.testssh_done')104 .format(str(pass_status), str(pubkey_status)))105 def setup_bastion(self):106 # Gets bastion setup screen107 self.manager.get_bastion_screen()108 def set_coresetkey(self):109 # Sets core setting option110 k_pos = self.coreset_list.get()111 coresetkey = str(k_pos)[1:]112 return coresetkey113 def get_coreset_desc(self):114 # Get description for the selected core option115 DEV.coreset_key = self.set_coresetkey()116 coreset_key_dot = DEV.coreset_key.replace("/",".")117 self.coreset_desc.set_title("\n" + i18n.t('coreset.screen.current_value') \118 + " " + str(TASKS.get_prev_value()) + "\n\n\n" \119 + i18n.t('coreset.screen.coreset_title') + "\n" \120 + i18n.t('coreset_tooltips.' + coreset_key_dot) \121 + "\n\n" + i18n.t('coreset_tooltips.see_tooltip')122 )123 LOG.write(i18n.t('log.coresetsc.desc_given').format(DEV.coreset_key))124 def coreset_change(self):125 # Popup for core option change126 DEV.coreset_key = self.set_coresetkey()127 pop_up = TASKS.which_popup(DEV.coreset_key)128 if pop_up == 'yn':129 self.manager.root.show_yes_no_popup(i18n.t('coreset.popup.yesno')130 .format(' /' + DEV.coreset_key),131 self.set_usercoreset_yesno132 )133 else:134 self.manager.root.show_text_box_popup(i18n.t('coreset.popup.textbox')135 .format(' /' + DEV.coreset_key),136 self.set_usercoreset_text137 )138 def set_createdssh_yesno(self, yn_set):139 # Sends user back to Choice Screen, to use new ssh keys140 if yn_set:141 LOG.write(i18n.t('log.coresetsc.newkey_refresh')142 .format(DEV.vlab_ssh_key))143 CONFIG.encrypt_config()144 CHOICE.get_configs()145 self.manager.get_choice_screen()146 else:147 return148 def set_usercoreset_yesno(self, yn_set):149 # Writes new core option to config file, if changed150 if yn_set:151 LOG.write(i18n.t('log.coresetsc.set_to')152 .format(DEV.coreset_key, str('true')))153 TASKS.set_newvalue(True)154 return155 else:156 LOG.write(i18n.t('log.coresetsc.set_to')157 .format(DEV.coreset_key, str('false')))158 TASKS.set_newvalue(False)159 def set_usercoreset_text(self, text_set):160 # Writes new core option to config file, if changed161 if text_set:162 if DEV.check_specialchars(text_set) == False:163 LOG.write(i18n.t('log.coresetsc.set_to').format(DEV.coreset_key, str(text_set)))164 TASKS.set_newvalue(text_set)165 return166 else:167 LOG.write(i18n.t('log.coresetsc.changes_non'))168 self.manager.root.move_focus(self.coreset_list)169 else:170 LOG.write(i18n.t('log.coresetsc.changes_non'))...
bastion_screen.py
Source:bastion_screen.py
1# Core modules - Developers only2import py_cui3import sys4sys.path.insert(1, '..')5import i18n6i18n.load_path.append('./locales/')7i18n.set('filename_format', '{namespace}.{format}')8i18n.set('fallback', 'en')9# Local modules - Developers only10import cui.screen_manager11import tasks.logr as LOG12import tasks.dev as DEV13import tasks.bastion as TASKS14# Functions - Developers only15class Bastion_Screen(cui.screen_manager.ScreenManager):16# Bastion Screen Class17 def initialize_screen_elements(self):18 # Bastion Screen widget19 bastion_widget_set = self.manager.root.create_new_widget_set(8, 8)20 self.page_heading = bastion_widget_set.add_label(i18n.t('bastion.screen.page_heading'), 0, 2, column_span=4)21 self.page_heading.set_selectable(False)22 self.bastion_list = bastion_widget_set.add_scroll_menu(i18n.t('bastion.screen.bastion_list_title'), 1, 1, row_span=5, column_span=2)23 self.bastion_list.add_key_command(py_cui.keys.KEY_E_UPPER, self.bastion_change)24 self.bastion_list.add_key_command(py_cui.keys.KEY_E_LOWER, self.bastion_change)25 self.bastion_list.add_key_command(py_cui.keys.KEY_ENTER, self.get_bastion_desc)26 self.bastion_list.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith', selected_color=py_cui.BLACK_ON_WHITE)27 self.bastion_list.set_focus_border_color(color=py_cui.GREEN_ON_BLACK)28 self.bastion_list.set_focus_text(i18n.t('bastion.screen.bastion_list_keys'))29 self.bastion_desc = bastion_widget_set.add_block_label(i18n.t('bastion.screen.bastion_desc_placeholder'), 1, 3, row_span=4, column_span=4, padx=5, center=0)30 self.accept_parameters = bastion_widget_set.add_button(i18n.t('bastion.screen.accept_parameters'), 7, 3, row_span=1, column_span=2, command=self.accept_changes)31 self.accept_parameters.set_color(color=py_cui.CYAN_ON_BLACK)32 self.accept_parameters.add_text_color_rule('', py_cui.WHITE_ON_BLACK,'startswith')33 return bastion_widget_set34 def accept_changes(self):35 # Return to operations screen36 TASKS.check_bastion()37 self.bastion_list.clear()38 self.manager.get_coreset_screen()39 def get_bastion_desc(self):40 # Get description for the selected bastion option41 k_pos = self.bastion_list.get()42 DEV.bastion_key = str(k_pos)[1:]43 bastion_key_dot = DEV.bastion_key.replace("/",".")44 self.bastion_desc.set_title("\n" + i18n.t('bastion.screen.current_value') \45 + " " + str(TASKS.get_prev_value()) + "\n\n\n" \46 + i18n.t('bastion.screen.bastion_title') + "\n" \47 + i18n.t('bastion_tooltips.' + bastion_key_dot) \48 + "\n\n" + i18n.t('bastion_tooltips.see_tooltip')49 )50 LOG.write(i18n.t('log.bastionsc.desc_given').format(DEV.bastion_key))51 def bastion_change(self):52 # Popup for core option change53 k_pos = self.bastion_list.get()54 DEV.bastion_key = str(k_pos)[1:]55 pop_up = TASKS.which_popup(DEV.bastion_key)56 if pop_up == 'yn':57 self.manager.root.show_yes_no_popup(i18n.t('bastion.popup.yesno')58 .format('/' + DEV.bastion_key),59 self.set_userbastion_yesno60 )61 else:62 self.manager.root.show_text_box_popup(i18n.t('bastion.popup.textbox')63 .format('/' + DEV.bastion_key),64 self.set_userbastion_text65 )66 def set_userbastion_yesno(self, yn_set):67 # Writes new core option to config file, if changed68 if yn_set:69 LOG.write(i18n.t('log.bastionsc.set_to')70 .format(DEV.bastion_key, str('true')))71 TASKS.set_newvalue(True)72 return73 else:74 LOG.write(i18n.t('log.bastionsc.set_to')75 .format(DEV.bastion_key, str('false')))76 TASKS.set_newvalue(False)77 def set_userbastion_text(self, text_set):78 # Writes new core option to config file, if changed79 if text_set:80 if DEV.check_specialchars(text_set) == False:81 LOG.write(i18n.t('log.bastionsc.set_to').format(DEV.bastion_key, str(text_set)))82 TASKS.set_newvalue(text_set)83 return84 else:85 LOG.write(i18n.t('log.bastionsc.changes_non'))86 self.manager.root.move_focus(self.bastion_list)87 else:88 LOG.write(i18n.t('log.bastionsc.changes_non'))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!