Best Python code snippet using tempest_python
recent_manager.py
Source:recent_manager.py
1import os2from designer.utils.utils import get_config_dir, get_fs_encoding3RECENT_FILES_NAME = 'recent_files'4class RecentManager(object):5 '''RecentManager is responsible for retrieving/storing the list of recently6 opened/saved projects.7 '''8 def __init__(self):9 super(RecentManager, self).__init__()10 self.list_projects = []11 self.max_recent_files = 1012 self.load_files()13 def add_path(self, path):14 '''To add file to RecentManager.15 :param path: path of project16 '''17 if isinstance(path, bytes):18 path = path.decode(get_fs_encoding()).encode(get_fs_encoding())19 _file_index = 020 try:21 _file_index = self.list_projects.index(path)22 except:23 _file_index = -124 if _file_index != -1:25 # If _file is already present in list_files, then move it to 0 index26 self.list_projects.remove(path)27 self.list_projects.insert(0, path)28 # Recent files should not be greater than max_recent_files29 while len(self.list_projects) > self.max_recent_files:30 self.list_projects.pop()31 self.store_files()32 def store_files(self):33 '''To store the list of files on disk.34 '''35 _string = ''36 for _file in self.list_projects:37 _string += _file + '\n'38 recent_file_path = os.path.join(get_config_dir(),39 RECENT_FILES_NAME)40 f = open(recent_file_path, 'w')41 f.write(_string)42 f.close()43 def load_files(self):44 '''To load the list of files from disk45 '''46 recent_file_path = os.path.join(get_config_dir(),47 RECENT_FILES_NAME)48 if not os.path.exists(recent_file_path):49 return50 f = open(recent_file_path, 'r')51 path = f.readline()52 while path != '':53 file_path = path.strip()54 if isinstance(file_path, bytes):55 file_path = file_path.decode(get_fs_encoding()).encode(56 get_fs_encoding())57 if os.path.exists(file_path):58 self.list_projects.append(file_path)59 path = f.readline()...
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!!