Ejemplo n.º 1
0
    def write_files(self, data, source_path, dest_dir):
        """writes files for the simulation


        Returns:
            PKDict: structure of files written (debugging only)
        """
        class _G(_Generate):
            def _abspath(basename):
                return source_path.new(basename=basename)

            def _input_file(self, model_name, field, filename):
                return filename

            def _lattice_filename(self, value):
                return value

        g = _G(data)
        g.sim()
        v = g.jinja_env
        r = PKDict(
            commands=dest_dir.join(source_path.basename),
            lattice=self._lattice_path(dest_dir, data),
        )
        pkio.write_text(r.commands, v.commands)
        pkio.write_text(r.lattice, v.rpn_variables + v.lattice)
        for f in set(
                LatticeUtil(data, _SCHEMA).iterate_models(
                    lattice.InputFileIterator(_SIM_DATA)).result, ):
            f = _SIM_DATA.lib_file_name_without_type(f)
            dest_dir.join(f).mksymlinkto(source_path.new(basename=f),
                                         absolute=False)
        f = g.filename_map
        r.output_files = [f[k] for k in f.keys_in_order]
        return r
Ejemplo n.º 2
0
def test_file_iterator():
    from sirepo.template import lattice
    from sirepo.template.lattice import LatticeUtil
    from pykern.pkunit import pkeq
    data = _find_example('bunchComp - fourDipoleCSR')
    v = LatticeUtil(data, _elegant()._SCHEMA).iterate_models(
        lattice.InputFileIterator(_elegant()._SIM_DATA)).result
    pkeq(v, ['WAKE-inputfile.knsl45.liwake.sdds'])
Ejemplo n.º 3
0
 def _lib_file_basenames(cls, data):
     res = LatticeUtil(data, cls.schema()).iterate_models(
         lattice.InputFileIterator(cls)).result
     if data.models.bunchFile.sourceFile:
         res.append(
             cls.lib_file_name_with_model_field(
                 'bunchFile', 'sourceFile',
                 data.models.bunchFile.sourceFile))
     return res
Ejemplo n.º 4
0
 def _write_input_files(self, data, source_path, dest_dir):
     for f in set(
             LatticeUtil(data, self._schema).iterate_models(
                 lattice.InputFileIterator(
                     self._sim_data, update_filenames=False), ).result, ):
         f = self._sim_data.lib_file_name_without_type(f)
         try:
             dest_dir.join(f).mksymlinkto(source_path.new(basename=f),
                                          absolute=False)
         except py.error.EEXIST:
             pass
Ejemplo n.º 5
0
def _get_file_list_from_model(model, code_name):
    # Get input and lattice if exists
    file_list = [
        model['_SimData__source'].basename,
    ]
    try:
        lattice_file = model._SimData__adapter._lattice_path('', model)
        file_list.append(lattice_file)
    except AttributeError:
        pass

    # Get all supporting files
    _sim_data, _, _schema = sirepo.sim_data.template_globals(code_name)
    files = lattice.LatticeUtil(model, _schema).iterate_models(
        lattice.InputFileIterator(_sim_data, update_filenames=False), ).result
    file_list.extend(files)

    return file_list
Ejemplo n.º 6
0
 def _lib_file_basenames(cls, data):
     return LatticeUtil(data, cls.schema()).iterate_models(
         lattice.InputFileIterator(cls)).result