write to a file with variable substitution
341054
def write(self, file, text, subvars={}, trim_leading_lf=True):
        ''''''
        file.write(self.substitute(text, subvars=subvars, trim_leading_lf=trim_leading_lf))
331729
def substitute_variables(command, level, name, value, target=None, **kwargs):
    """"""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {
        '${level}': str(level),
        '${target}': str(target),
        '${name}': '"' + str(name) + '"',
        '${value}': str(value),
        '${limit_value}': str(rule_value),
    }

    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)

    return result
722395
def write_file(self, filename, **kwargs):
        
        with zopen(filename, "wt") as f:
            f.write(self.get_string(**kwargs))
129628
def write_file(filename, string):
    """"""
    import sys
    #ugly fix, hopefully we can find a better one
    if sys.version_info[0] >= 3:
        with open(filename, 'w', encoding="utf-8") as f:
            f.write(string)
    else:
        with open(filename, 'w') as f:
            f.write(string.encode("utf-8"))
825115
def write(self, file_path, template, context={}, preserve=False, force=False):
        
        if not file_path or not template:
            click.secho('source or target missing for document')
            return
        if not context:
            context = self.context
        error = False
        try:
            self._write(file_path, template, context, preserve, force)
        except TemplateSyntaxError as exc:
            message = '{0}:{1}: error: {2}'.format(exc.filename, exc.lineno, exc.message)
            click.secho(message, fg='red', err=True)
            error = True
        except TemplateNotFound as exc:
            message = '{0}: error: Template not found'.format(exc.name)
            click.secho(message, fg='red', err=True)
            error = True
        except TemplateError as exc:
            # Just return with an error, the generic template_error_handler takes care of printing it
            error = True

        if error and Generator.strict:
            sys.exit(1)
267769
def write_vars(self,fh):
    
    if self.__macros.keys() or self.__opts.keys() or self.__args:
      fh.write( 'VARS ' + self.__name )
    for k in self.__macros.keys():
      fh.write( ' ' + str(k) + '="' + str(self.__macros[k]) + '"' )
    for k in self.__opts.keys():
      fh.write( ' ' + str(k) + '="' + str(self.__opts[k]) + '"' )
    if self.__args:
      for i in range(self.__arg_index):
        fh.write( ' macroargument' + str(i) + '="' + self.__args[i] + '"' )
    fh.write( '\n' )
482044
def _write_int(fname, data, append=True):
    """"""
    # pylint: disable=W0705
    data_ex = pexdoc.exh.addex(ValueError, "There is no data to save to file")
    fos_ex = pexdoc.exh.addex(
        OSError, "File *[fname]* could not be created: *[reason]*"
    )
    data_ex((len(data) == 0) or ((len(data) == 1) and (len(data[0]) == 0)))
    try:
        pmisc.make_dir(fname)
        mode = "w" if append is False else "a"
        if sys.hexversion < 0x03000000:  # pragma: no cover, no branch
            with open(fname, mode) as file_handle:
                csv.writer(file_handle, delimiter=",").writerows(data)
        else:  # pragma: no cover
            with open(fname, mode, newline="") as file_handle:
                csv.writer(file_handle, delimiter=",").writerows(data)
    except (IOError, OSError) as eobj:
        fos_ex(True, _MF("fname", fname, "reason", eobj.strerror))
72831
def write(self, session, directory, name, maskMap):
        

        # Assemble Path to file
        name_split = name.split('.')
        name = name_split[0]

        # Default extension
        extension = ''

        if len(name_split) >= 2:
            extension = name_split[-1]

        # Run name preprocessor method if present
        try:
            name = self._namePreprocessor(name)
        except:
            'DO NOTHING'

        if extension == '':
            filename = '{0}.{1}'.format(name, self.fileExtension)
        else:
            filename = '{0}.{1}'.format(name, extension)

        filePath = os.path.join(directory, filename)

        with open(filePath, 'w') as openFile:
            # Write Lines
            self._write(session=session,
                        openFile=openFile,
                        maskMap=maskMap)
875945
def instance_write(attr, value)
      setter = :"#{name}_#{attr}="
      responds = instance.respond_to?(setter)
      self.instance_variable_set("@_#{setter.to_s.chop}", value)
      instance.send(setter, value) if responds || attr.to_s == "file_name"
    end
571307
def WriteRow(stream, values):
  ""
  stream.write(','.join([EncodeForCSV(val) for val in values]))
  stream.write('\n')
155847
def _write(self, str_buf):
    """"""
    self._filehandle.write(str_buf)
    self._buf_size += len(str_buf)
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)
254433
async function write(filename, object, options = undefined) {
  const {encoding, flag, ...opts} = normalizeOptions(options)

  if (!isNumber(filename)) {
    filename = toAbsolute(base, filename)

    opts.filename = filename
  }

  await fs.writeFile(filename, yaml.dump(object, opts), {encoding, flag})
}
1245068
def _writeXput(self, session, directory, fileCards,
                   name=None, replaceParamFile=None):
        
        for card in self.projectCards:
            if (card.name in fileCards) and self._noneOrNumValue(card.value) \
                    and fileCards[card.name]:
                fileIO = fileCards[card.name]
                filename = card.value.strip('"')

                # Check for replacement variables
                if '[' in filename or ']' in filename:
                    log.info('The file for project card {0} cannot be '
                             'written, because the path has been replaced '
                             'with replacement variable {1}.'.format(card.name, filename))
                    return

                # Determine new filename
                filename = self._replaceNewFilename(filename=filename,
                                                    name=name)

                # Invoke write method on each file
                self._invokeWrite(fileIO=fileIO,
                                  session=session,
                                  directory=directory,
                                  filename=filename,
                                  replaceParamFile=replaceParamFile)
871064
def write_string_to_file(path, string, make_parents=False, backup_suffix=BACKUP_SUFFIX, encoding="utf8"):
  
  with atomic_output_file(path, make_parents=make_parents, backup_suffix=backup_suffix) as tmp_path:
    with codecs.open(tmp_path, "wb", encoding=encoding) as f:
      f.write(string)
285284
def write_to_textfile(path, registry):
    """"""
    tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
    with open(tmppath, 'wb') as f:
        f.write(generate_latest(registry))
    # rename(2) is atomic.
    os.rename(tmppath, path)
1179741
private void writeVars(Definition def, Writer out, int indent) throws IOException
   {
      writeWithIndent(out, indent, "/** JNDI name */\n");
      writeWithIndent(out, indent,
            "private static final String JNDI_NAME = \"java:/eis/" + def.getDefaultValue() + "\";\n\n");

      writeWithIndent(out, indent, "/** MBeanServer instance */\n");
      writeWithIndent(out, indent, "private MBeanServer mbeanServer;\n\n");

      writeWithIndent(out, indent, "/** Object Name */\n");
      writeWithIndent(out, indent, "private String objectName;\n\n");

      writeWithIndent(out, indent, "/** The actual ObjectName instance */\n");
      writeWithIndent(out, indent, "private ObjectName on;\n\n");

      writeWithIndent(out, indent, "/** Registered */\n");
      writeWithIndent(out, indent, "private boolean registered;\n\n");
   }