def get_report_robot_filename_rd(self, id_robot):
     pattern = DirectoryStructure.pattern_report_robot
     filename = os.path.join(self.root, DirectoryStructure.DIR_REPORTS,
                            substitute(pattern, id_robot=id_robot))
     mkdirs_thread_safe(os.path.dirname(filename))
     rd = os.path.join(self.root, DirectoryStructure.DIR_REPORTS,
                         DirectoryStructure.pattern_report_rd)
     return filename, rd
 def get_report_filename(self, id_agent, id_robot, id_state, phase):
     pattern = DirectoryStructure.pattern_report
     filename = os.path.join(self.root, DirectoryStructure.DIR_REPORTS,
                            substitute(pattern,
                                       phase=phase,
                                       id_agent=id_agent,
                                       id_robot=id_robot,
                                       id_state=id_state))
     mkdirs_thread_safe(os.path.dirname(filename))
     return filename
 def get_report_res_dir(self, id_agent, id_robot, id_state, phase):
     ''' Returns the directory for the resources of the report. '''
     pattern = DirectoryStructure.pattern_report_rd
     dirname = os.path.join(self.root, DirectoryStructure.DIR_REPORTS,
                            substitute(pattern,
                                       phase=phase,
                                       id_agent=id_agent,
                                       id_robot=id_robot,
                                       id_state=id_state))
     mkdirs_thread_safe(dirname)
     assert os.path.exists(dirname)
     return dirname
    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
Esempio n. 6
0
def dp(arguments):
    usage = substitute(usage_pattern, commands_list=commands_list,
                       cmd=MAIN_CMD_NAME)

    parser = MyOptionParser(prog=MAIN_CMD_NAME, usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--contracts", default=False, action='store_true',
                      help="Activate PyContracts (disabled by default)")

    parser.add_option("--profile", default=False, action='store_true',
                      help="Use Python profiler")

    parser.add_option("-d", "--directory", default="default:.",
                      help="Configuration directory")

    (options, args) = parser.parse_args(arguments)

    if not options.contracts:
        logger.warning('PyContracts disabled for speed. Use --contracts to activate.')
        contracts.disable_all()

    if not args:
        msg = ('Please supply a command.\nAvailable commands:\n%s' % commands_list)
        raise UserError(msg)

    cmd = args[0]
    cmd_args = args[1:]

    if not cmd in Storage.commands:
        msg = ('Unknown command %r. Available: %s.' % 
               (cmd, ", ".join(Storage.commands.keys())))
        raise UserError(msg)

    confdir = options.directory
    config = DiffeoplanConfigMaster()
    config.load()
    if confdir is not None:
        config.load(confdir)
    
    set_current_config(config)

    function = Storage.commands[cmd]
    usage = function.short_usage 
    parser = CmdOptionParser(prog='%s %s' % (MAIN_CMD_NAME, cmd), usage=usage,
                             args=cmd_args)
    parser.enable_interspersed_args()
    
    def go():
        return function(config, parser)

    if not options.profile:
        go()
    else:
        logger.warning('Note: the profiler does not work when using '
                       'parallel execution. (use "make" instead of "parmake").')
        import cProfile
        cProfile.runctx('go()', globals(), locals(), 'dp_prof')
        import pstats
        p = pstats.Stats('dp_prof')
        n = 30
        p.sort_stats('cumulative').print_stats(n)
        p.sort_stats('time').print_stats(n)
