How to use safe_files method in molecule

Best Python code snippet using molecule_python

FsCryptManger.py

Source:FsCryptManger.py Github

copy

Full Screen

1#!/usr/bin/env python2import commands3import os4import time5from ovd.Logger import Logger6class FsCryptManger:7 def __init__(self, directory, key_id):8 self.safe_dir = directory 9 self.key_id = key_id10 self.postfix = '.asc'11 def encrypt_dir(self):12 safe_files = self.traverse_path()13 for filepath in safe_files:14 if not filepath.endswith(self.postfix):15 self.encrypt_file(filepath)16 def decrypt_dir(self):17 safe_files = self.traverse_path()18 for filepath in safe_files:19 if filepath.endswith(self.postfix):20 self.decrypt_file(filepath)21 def traverse_path(self):22 safe_files = []23 for dirpath, dirnames, filenames in os.walk(self.safe_dir):24 for filename in filenames:25 filepath = os.path.join(dirpath,filename)26 if os.path.isfile(filepath) and '/.' not in filepath:27 safe_files.append(filepath)28 return safe_files29 def decrypt_file(self,path):30 if path.endswith(self.postfix) is False:31 Logger.error('the path is not a secret file %s'%(path))32 return None33 if path is None or len(path.strip()) is 0:34 Logger.error('the path is None or empty')35 return None36 if os.path.isfile(path) is False:37 Logger.error( 'the path is not file %s'%(path))38 return None39 dist_path = path[0:-4]40 decrypt_cmd = 'gpg -o %s --decrypt %s'%(dist_path, path)41 s,o = commands.getstatusoutput(decrypt_cmd)42 if s is not 0:43 Logger.error( 'decrypt path err cmd[%s]'%(decrypt_cmd))44 Logger.error( 'the out put [%d %s]'%(s,o))45 return None46 owner_cmd = 'chown --reference=%s %s'%(path, dist_path)47 s,o = commands.getstatusoutput(owner_cmd)48 if s is not 0:49 Logger.error( 'chown err cmd[%s]'%(owner_cmd))50 Logger.error( 'the out put [%d %s]'%(s,o))51 return None52 mode_cmd = 'chmod --reference=%s %s'%(path, dist_path)53 s,o = commands.getstatusoutput(mode_cmd)54 if s is not 0:55 Logger.error( 'chmod err cmd[%s]'%(mode_cmd))56 Logger.error( 'the out put [%d %s]'%(s,o))57 return None58 touch_cmd = 'touch --reference=%s %s'%(path, dist_path)59 s,o = commands.getstatusoutput(touch_cmd)60 if s is not 0:61 Logger.error( 'touch err cmd[%s]'%(touch_cmd))62 Logger.error( 'the out put [%d %s]'%(s,o))63 return None64 os.unlink(path)65 return True66 def encrypt_file(self,path):67 if path.endswith(self.postfix):68 Logger.error( 'the path is already encrypt')69 return None70 if path is None or len(path.strip()) is 0:71 Logger.error( 'the path is None or empty')72 return None73 if os.path.isfile(path) is False:74 Logger.error( 'the path is not file %s'%(path))75 return None76 encrypt_cmd = 'gpg -ea -r %s %s'%(self.key_id, path)77 s,o = commands.getstatusoutput(encrypt_cmd)78 if s is not 0:79 Logger.error( 'encrypt path err cmd[%s]'%(encrypt_cmd))80 Logger.error( 'the out put [%d %s]'%(s,o))81 return None82 owner_cmd = 'chown --reference=%s %s%s'%(path, path, self.postfix)83 s,o = commands.getstatusoutput(owner_cmd)84 if s is not 0:85 Logger.error( 'owner path err cmd[%s]'%(owner_cmd))86 Logger.error( 'the out put [%d %s]'%(s,o))87 return None88 mode_cmd = 'chmod --reference=%s %s%s'%(path, path, self.postfix)89 s,o = commands.getstatusoutput(mode_cmd)90 if s is not 0:91 Logger.error( 'mode path err cmd[%s]'%(mode_cmd))92 Logger.error( 'the out put [%d %s]'%(s,o))93 return None94 touch_cmd = 'touch --reference=%s %s%s'%(path, path, self.postfix)95 s,o = commands.getstatusoutput(touch_cmd)96 if s is not 0:97 Logger.error( 'touch path err cmd[%s]'%(touch_cmd))98 Logger.error( 'the out put [%d %s]'%(s,o))99 return None100 os.unlink(path)101 return True102if __name__ == '__main__':103 crypt_m = FsCryptManger('/root/test/ulteo-ovd-sources-3.0.4','nfstest')104 print crypt_m.safe_dir105 time_str = '%d %d'%(time.localtime().tm_min,time.localtime().tm_sec)106 print time_str107 #crypt_m.encrypt_dir()108 crypt_m.decrypt_dir()109 time_str = '%d %d'%(time.localtime().tm_min,time.localtime().tm_sec)110 print time_str111 #if crypt_m.decrypt_file('/home/nfs/test/xrdp/configure.ac.asc') is not None:112 # print 'ok'113 #crypt_m.traverse_path()114 #for filepath in crypt_m.safe_files:...

