def dump_data(self, name, data, ext='data', subdir=None):
        if not isinstance(data, list):
            data = [data]

        basedir, filename = self._compute_filenames(name, ext, subdir)
        utils.mkdirp(basedir)
        with open(filename, "w") as f:
            for l in data:
                f.write(str(l) + '\n')
Exemplo n.º 2
0
def create_output_dir(args, domain_name, instance_name):
    """ Determine what the output dir should be and create it. Return the output dir path. """
    translation_dir = args.output
    if not translation_dir:
        if args.tag is None:
            import time
            args.tag = time.strftime("%y%m%d")
        translation_dir = os.path.abspath(os.path.join(*[FS_WORKSPACE, args.tag, domain_name, instance_name]))
    utils.mkdirp(translation_dir)
    return translation_dir
Exemplo n.º 3
0
def move_files(instance, domain, target_dir, use_vanilla):
    """ Moves the domain and instance description files plus additional data files to the translation directory """
    base_dir = os.path.dirname(instance)
    definition_dir = target_dir + '/definition'
    data_dir = target_dir + '/data'

    # Copy the domain and instance file to the subfolder "definition" on the destination dir
    utils.mkdirp(definition_dir)
    shutil.copy(instance, definition_dir)
    shutil.copy(domain, definition_dir)

    is_external_defined = os.path.isfile(base_dir + '/external.hxx')

    if is_external_defined and use_vanilla:
        raise RuntimeError(
            "An external definitions file was found at '{}', but the runner script determined"
            " that no external files were needed. Something is wrong.".format(
                base_dir))

    if not use_vanilla:
        # The ad-hoc external definitions file - if it does not exist, we use the default.
        if is_external_defined:
            shutil.copy(base_dir + '/external.hxx', target_dir)
        if os.path.isfile(base_dir + '/external.cxx'
                          ):  # We also copy a possible cxx implementation file
            shutil.copy(base_dir + '/external.cxx', target_dir)
        if os.path.isfile(base_dir + '/translating.hxx'
                          ):  # We also copy a possible cxx implementation file
            shutil.copy(base_dir + '/translating.hxx', target_dir)
        if os.path.isfile(base_dir + '/epistemic_checker.cxx'
                          ):  # We also copy a possible cxx implementation file
            shutil.copy(base_dir + '/epistemic_checker.cxx', target_dir)
        if os.path.isfile(base_dir + '/epistemic_checker.hxx'
                          ):  # We also copy a possible cxx implementation file
            shutil.copy(base_dir + '/epistemic_checker.hxx', target_dir)
        if os.path.isfile(base_dir + '/domain.hxx'
                          ):  # We also copy a possible cxx implementation file
            shutil.copy(base_dir + '/domain.hxx', target_dir)

        else:
            default = tplManager.get('external_default.hxx').substitute(
            )  # No substitutions for the default template
            utils.save_file(target_dir + '/external.hxx', default)

    # Copy, if they exist, all data files
    origin_data_dir = base_dir + '/data'
    if os.path.isdir(origin_data_dir):
        for filename in glob.glob(os.path.join(origin_data_dir, '*')):
            if os.path.isfile(filename):
                shutil.copy(filename, data_dir)
            else:
                dst = os.path.join(data_dir, os.path.basename(filename))
                if os.path.exists(dst):
                    shutil.rmtree(dst)
                shutil.copytree(filename, dst)
Exemplo n.º 4
0
def run_planner(instance, driver, options, asp=False):
    """ Creates an anonymous runner for a certain instance and planner configuration """
    tag = "test_{}".format(timestamp)
    args = [
        '--debug', '--run', '--tag', tag, '--instance', instance, '--driver',
        driver
    ]
    name_args = [tag, driver, os.path.basename(instance)]

    if options is not None:
        args += ['--options', options]
        name_args += [options]

    if asp:
        args += ['--asp']
        name_args += ['asp']

    exp_name = '.'.join(name_args).replace("=", '_').replace(',', '.')
    output = os.path.join(FS_WORKSPACE, exp_name)
    utils.mkdirp(output)
    args += ['--output', output]

    exit_code = runner.main(args)
    assert exit_code == 0