Exemplo n.º 1
0
def update_template(filename, entry, key, val):
    template = yu.read_yaml(filename)
    entry = _string_to_val(entry)
    val = _string_to_val(val)
    template[entry][template[entry].keys()[0]][key] = val

    with open(filename, 'w') as stream:
        yu.dump_yaml(template, stream)
Exemplo n.º 2
0
def _set_system_params():
    # look in conda environment to see which version is being used
    savu_path = sys.modules['savu'].__path__[0]
    sys_files = os.path.join(os.path.dirname(savu_path), 'system_files')
    subdirs = os.listdir(sys_files)
    sys_folder = 'dls' if len(subdirs) > 1 else subdirs[0]
    fname = 'system_parameters.yml'
    sys_file = os.path.join(sys_files, sys_folder, fname)
    return yaml.read_yaml(sys_file)
Exemplo n.º 3
0
def _set_system_params():
    # look in conda environment to see which version is being used
    savu_path = sys.modules['savu'].__path__[0]
    sys_files = os.path.join(
            os.path.dirname(savu_path), 'system_files')
    subdirs = os.listdir(sys_files)
    sys_folder = 'dls' if len(subdirs) > 1 else subdirs[0]
    fname = 'system_parameters.yml'
    sys_file = os.path.join(sys_files, sys_folder, fname)
    return yaml.read_yaml(sys_file)
Exemplo n.º 4
0
 def _check_for_inheritance(self, ddict, inherit):
     if 'inherit' in ddict.keys():
         idict = ddict['inherit']
         idict = idict if isinstance(idict, list) else [idict]
         for i in idict:
             if i != 'None':
                 new_dict = yu.read_yaml(i)
                 inherit.update(new_dict)
                 inherit = self._check_for_inheritance(new_dict, inherit)
     self._update(inherit, ddict)
     return inherit
Exemplo n.º 5
0
    def setup(self, template=False, metadata=True):
        #  Read YAML file
        yfile = self.parameters['yaml_file']
        data_dict = yu.read_yaml(self._get_yaml_file(yfile))
        data_dict = self._check_for_inheritance(data_dict, {})
        self._check_for_imports(data_dict)
        data_dict.pop('inherit', None)
        data_dict.pop('import', None)
        if template:
            return data_dict

        data_dict = self._add_template_updates(data_dict)
        self._set_entries(data_dict)
Exemplo n.º 6
0
    def setup(self, template=False, metadata=True):
        #  Read YAML file
        yfile = self.parameters['yaml_file']
        data_dict = yu.read_yaml(self._get_yaml_file(yfile))
        data_dict = self._check_for_inheritance(data_dict, {})
        self._check_for_imports(data_dict)
        data_dict.pop('inherit', None)
        data_dict.pop('import', None)
        if template:
            return data_dict

        data_dict = self._add_template_updates(data_dict)
        self._set_entries(data_dict)
 def __set_system_params(self):
     sys_file = self.meta_data.get('system_params')
     import sys
     if sys_file is None:
         # look in conda environment to see which version is being used
         savu_path = sys.modules['savu'].__path__[0]
         sys_files = os.path.join(
                 os.path.dirname(savu_path), 'system_files')
         subdirs = os.listdir(sys_files)
         sys_folder = 'dls' if len(subdirs) > 1 else subdirs[0]
         fname = 'system_parameters.yml'
         sys_file = os.path.join(sys_files, sys_folder, fname)
     logging.info('Using the system parameters file: %s', sys_file)
     self.meta_data.set('system_params', yaml.read_yaml(sys_file))
Exemplo n.º 8
0
 def _check_for_inheritance(self, ddict, inherit, override=False):
     if 'inherit' in ddict.keys():
         idict = ddict['inherit']
         idict = idict if isinstance(idict, list) else [idict]
         for i in idict:
             if i != 'None':
                 new_dict = yu.read_yaml(self._get_yaml_file(i))
                 new_dict, isoverride = \
                     self.__override(inherit, new_dict, override)
                 inherit.update(new_dict)
                 inherit = self._check_for_inheritance(
                         new_dict, inherit, override=isoverride)
     self._update(inherit, ddict)
     return inherit
Exemplo n.º 9
0
 def __set_system_params(self):
     sys_file = self.meta_data.get('system_params')
     import sys
     if sys_file is None:
         # look in conda environment to see which version is being used
         savu_path = sys.modules['savu'].__path__[0]
         sys_files = os.path.join(os.path.dirname(savu_path),
                                  'system_files')
         subdirs = os.listdir(sys_files)
         sys_folder = 'dls' if len(subdirs) > 1 else subdirs[0]
         fname = 'system_parameters.yml'
         sys_file = os.path.join(sys_files, sys_folder, fname)
     logging.info('Using the system parameters file: %s', sys_file)
     self.meta_data.set('system_params', yaml.read_yaml(sys_file))
Exemplo n.º 10
0
    def setup(self, template=False):
        #  Read YAML file
        if self.parameters['yaml_file'] is None:
            raise Exception('Please pass a yaml file to the yaml loader.')

        data_dict = yu.read_yaml(self.parameters['yaml_file'])
        data_dict = self._check_for_inheritance(data_dict, {})
        self._check_for_imports(data_dict)
        data_dict.pop('inherit', None)
        data_dict.pop('import', None)
        if template:
            return data_dict

        data_dict = self._add_template_updates(data_dict)
        self._set_entries(data_dict)
Exemplo n.º 11
0
    def update_process_list(self, template):
        tdict = yu.read_yaml(template)

        for plugin_no, entry in tdict.iteritems():
            plugin = entry.keys()[0]
            for key, value in entry.values()[0].iteritems():
                depth = self.dict_depth(value)
                if depth == 1:
                    self._set_param_for_template_loader_plugin(
                            plugin_no, key, value)
                elif depth == 0:
                    if plugin_no == 'all':
                        self._set_param_for_all_instances_of_a_plugin(
                                plugin, key, value)
                    else:
                        data = self._get_plugin_data_dict(str(plugin_no))
                        data[key] = value
                else:
                    raise Exception("Template key not recognised.")
Exemplo n.º 12
0
    def update_process_list(self, template):
        tdict = yu.read_yaml(template)
        del tdict['process_list']

        for plugin_no, entry in tdict.iteritems():
            plugin = entry.keys()[0]
            for key, value in entry.values()[0].iteritems():
                depth = self.dict_depth(value)
                if depth == 1:
                    self._set_param_for_template_loader_plugin(
                            plugin_no, key, value)
                elif depth == 0:
                    if plugin_no == 'all':
                        self._set_param_for_all_instances_of_a_plugin(
                                plugin, key, value)
                    else:
                        data = self._get_plugin_data_dict(str(plugin_no))
                        data[key] = value
                else:
                    raise Exception("Template key not recognised.")