Full Screen

Full Screen

dataset_splitter.py

Source:dataset_splitter.py Github

copy

Full Screen

1from src.processing import metrics_extractor2RANDOM_STATE = 73TARGET_LABEL = "IS_WEAK"4__train_data = None5__train_labels = None6__test_data = None7__test_labels = None8def __init_train_test_sets():9 """10 Inits the training and test sets.11 """12 metrics = metrics_extractor.load_features()13 # Select rows14 weak_files = metrics.loc[metrics[TARGET_LABEL] == 1].sample(frac=1, random_state=RANDOM_STATE)15 safe_files = metrics.loc[metrics[TARGET_LABEL] == 0].sample(n=weak_files.shape[0], random_state=RANDOM_STATE)16 # Reset indexes17 weak_files.reset_index(drop=True, inplace=True)18 safe_files.reset_index(drop=True, inplace=True)19 # Compute the 80% of each subset20 number_of_rows = int(weak_files.shape[0] * 0.8)21 # Compute train and test sets for weak files22 weak_files_train_data = weak_files.loc[0:number_of_rows, :].drop(TARGET_LABEL, axis=1)23 weak_files_train_labels = weak_files.loc[0:number_of_rows, TARGET_LABEL]24 weak_files_test_data = weak_files.loc[number_of_rows:, :].drop(TARGET_LABEL, axis=1)25 weak_files_test_labels = weak_files.loc[number_of_rows:, TARGET_LABEL]26 # Compute train and test sets for safe files27 safe_files_train_data = safe_files.loc[0:number_of_rows:, :].drop(TARGET_LABEL, axis=1)28 safe_files_train_labels = safe_files.loc[0:number_of_rows, TARGET_LABEL]29 safe_files_test_data = safe_files.loc[number_of_rows:, :].drop(TARGET_LABEL, axis=1)30 safe_files_test_labels = safe_files.loc[number_of_rows:, TARGET_LABEL]31 global __train_data32 global __test_data33 global __train_labels34 global __test_labels35 # Compute global train and test sets36 __train_data = weak_files_train_data.append(safe_files_train_data)37 __test_data = weak_files_test_data.append(safe_files_test_data)38 __train_labels = weak_files_train_labels.append(safe_files_train_labels)39 __test_labels = weak_files_test_labels.append(safe_files_test_labels)40 # Shuffle the datasets and reset the indexes41 __train_data = __train_data.sample(frac=1, random_state=RANDOM_STATE).reset_index(drop=True)42 __test_data = __test_data.sample(frac=1, random_state=RANDOM_STATE).reset_index(drop=True)43 __train_labels = __train_labels.sample(frac=1, random_state=RANDOM_STATE).reset_index(drop=True)...

Full Screen

Full Screen

SaveFiles.py

Source:SaveFiles.py Github

copy

Full Screen

1from os import rename,path2import uuid3from config.conf import ALLOWED_EXTENSIONS,IMAGE_PATH,VIDEO_PATH4def safeFile(file):5 left_index = file.lfind('.')6 right_index = file.rfind('.')7 if(left_index == right_index):8 for extention in ALLOWED_EXTENSIONS:9 if(file.endswith(extention)):10 new_file_name = uuid.uuid4()11 return new_file_name12 return False13 return False14def File(file):15 file_extension = path.splitext(file)[1]16 if(not safeFile(file.filename)):17 return False18 new_file = safeFile(file.filename)+'.'+file_extension19 rename(file.filename,new_file)20 if(file.filename.endswith('.mp4')):21 file.save(path.join(VIDEO_PATH, file.filename)) 22 file.save(path.join(IMAGE_PATH, file.filename)) 23def Files(files) -> bool:24 safe_files = []25 for file in files:26 file_extension = path.splitext(file)[1]27 if (not safeFile(file.filename)):28 return False29 new_file = safeFile(file.filename)+'.'+file_extension30 rename(file.filename,new_file)31 safe_files.append(new_file)32 for file in safe_files:33 if(file.filename.endswith('.mp4')):34 file.save(path.join(VIDEO_PATH, file.filename)) 35 file.save(path.join(IMAGE_PATH, file.filename)) ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful