How to use set_filename method in Slash

Best Python code snippet using slash

file_certs.py

Source:file_certs.py Github

copy

Full Screen

...48 """ Certification file of format:49 certname1: user1=level1, user2=level2, ...50 certname2: user1=level1, user2=level2, ...51 """52 def set_filename(self, file):53 self.f = file54 try:55 p, f = path.split(file)56 makedirs(p)57 except:58 pass59 def __read_dict(self):60 self.info = {}61 try:62 f = open(self.f,"rw")63 except:64 return65 for l in f.readlines():66 l = l.strip()67 if len(l) == 0:68 continue69 [ftype, certs] = l.split(":")70 ftype = unsafe_str(ftype)71 certs = certs.split(",")72 for cert in certs:73 [fname, flevel] = cert.split("=")74 l = unsafe_str(flevel)75 fn = unsafe_str(fname)76 DictCertifications.add(self, ftype, fn, l)77 f.close()78 def __write_dict(self):79 f = open(self.f,"w")80 for key in DictCertifications.cert_keys(self):81 l = safe_str(key)+": "82 certs = []83 dict = DictCertifications.certs_by_type(self, key)84 for c in dict.keys():85 certs.append(safe_str(c)+"="+safe_str(dict[c]))86 l += join(certs, ", ") + "\n"87 f.write(l)88 f.close()89 def cert_keys(self):90 self.__read_dict()91 return DictCertifications.cert_keys(self)92 def certs_by_type(self, type):93 self.__read_dict()94 return DictCertifications.certs_by_type(self, type)95 def cert_type_keys(self, type, name):96 self.__read_dict()97 return DictCertifications.certs_type_keys(self, type, name)98 def add(self, type, name, level):99 self.__read_dict()100 DictCertifications.add(self, type, name, level)101 self.__write_dict()102 def remove(self, type, name):103 self.__read_dict()104 DictCertifications.remove(self, type, name, level)105 self.__write_dict()106 def cert_level(self, type, name):107 self.__read_dict()108 return DictCertifications.cert_level(self, type, name)109class FileProfile(Profile):110 def __init__(self, name, cert_class):111 Profile.__init__(self, name, cert_class)112 self._certs_by_subj.set_filename("users/"+str(name)+"/certs.subj")113 self._certs_by_issuer.set_filename("users/"+str(name)+"/certs.issuer")114 # overload meaning of FileCertifications here to store user-profile.115 self.info = FileCertifications()116 self.info.set_filename("users/"+str(name)+"/profile")117 def set_filename(self, file):118 self.info.set_filename(file)119 def info_keys(self):120 return self.info.cert_keys()121 def infos_by_type(self, type):122 return self.info.certs_by_type(type)123 def info_type_keys(self, type, name):124 return self.info.certs_type_keys(type, name)125 def add(self, type, name, level):126 self.info.add(type, name, level)127 def remove(self, type, name):128 self.info.remove(type, name, level)129 def info_index(self, type, name):130 return self.info.cert_level(type, name)131class FileCertInfo(CertInfo):132 """ This is probably some of the clumsiest code ever written.133 overload DictCertification - because it's been a really134 good, lazy weekend, to store an unordered list (seeds),135 an ordered list (levels) etc.136 yuck. please, someone shoot me or do a better job,137 _esp._ for example code.138 """139 def cert_seeds(self, idxn):140 d = FileCertifications()141 d.set_filename("certs/"+str(idxn))142 # clumsy usage of a dictionary as an unordered list. argh.143 d = d.certs_by_type("seeds")144 return d.keys()145 def cert_levels(self, idxn):146 d = FileCertifications()147 d.set_filename("certs/"+str(idxn))148 dict = d.certs_by_type("levels")149 # clumsy usage of a dictionary into an ordered list. argh.150 keys = dict.keys()151 l = [None] * len(keys)152 for idx in keys:153 l[int(idx)] = dict[idx]154 return l155 def cert_level_default(self, idxn):156 d = FileCertifications()157 d.set_filename("certs/"+str(idxn))158 [d] = d.certs_by_type("default level").keys()159 return d160 def cert_level_min(self, idxn):161 d = FileCertifications()162 d.set_filename("certs/"+str(idxn))163 [d] = d.certs_by_type("min level").keys()164 return d165 def cert_tmetric_type(self, idxn):166 d = FileCertifications()167 d.set_filename("certs/"+str(idxn))168 [d] = d.certs_by_type("type").keys()169 return d170 def add_cert_seed(self, idxn, seed):171 d = FileCertifications()172 d.set_filename("certs/"+str(idxn))173 # clumsy usage of a dictionary as an unordered list. argh.174 return d.add("seeds", seed, None)175 def add_cert_level(self, idxn, level, index):176 d = FileCertifications()177 d.set_filename("certs/"+str(idxn))178 # clumsy usage of a dictionary as an index-ordered list. argh.179 return d.add("levels", index, level)180 def set_cert_level_default(self, idxn, dflt_level):181 d = FileCertifications()182 d.set_filename("certs/"+str(idxn))183 return d.add("default level", dflt_level, None)184 def set_cert_level_min(self, idxn, min_level):185 d = FileCertifications()186 d.set_filename("certs/"+str(idxn))187 return d.add("min level", min_level, None)188 def set_cert_tmetric_type(self, idxn, type):189 d = FileCertifications()190 d.set_filename("certs/"+str(idxn))191 return d.add("type", type, None)192def test():193 from profile import Profiles194 from tm_calc import TrustMetric195 from pprint import pprint196 f = FileCertInfo()197 f.add_cert_seed('like', '55')198 f.add_cert_seed('like', 'luke')199 f.add_cert_level('like', 'none', 0)200 f.add_cert_level('like', "don't care", 1)201 f.add_cert_level('like', 'good', 2)202 f.add_cert_level('like', 'best', 3)203 f.set_cert_level_default('like', "don't care")204 f.set_cert_level_min('like', 'none')...

