def __init__(self, filename, id_stream, boot_spec): warn_good_filename(filename) warn_good_identifier(id_stream) assert isinstance(boot_spec, BootSpec) self.filename = filename # XXX: check that we are not given the same filename self.tmp_filename = filename + '.active' self.hf = tables.openFile(self.tmp_filename, 'w') # so can we use PyTables' natural naming scheme id_stream = id_stream.replace('-', '_') self.id_stream = id_stream self.table = None self.boot_spec = boot_spec
def get_log_filename(self, base_dir, id_agent, id_robot, id_stream, logs_format=None, add_unique=True): warn_good_identifier(id_stream) if logs_format is None: logs_format = self.log_format check_contained(logs_format, LogsFormat.formats, 'format') pattern = DirectoryStructure.pattern_logdir dirname = os.path.join(base_dir, substitute(pattern, id_agent=id_agent, id_robot=id_robot, id_stream=id_stream)) mkdirs_thread_safe(dirname) assert os.path.exists(dirname) # Add a unique string to the file if add_unique: tmpfile = tempfile.NamedTemporaryFile( suffix='.%s.active' % logs_format, prefix='%s-' % id_stream, dir=dirname, delete=False) tmpfile.write('To be used') tmp_filename = tmpfile.name warn_good_filename(tmp_filename) filename = tmp_filename.replace('.active', '') tmpfile.close() else: filename = os.path.join(dirname, '%s.%s' % (id_stream, logs_format)) # logger.debug('Writing on %r' % friendly_path(filename)) warn_good_filename(filename) return filename