Expand variables in policy data.

        Updates the policy data in-place.
342438
def expand_variables(self, variables):
        
        # format string values returns a copy
        updated = utils.format_string_values(self.data, **variables)

        # Several keys should only be expanded at runtime, perserve them.
        if 'member-role' in updated.get('mode', {}):
            updated['mode']['member-role'] = self.data['mode']['member-role']

        # Update ourselves in place
        self.data = updated
        # Reload filters/actions using updated data, we keep a reference
        # for some compatiblity preservation work.
        m = self.resource_manager
        self.resource_manager = self.load_resource_manager()

        # XXX: Compatiblity hack
        # Preserve notify action subject lines which support
        # embedded jinja2 as a passthrough to the mailer.
        for old_a, new_a in zip(m.actions, self.resource_manager.actions):
            if old_a.type == 'notify' and 'subject' in old_a.data:
                new_a.data['subject'] = old_a.data['subject']
474667
def _expand_rec_to_vars(var_items, rec_items, input_order, items_by_key, parallel):
    
    num_items = var_items
    var_items = list(var_items)[0]
    if rec_items:
        for rec_key in (k for (k, t) in input_order.items() if t == "record"):
            rec_vals = items_by_key[rec_key]
            if len(rec_vals) == 1 and var_items > 1:
                items_by_key[rec_key] = rec_vals * var_items
            else:
                assert var_items == len(rec_vals), (var_items, rec_vals)
    return items_by_key, num_items
1342068
def update(self, infos):
        """"""
        for info_in in infos:
            if isinstance(info_in, LearningGene):
                if random.random() < 0.10:
                    self.mutate(info_in)
                else:
                    self.replicate(info_in)
994567
def set(self, variables: Dict[str, str]):
        
        current_variables = self.get()
        difference = DictDiffer(variables, current_variables)

        removed_keys = difference.removed()
        self.remove(removed_keys)

        changed_keys = difference.added() | difference.changed()
        changed = {key: variables[key] for key in changed_keys}
        self.add(changed, overwrite=True)
863647
def add_policy(self, name, policy_type, cooldown, change=None,
            is_percent=False, desired_capacity=None, args=None):
        
        return self.manager.add_policy(self, name, policy_type, cooldown,
                change=change, is_percent=is_percent,
                desired_capacity=desired_capacity, args=args)
1027669
def add_var(self, var):
        
        if var.name in [v.name for v in self.vars]:
            logger.error("Variable set named '%s' already exists." % var.name)
            return

        var.i1 = self.var_N
        var.iN = self.var_N + var.N - 1
        self.vars.append(var)
206426
def add_variables(vars)
      # Store all the variables in the model
      # Most of the work will be done when we add the constraints
      vars.each do |var|
        var.model = self
        var.index = @variables.count
        @variables << var
      end
    end
498936
def _extend_data(self, datapoint, new_data):
        
        if new_data:
            try:
                self.data[datapoint].extend(new_data)
            except KeyError:
                self.data[datapoint] = new_data
953847
def expandConfigPaths (config, prefix=None, datetime=None, pathvars=None, parameter_key='', *keys):
    
    if len(keys) == 0:
        keys = PATH_KEYS

    for name, value in config.items():
        if name in keys and type(name) is str:
            expanded = util.expandPath(value, prefix)
            cleaned = replaceVariables(expanded, datetime=datetime, pathvars=pathvars)

            for p in cleaned:
                if not os.path.exists(p):
                    msg = "Config parameter {}.{} specifies nonexistent path {}".format(parameter_key, name, p)
                    log.warn(msg)

            config[name] = cleaned[0] if len(cleaned) == 1 else cleaned

        elif type(value) is dict:
            param_key = name if parameter_key == '' else parameter_key + '.' + name
            expandConfigPaths(value, prefix, datetime, pathvars, param_key, *keys)
586552
def _expand_space(self):
        

        ## --- Expand the config space
        self._expand_config_space()

        ## --- Expand the space
        self.space_expanded = []
        for variable in self.space:
            self.space_expanded += variable.expand()
43049
def add_default_values_of_scoped_variables_to_scoped_data(self):
        
        for key, scoped_var in self.scoped_variables.items():
            self.scoped_data[str(scoped_var.data_port_id) + self.state_id] = \
                ScopedData(scoped_var.name, scoped_var.default_value, scoped_var.data_type, self.state_id,
                           ScopedVariable, parent=self)
1154506
def add_policy_statements(self, statements):
        
        if isinstance(statements, Statement):
            statements = [statements]
        self._policy_statements.extend(statements)
160960
def update_policy(self, scaling_group, policy, name=None, policy_type=None,
            cooldown=None, change=None, is_percent=False,
            desired_capacity=None, args=None):
        
        return self._manager.update_policy(scaling_group, policy, name=name,
                policy_type=policy_type, cooldown=cooldown, change=change,
                is_percent=is_percent, desired_capacity=desired_capacity,
                args=args)
1323595
def store_policy(self, pol_id, policy):
        
        if pol_id not in self.policies:
            self.policies[pol_id] = policy
            self.policy_cnt += 1
132288
def _merge_variables(new, cur):
    
    new_added = set([])
    out = []
    for cur_var in cur:
        updated = False
        for new_var in new:
            if get_base_id(new_var["id"]) == get_base_id(cur_var["id"]):
                out.append(new_var)
                new_added.add(new_var["id"])
                updated = True
                break
        if not updated:
            out.append(cur_var)
    for new_var in new:
        if new_var["id"] not in new_added:
            out.append(new_var)
    return out
192932
public String expand(Map<String, Object> vars) throws VariableExpansionException
    {
        this.values = vars;
        return expand();
    }
1118225
function expandVariables(service, processNumber) {
  // first the simple case of env, which is always an object.
  service.env = _.reduce(service.env, function(result, v, k) {
    var value = typeof v === 'string' ? v.replace(/%i/g, processNumber) : v;
    return (result[k] = value, result)
  }, {});

  // next, the more annoying usecase of args which can be
  // an array on an object.
  if (_.isArray(service.args)) {
    service.args = _.map(service.args, function(arg) {
      return typeof arg === 'string' ? arg.replace(/%i/g, processNumber) : arg;
    });
  } else {
    service.args = _.reduce(service.args, function(result, v, k) {
      var value = typeof v === 'string' ? v.replace(/%i/g, processNumber) : v;
      return (result[k] = value, result)
    }, {});
  }
}