If replacement operation, perform 'configure replace' for the entire config.

        If merge operation, perform copy <file> running-config.
515187
def commit_config(self):
        
        # Always generate a rollback config on commit
        self._gen_rollback_cfg()

        if self.config_replace:
            # Replace operation
            filename = self.candidate_cfg
            cfg_file = self._gen_full_path(filename)
            if not self._check_file_exists(cfg_file):
                raise ReplaceConfigException("Candidate config file does not exist")
            if self.auto_rollback_on_error:
                cmd = 'configure replace {} force revert trigger error'.format(cfg_file)
            else:
                cmd = 'configure replace {} force'.format(cfg_file)
            output = self._commit_hostname_handler(cmd)
            if ('original configuration has been successfully restored' in output) or \
               ('error' in output.lower()) or \
               ('failed' in output.lower()):
                msg = "Candidate config could not be applied\n{}".format(output)
                raise ReplaceConfigException(msg)
            elif '%Please turn config archive on' in output:
                msg = "napalm-ios replace() requires Cisco 'archive' feature to be enabled."
                raise ReplaceConfigException(msg)
        else:
            # Merge operation
            filename = self.merge_cfg
            cfg_file = self._gen_full_path(filename)
            if not self._check_file_exists(cfg_file):
                raise MergeConfigException("Merge source config file does not exist")
            cmd = 'copy {} running-config'.format(cfg_file)
            self._disable_confirm()
            output = self._commit_hostname_handler(cmd)
            self._enable_confirm()
            if 'Invalid input detected' in output:
                self.rollback()
                err_header = "Configuration merge failed; automatic rollback attempted"
                merge_error = "{0}:\n{1}".format(err_header, output)
                raise MergeConfigException(merge_error)

        # Save config to startup (both replace and merge)
        output += self.device.send_command_expect("write mem")
966857
def _copy_source_to_target(self):
        
        if self.source and self.target:
            for k, v in self.source.items('config'):
                # always have source override target.
                self.target.set_input(k, v)
122518
def load_replace_candidate(self, filename=None, config=None):
        """"""
        self.config_replace = True
        self._load_candidate(filename, config, True)
148598
def copyFile(input, output, replace=None):
    """"""

    _found = findFile(output)
    if not _found or (_found and replace):
        shutil.copy2(input, output)
1011492
def _replace_config(s, env):
    """"""
    m = re.match(r"\[(.*?)\](.*)", s)
    if m:
        section, option = m.groups()
        expanded = env.config.get(section, option)
        return '\n'.join([expand_factor_conditions(e, env)
                          for e in expanded.split("\n")])
    else:
        raise ValueError()
796496
def replace(self):
        
        doc_dict = self.doc_dict.copy()
        for k, v in doc_dict.items():
            if '{' and '}' in v:
                self.doc_dict[k] = v.format(**doc_dict)
232962
def copy_config(config, mutable_config_keys=MUTABLE_CONFIG_KEYS):
    

    cloned_config = copy(config)
    # Apply ``copy`` function to mutable config values
    for key in mutable_config_keys:
        cloned_config[key] = copy(config[key])
    return cloned_config
1237761
static void copy(final Configuration conf, final Arguments args
      ) throws IOException {
    DistCopier copier = getCopier(conf, args);
    
    if (copier != null) {
      try {
        JobClient client = copier.getJobClient();
        RunningJob job = client.submitJob(copier.getJobConf());
        try {
          if (!client.monitorAndPrintJob(copier.getJobConf(), job)) {
            throw new IOException("Job failed!");
          }
        } catch (InterruptedException ie) {
          Thread.currentThread().interrupt();
        }
        copier.finalizeCopiedFiles();
      } finally {
        copier.cleanupJob();
      }
    }
  }
1170859
def run_configurations(callback, sections_reader):
    """"""
    base = dict(OPTIONS)
    sections = sections_reader()
    if sections is None:
        logger.info("Configuration not found in .ini files. "
                    "Running with default settings")
        recompile()
    elif sections == []:
        logger.info("Configuration does not match current runtime. "
                    "Exiting")
    results = []
    for section, options in sections:
        OPTIONS.clear()
        OPTIONS.update(base)
        OPTIONS.update(options)
        logger.debug("Running configuration from section \"%s\". OPTIONS: %r",
                     section, OPTIONS)
        results.append(callback())
    return results
432319
def copy(self, new_path, replace=False):
        """"""
        if replace or not get_file(new_path).exists():
            self.key.copy(self.key.bucket, new_path)
            return True
        return False
734235
def _merge_config(self, config_override):
        
        if not isinstance(config_override, dict):
            raise TypeError("config override must be a dict")

        def recursion(config_value, override_value):
            for key, value in override_value.items():
                if key in config_value:
                    if isinstance(value, dict) and isinstance(config_value[key], dict):
                        recursion(config_value[key], value)
                    else:
                        config_value[key] = value
                else:
                    config_value[key] = value

        for key, value in config_override.items():
            if key in self._data:
                recursion(self._data[key], value)
            else:
                self._data[key] = value
785
function replaceInFile (filename, regex, replacement) {
    let contents = fs.readFileSync (filename, 'utf8')
    const parts = contents.split (regex)
    const newContents = parts[0] + replacement + parts[1]
    fs.truncateSync (filename)
    fs.writeFileSync (filename, newContents)
}
610052
def run_configure(self, mandatory=True):
        
        if not has_file(self.working_dir, 'configure'):
            if mandatory:
                raise FileNotFoundError(
                    "Could not find a configure script for execution.")
            else:
                return
        try:
            prog = RunningProgram(self, 'configure')
            prog.expect_exit_status(0)
        except Exception:
            if mandatory:
                raise
429010
function replace(file, options) {
  var contents = file.contents;
  var copied = 0;

  var processed = translate(options, contents, copied, file.path);

  var files = [];
  for (var lang in processed) {
    var params = {};
    params.ext = path.extname(file.path).substr(1);
    params.name = path.basename(file.path, path.extname(file.path));
    params.path = file.path.substring(file.base.length, file.path.lastIndexOf(path.sep));
    params.lang = lang;

    var filePath = options.filename;
    for (var param in params) {
      filePath = filePath.replace('${' + param + '}', params[param]);
    }
    filePath = path.join(file.base,filePath);

    var newFile = new gutil.File({
      base: file.base,
      cwd: file.cwd,
      path: filePath,
      contents: new Buffer(processed[lang], 'utf8')
    });
    files.push(newFile);
  }

	return files;
}
128628
def copy_and_replace(file_in, file_out, mapping, **kwargs):
    '''
    
    '''
    separator = '@@'
    if 'separator' in kwargs:
        separator = kwargs['separator']
    file_in = open(file_in, 'r')
    file_out = open(file_out, 'w')
    s = file_in.read()
    for find, replace in mapping:
        find = separator + find + separator
        print(u'Replacing {0} with {1}'.format(find, replace))
        s = s.replace(find, replace)
    file_out.write(s)
1075882
public static Configuration copyConfiguration(final Configuration original) {
		Configuration copy = new MapConfiguration(new HashMap<String, Object>());

		for (Iterator<?> i = original.getKeys(); i.hasNext();) {
			String key = (String) i.next();
			Object value = original.getProperty(key);

			if (value instanceof List) {
				value = new ArrayList((List) value);
			}

			copy.setProperty(key, value);
		}

		return copy;
	}
1081927
def replace(self, child, replacement):
        """"""
        for i in range(len(self.chunks)):
            if self.chunks[i] == child:
                self.chunks[i] = replacement