def start_store(self, dirname=None): # Make record dir if not dirname: dirname = time.time() directory = os.path.join(DATA_DIR, dirname) self.log.info( '[MAIN THREAD] Starting local storage in {}'.format(directory)) if os.path.isdir(directory): shutil.rmtree(directory) os.makedirs(directory) self.log.debug('[MAIN THREAD] Made local record dir') # Open files for types in self.targets: for instance in self.targets[types]: filename = os.path.join(directory, instance) self.files[instance] = open(filename, 'w') self.log.debug('[MAIN THREAD] Opened {}'.format(filename)) # Write headers for key in self.files: if key == 'system': print >> self.files[key], list_to_csv(self.headers['system']) self.log.debug('[MAIN THREAD] wrote {} in file {}'.format( list_to_csv(self.headers['system']), key)) else: print >> self.files[key], list_to_csv(self.headers['process']) self.log.debug('[MAIN THREAD] wrote {} in file {}'.format( list_to_csv(self.headers['process']), key)) # Ask start storing and return store file paths self.local_store = True self.log.debug('[MAIN THREAD] End start local') return [os.path.join(directory, instance) for instance in self.files]
def start_store(self, dirname = None): # Make record dir if not dirname: dirname = time.time() directory = os.path.join(LOCAL_DATA_DIR, dirname) self.log.info('[MAIN THREAD] Starting local storage in {}'.format(directory)) if os.path.isdir(directory): shutil.rmtree(directory) os.makedirs(directory) self.log.debug('[MAIN THREAD] Made local record dir') # Open files for types in self.targets: for instance in self.targets[types]: filename = os.path.join(directory, instance) self.files[instance] = open(filename, 'w') self.log.debug('[MAIN THREAD] Opened {}'.format(filename)) # Write headers for key in self.files: if key == 'system': print >> self.files[key], list_to_csv(self.headers['system']) self.log.debug('[MAIN THREAD] wrote {} in file {}'.format(list_to_csv(self.headers['system']), key)) else: print >> self.files[key], list_to_csv(self.headers['process']) self.log.debug('[MAIN THREAD] wrote {} in file {}'.format(list_to_csv(self.headers['process']), key)) # Ask start storing self.local_store = True self.log.debug('[MAIN THREAD] End start local') return [os.path.join(directory, instance) for instance in self.files]
def process_store(self, dico): for target in self.files: try: if target == 'system': res = [dico[target][data_field] for data_field in self.headers['system']] else: res = [dico[target][data_field] for data_field in self.headers['process']] except AttributeError: res = range(len(dico)) print >> self.files[target], list_to_csv(res) self.log.debug('[PROCESS THREAD] Stored {}'.format(list_to_csv(res)))
def process_store(self, dico): for target in self.files: try: if target == 'system': res = [ dico[target][data_field] for data_field in self.headers['system'] ] else: res = [ dico[target][data_field] for data_field in self.headers['process'] ] except AttributeError: res = range(len(dico)) print >> self.files[target], list_to_csv(res) self.log.debug('[PROCESS THREAD] Stored {}'.format( list_to_csv(res)))