Full Screen

Full Screen

conversion_utils.py

Source:conversion_utils.py Github

copy

Full Screen

1import os2from .readBin import get_active_tetrode, get_active_eeg3def get_set_header(set_filename):4 with open(set_filename, 'r+') as f:5 header = ''6 for line in f:7 header += line8 if 'sw_version' in line:9 break10 return header11def is_egf_active(set_filename):12 active_egf_str = 'saveEGF'13 with open(set_filename) as f:14 for line in f:15 if active_egf_str in line:16 _, egf_status = line.split(' ')17 if int(egf_status) == 1:18 return True19 return False20def is_converted(set_filename):21 """This method will check if the file has been converted already"""22 # find active tetrodes23 active_tetrodes = get_active_tetrode(set_filename)24 # check if each of these active .N files have been created yet25 set_basename = os.path.basename(os.path.splitext(set_filename)[0])26 set_directory = os.path.dirname(set_filename)27 all_tetrodes_written = True28 all_eeg_written = True29 all_egf_written = True30 pos_written = True31 if not os.path.exists(os.path.join(set_directory, '%s.pos' % (set_basename))):32 pos_written = False33 for tetrode in active_tetrodes:34 if not os.path.exists(os.path.join(set_directory, '%s.%d' % (set_basename, int(tetrode)))):35 all_tetrodes_written = False36 break37 active_eeg = get_active_eeg(set_filename)38 for eeg in active_eeg.keys():39 if eeg == 1:40 if not os.path.exists(os.path.join(set_directory, '%s.eeg' % (set_basename))):41 all_eeg_written = False42 break43 elif not os.path.exists(os.path.join(set_directory, '%s.eeg%d' % (set_basename, int(eeg)))):44 all_eeg_written = False45 break46 if is_egf_active(set_filename):47 for egf in active_eeg.keys():48 if egf == 1:49 if not os.path.exists(os.path.join(set_directory, '%s.egf' % (set_basename))):50 all_egf_written = False51 break52 elif not os.path.exists(os.path.join(set_directory, '%s.egf%d' % (set_basename, int(egf)))):53 all_egf_written = False54 break55 return all_tetrodes_written and all_eeg_written and all_egf_written and pos_written56def has_files(set_filename):57 """This method will check if all the necessary files exist"""58 # the only thing it needs is a .bin file59 tint_basename = os.path.basename(os.path.splitext(set_filename)[0])60 directory = os.path.dirname(set_filename)61 if os.path.exists(os.path.join(directory, '%s.bin' % tint_basename)):62 return True...

Full Screen

Full Screen

load_data.py

Source:load_data.py Github

copy

Full Screen

1image_size = 28 # Pixel width and height.2pixel_depth = 255.0 # Number of levels per pixel.3def load_letter(folder, min_num_images):4 """Load the data for a single letter label."""5 image_files = os.listdir(folder)6 dataset = np.ndarray(shape=(len(image_files), image_size, image_size),7 dtype=np.float32)8 image_index = 09 print(folder)10 for image in os.listdir(folder):11 image_file = os.path.join(folder, image)12 try:13 image_data = (ndimage.imread(image_file).astype(float) - 14 pixel_depth / 2) / pixel_depth15 if image_data.shape != (image_size, image_size):16 raise Exception('Unexpected image shape: %s' % str(image_data.shape))17 dataset[image_index, :, :] = image_data18 image_index += 119 except IOError as e:20 print('Could not read:', image_file, ':', e, '- it\'s ok, skipping.')21 22 num_images = image_index23 dataset = dataset[0:num_images, :, :]24 if num_images < min_num_images:25 raise Exception('Many fewer images than expected: %d < %d' %26 (num_images, min_num_images))27 28 print('Full dataset tensor:', dataset.shape)29 print('Mean:', np.mean(dataset))30 print('Standard deviation:', np.std(dataset))31 return dataset32 33def maybe_pickle(data_folders, min_num_images_per_class, force=False):34 dataset_names = []35 for folder in data_folders:36 set_filename = folder + '.pickle'37 dataset_names.append(set_filename)38 if os.path.exists(set_filename) and not force:39 # You may override by setting force=True.40 print('%s already present - Skipping pickling.' % set_filename)41 else:42 print('Pickling %s.' % set_filename)43 dataset = load_letter(folder, min_num_images_per_class)44 try:45 with open(set_filename, 'wb') as f:46 pickle.dump(dataset, f, pickle.HIGHEST_PROTOCOL)47 except Exception as e:48 print('Unable to save data to', set_filename, ':', e)49 ...

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 Slash 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