Пример #1
0
    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_video_basename(self, id_robot, id_agent, id_episode):
        pattern = DirectoryStructure.pattern_video

        if not id_episode:
            id_episode = "alleps"
        if not id_agent:
            id_agent = "allags"

        filename = os.path.join(self.root, DirectoryStructure.DIR_VIDEOS,
                               substitute(pattern,
                                          id_robot=id_robot,
                                          id_agent=id_agent,
                                          id_episode=id_episode))
        warn_good_filename(filename)
        return filename
    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