Esempio n. 7
0
def dp(arguments):
    usage = substitute(usage_pattern,
                       commands_list=commands_list,
                       cmd=MAIN_CMD_NAME)

    parser = MyOptionParser(prog=MAIN_CMD_NAME, usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--contracts",
                      default=False,
                      action='store_true',
                      help="Activate PyContracts (disabled by default)")

    parser.add_option("--profile",
                      default=False,
                      action='store_true',
                      help="Use Python profiler")

    parser.add_option("-d",
                      "--directory",
                      default="default:.",
                      help="Configuration directory")

    (options, args) = parser.parse_args(arguments)

    if not options.contracts:
        logger.warning(
            'PyContracts disabled for speed. Use --contracts to activate.')
        contracts.disable_all()

    if not args:
        msg = ('Please supply a command.\nAvailable commands:\n%s' %
               commands_list)
        raise UserError(msg)

    cmd = args[0]
    cmd_args = args[1:]

    if not cmd in Storage.commands:
        msg = ('Unknown command %r. Available: %s.' %
               (cmd, ", ".join(Storage.commands.keys())))
        raise UserError(msg)

    confdir = options.directory
    config = DiffeoplanConfigMaster()
    config.load()
    if confdir is not None:
        config.load(confdir)

    set_current_config(config)

    function = Storage.commands[cmd]
    usage = function.short_usage
    parser = CmdOptionParser(prog='%s %s' % (MAIN_CMD_NAME, cmd),
                             usage=usage,
                             args=cmd_args)
    parser.enable_interspersed_args()

    def go():
        return function(config, parser)

    if not options.profile:
        go()
    else:
        logger.warning(
            'Note: the profiler does not work when using '
            'parallel execution. (use "make" instead of "parmake").')
        import cProfile
        cProfile.runctx('go()', globals(), locals(), 'dp_prof')
        import pstats
        p = pstats.Stats('dp_prof')
        n = 30
        p.sort_stats('cumulative').print_stats(n)
        p.sort_stats('time').print_stats(n)
Esempio n. 8
0
def boot_olympics_manager(arguments):
    usage = substitute(usage_pattern, commands_list=commands_list,
                       cmd='boot_olympics_manager')

    parser = OptionParser(prog='boot_olympics_manager', usage=usage)
    parser.disable_interspersed_args()
    parser.add_option("-d", dest='boot_root', default=None,
                      help='Root directory with logs, config, etc. [%default]')

    parser.add_option("-c", dest='extra_conf_dirs', action="append", default=[],
                      help='Adds an extra config dir.')

    parser.add_option("-l", dest='extra_log_dirs', action="append", default=[],
                      help='Adds an extra directory storing logs.')

    parser.add_option("--contracts", default=False, action='store_true',
                      help="Activate PyContracts (disabled by default)")

    parser.add_option("--seterr", dest='seterr', default="warn",
                      help="Sets np.seterr. "
                      "Possible values: ignore, warn, raise, print, log")

    parser.add_option("--profile", default=False, action='store_true',
                      help="Use Python profiler")

    available = LogsFormat.formats.keys()
    parser.add_option("--logformat", dest='log_format',
                      default=BootOlympicsConstants.DEFAULT_LOG_FORMAT,
                      help="Choose format for writing logs in %s. [%%default]"
                        % str(available))

    (options, args) = parser.parse_args(arguments)

    if not args:
        msg = ('Please supply command. Available: %s'
               % ", ".join(Storage.commands.keys()))
        raise UserError(msg)

    cmd = args[0]
    cmd_options = args[1:]

    if not cmd in Storage.commands:
        msg = ('Unknown command %r. Available: %s.' % 
               (cmd, ", ".join(Storage.commands.keys())))
        raise UserError(msg)

    np.seterr(all=options.seterr)
    # underflow is very common in all libraries (e.g. matplotlib)
    np.seterr(under='warn')

    if not options.contracts:
        contracts.disable_all()

    if options.boot_root is None:
        options.boot_root = DirectoryStructure.DEFAULT_ROOT
        logger.info('Using %r as default root directory '
                    '(use -d <dir> to change)' % options.boot_root)


    data_central = DataCentral(options.boot_root)
    
    GlobalConfig.global_load_dir('default')  # need skins
    for dirname in options.extra_conf_dirs:
        GlobalConfig.global_load_dir(dirname)
    
    dir_structure = data_central.get_dir_structure() 
    dir_structure.set_log_format(options.log_format)
    for dirname in options.extra_log_dirs:
        dir_structure.add_log_directory(dirname)

    def go():
        return Storage.commands[cmd](data_central, cmd_options)

    if not options.profile:
        go()
    else:
        logger.warning('Note: the profiler does not work when using '
                       'parallel execution. (use "make" instead of "parmake").')
        import cProfile
        cProfile.runctx('go()', globals(), locals(), 'bom_prof')
        import pstats
        p = pstats.Stats('bom_prof')
        p.sort_stats('cumulative').print_stats(30)
        p.sort_stats('time').print_stats(30)