'Prepare the job to run by creating the working directory and the
config files.'

def prepare(self, compute_environment=None):

    self.sa_session.expunge_all()
    if (not os.path.exists(self.working_directory)):
        os.mkdir(self.working_directory)
    job = self._load_job()
    def get_special():
        special = self.sa_session.query(model.JobExportHistoryArchive).filter_by(job=job).first()
        if (not special):
            special = self.sa_session.query(model.GenomeIndexToolData).filter_by(job=job).first()
        return special
    tool_evaluator = self._get_tool_evaluator(job)
    compute_environment = (compute_environment or self.default_compute_environment(job))
    tool_evaluator.set_compute_environment(compute_environment, get_special=get_special)
    self.sa_session.flush()
    (self.command_line, self.extra_filenames, self.environment_variables) = tool_evaluator.build()
    self.galaxy_lib_dir
    self.dependency_shell_commands = self.tool.build_dependency_shell_commands(job_directory=self.working_directory)
    job.command_line = unicodify(self.command_line)
    job.dependencies = self.tool.dependencies
    self.sa_session.add(job)
    self.sa_session.flush()
    self.param_dict = tool_evaluator.param_dict
    version_string_cmd_raw = self.tool.version_string_cmd
    if version_string_cmd_raw:
        version_command_template = string.Template(version_string_cmd_raw)
        version_string_cmd = version_command_template.safe_substitute({'__tool_directory__': compute_environment.tool_directory()})
        self.write_version_cmd = ('%s    >    %s    2>&1' % (version_string_cmd, compute_environment.version_path()))
    else:
        self.write_version_cmd = None
    return self.extra_filenames
