Best Python code snippet using lisa_python
directory_helper.py
Source: directory_helper.py
...12 sub_sub_folder_names = ['Authentic/', 'Tampered/']13 if os.path.exists(new_dir):14 delete_dir_files(new_dir)15 if(len(os.listdir(new_dir)) == 0):16 create_directory(new_dir, sub_folder_names)17 create_directory(train_dir, sub_sub_folder_names)18 create_directory(test_dir, sub_sub_folder_names)19 # create_directory(valid_dir, sub_sub_folder_names)20 return 'Train/Test and Authentic/Tampered directories created!'21 else:22 if os.path.exists(train_dir) and os.path.exists(test_dir):23 len_train = len(os.listdir(train_dir))24 len_test = len(os.listdir(test_dir))25 # len_valid = len(os.listdir(valid_dir))26 if(len_train != 0) and (len_test != 0):27 delete_dir_files(train_dir)28 delete_dir_files(test_dir)29 # delete_dir_files(valid_dir)30 if(len_train == 0) and (len_test == 0):31 create_directory(train_dir, sub_sub_folder_names)32 create_directory(test_dir, sub_sub_folder_names)33 # create_directory(valid_dir, sub_sub_folder_names)34 delete_dir_files(train_dir + sub_sub_folder_names[0])35 delete_dir_files(test_dir + sub_sub_folder_names[1])36 # delete_dir_files(valid_dir + sub_sub_folder_names[2])37 return 'Authentic/Tampered Folders created in Train/Test/ directories!'38 else:39 return 'All necessary folders already exist!'40 else:41 create_directory(new_dir)42 create_directory(new_dir, sub_folder_names)43 create_directory(train_dir, sub_sub_folder_names)44 create_directory(test_dir, sub_sub_folder_names)45 # create_directory(valid_dir, sub_sub_folder_names)46 return 'All directories needed created!'47def create_directory(directory, sub_folder=None):48 """Creates new directories and subfolders. Deletes any MacOS auto generated files(.DS_Store).49 Params: directory to create, optional=sub_folder.50 """51 if(sub_folder == None):52 os.makedirs(directory)53 else:54 for folder in tqdm(sub_folder):55 os.makedirs(os.path.join(directory, folder))56 delete_dir_files(directory)57def delete_dir_files(directory):58 """Deletes any files found in a directory."""59 folder = os.listdir(directory)60 for f in tqdm(folder):61 if(os.path.isfile(directory + f)):...
DataCollector.py
Source: DataCollector.py
1import os2import cv23import time4import calendar5def create_directory(dir_path):6 if not os.path.isdir(dir_path):7 os.mkdir(dir_path)8class DataCollector:9 def __init__(self, base_path="."):10 # Base directory for all data11 data_dir = os.path.join(base_path, "data")12 # Train and validation data go in separate directories13 train_dir = os.path.join(data_dir, "train")14 val_dir = os.path.join(data_dir, "validation")15 # Train data directories16 train_rock_dir = os.path.join(train_dir, "rock")17 train_paper_dir = os.path.join(train_dir, "paper")18 train_scissors_dir = os.path.join(train_dir, "scissors")19 train_none_dir = os.path.join(train_dir, "none")20 # Validation data directories21 val_rock_dir = os.path.join(val_dir, "rock")22 val_paper_dir = os.path.join(val_dir, "paper")23 val_scissors_dir = os.path.join(val_dir, "scissors")24 val_none_dir = os.path.join(val_dir, "none")25 create_directory(data_dir)26 create_directory(train_dir)27 create_directory(val_dir)28 create_directory(train_rock_dir)29 create_directory(train_paper_dir)30 create_directory(train_scissors_dir)31 create_directory(train_none_dir)32 create_directory(val_rock_dir)33 create_directory(val_paper_dir)34 create_directory(val_scissors_dir)35 create_directory(val_none_dir)36 self.validation_dir = val_dir37 self.train_dir = train_dir38 def save_image(self, image, label, target_folder):39 label = label.lower()40 gmt = time.gmtime()41 timestamp = calendar.timegm(gmt)42 filename = f"{label}{timestamp}.jpg"43 if target_folder == "train":44 filepath = os.path.join(self.train_dir, label, filename)45 else:46 filepath = os.path.join(self.validation_dir, label, filename)47 cv2.imwrite(filepath, image)...
__init__.py
Source: __init__.py
...11PROCESSED_USER_INTRO_FILE_PATH = PROCESSED_JSON_FILE_DIR + "/" + "PinutUserIntroFiles"12PROCESSED_USER_FILE_PATH = PROCESSED_JSON_FILE_DIR + "/" + "PinutUserFiles"13PROCESSED_CONNECTION_FILE_PATH = PROCESSED_JSON_FILE_DIR + "/" + "PinutConnectionFiles"14PROCESSED_FEEDBACK_FILE_PATH = PROCESSED_JSON_FILE_DIR + "/" + "PinutFeedbackFiles"15def create_directory(path):16 try:17 if not os.path.exists(path):18 os.makedirs(path)19 except Exception,e:20 print "Exception : %s Not able to create directory : %s" % (e,path)21create_directory(PINUT_JSON_FILE_DIR)22create_directory(PROCESSED_JSON_FILE_DIR)23create_directory(PINUT_USER_INTRO_FILE_PATH)24create_directory(PINUT_USER_FILE_PATH)25create_directory(PINUT_CONNECTION_FILE_PATH)26create_directory(PINUT_FEEDBACK_FILE_PATH)27create_directory(PINUT_CAPTIVE_DATA_FILE_PATH)28create_directory(PROCESSED_USER_INTRO_FILE_PATH)29create_directory(PROCESSED_USER_FILE_PATH)30create_directory(PROCESSED_CONNECTION_FILE_PATH)...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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!!