def close_tab(self): if self.driver: self.driver.find_element_by_tag_name('body').send_keys(CL_TAB) try: self.driver.current_url() except: self.driver = None log.debug('Browser was closed.')
def find_apis(): """ Find APIs """ global api_lib api_lib = {} log.debug('Looking for APIs in: ' + str(settings.API_DIRS)) for finder, name, _ in pkgutil.iter_modules(settings.API_DIRS): try: file = finder.find_module(name).load_module(name) for member in dir(file): obj = getattr(file, member) if inspect.isclass(obj): for parent in obj.__bases__: if 'Api' is parent.__name__: api = obj() api_lib[api.key] = api except Exception as e: print(traceback.format_exc()) log.error('Error loading \'' + name + '\' ' + str(e))
def find_mods(): """ Find and import modules from the module directories """ global mod_lib mod_lib = [] log.debug('Looking for modules in: ' + str(settings.MOD_DIRS)) for finder, name, _ in pkgutil.iter_modules(settings.MOD_DIRS): try: mod = finder.find_module(name).load_module(name) for member in dir(mod): obj = getattr(mod, member) if inspect.isclass(obj): for parent in obj.__bases__: if 'Module' is parent.__name__: mod_lib.append(obj()) except Exception as e: print((traceback.format_exc())) log.error('Error loading \'' + name + '\' ' + str(e)) mod_lib.sort(key=lambda mod: mod.priority, reverse=True)
def action(self, text): try: api_lib['voice_browse_api'].driver.current_url except: api_lib['voice_browse_api'].driver = None log.debug('Browser was closed.') funcs = { 0: api_lib['voice_browse_api'].search, 1: api_lib['voice_browse_api'].open, 2: api_lib['voice_browse_api'].type, 3: api_lib['voice_browse_api'].close_tab, 4: api_lib['voice_browse_api'].close, 5: api_lib['voice_browse_api'].clear, 6: api_lib['voice_browse_api'].maximize, 7: api_lib['voice_browse_api'].click, 8: api_lib['voice_browse_api'].switch_tab, } if self.case < 3: funcs[self.case](self.group1) else: funcs[self.case]()
def list_apis(): """ List APIs """ global api_lib log.debug('APIs: ' + str(list(api_lib.keys()))[1:-1])
def load_user(self, username): """ Load (username).yml data into the user """ with open(os.path.join(settings.USERS_DIR, username + '.yml'), 'r') as f: self.user = yaml.load(f) log.debug('Logged in as: ' + self.user['user_api']['username'])