Write a SysFS attribute/action

    CLI example:
     .. code-block:: bash

        salt '*' sysfs.write devices/system/cpu/cpu0/cpufreq/scaling_governor 'performance'
435495
def write(key, value):
    '''
    
    '''
    try:
        key = target(key)
        log.trace('Writing %s to %s', value, key)
        with salt.utils.files.fopen(key, 'w') as twriter:
            twriter.write(
                salt.utils.stringutils.to_str('{0}\n'.format(value))
            )
            return True
    except Exception:
        return False
819815
def write(self, fptr):
        
        self._validate(writing=True)
        length = 16 + 4 * len(self.compatibility_list)
        fptr.write(struct.pack('>I4s', length, b'ftyp'))
        fptr.write(self.brand.encode())
        fptr.write(struct.pack('>I', self.minor_version))

        for item in self.compatibility_list:
            fptr.write(item.encode())
209339
def write_ioc_to_file(self, output_dir=None, force=False):
        
        return write_ioc(self.root, output_dir, force=force)
96599
def write_proc_sh(self):
        
        print("Writing proc.sh")
        context = {
            'tmp': '/tmp',
            'home': '/app',
            'settings': '/settings.yaml',
            'envsh': '/env.sh',
            'port': self.config.port,
            'cmd': self.get_cmd(),
        }
        sh_path = os.path.join(get_container_path(self.config), 'proc.sh')
        rendered = get_template('proc.sh') % context
        with open(sh_path, 'w') as f:
            f.write(rendered)
        st = os.stat(sh_path)
        os.chmod(
            sh_path, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
1103160
def write(self, text, fg='black', bg='white'):
        ''''''
        if isinstance(text, str):
            sys.stdout.write(text)
        else:
            sys.stdout.write(str(text))
        sys.stdout.flush()
964053
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, tag, columns, limit):
    """"""

    manager = SoftLayer.HardwareManager(env.client)
    servers = manager.list_hardware(hostname=hostname,
                                    domain=domain,
                                    cpus=cpu,
                                    memory=memory,
                                    datacenter=datacenter,
                                    nic_speed=network,
                                    tags=tag,
                                    mask="mask(SoftLayer_Hardware_Server)[%s]" % columns.mask(),
                                    limit=limit)

    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for server in servers:
        table.add_row([value or formatting.blank()
                       for value in columns.row(server)])

    env.fout(table)
1293424
def __writepid(self, pid):
        
        import tempfile
        d = tempfile.gettempdir()
        name = os.path.join(d, "hoverpy.%i.%i"%(self._proxyPort, self._adminPort))
        with open(name, 'w') as f:
            f.write(str(pid))
            logging.debug("writing to %s"%name)
958753
def _write_conf(conf, path=MAIN_CF):
    '''
    
    '''
    with salt.utils.files.fopen(path, 'w') as fh_:
        for line in conf:
            line = salt.utils.stringutils.to_str(line)
            if isinstance(line, dict):
                fh_.write(' '.join(line))
            else:
                fh_.write(line)
            fh_.write('\n')
429871
def write(self, fn=None, sorted=False, wait=0):
        
        config = ConfigParser(interpolation=None)
        if sorted==True: keys.sort()
        for key in self.__dict__.get('ordered_keys') or self.keys():
            config[key] = {}
            ks = self[key].keys()
            if sorted==True: ks.sort()
            for k in ks:
                if type(self[key][k])==list and self.__join_list__ is not None:
                    config[key][k] = self.__join_list__.join([v for v in self[key][k] if v!=''])
                else:
                    config[key][k] = str(self[key][k])
        fn = fn or self.__dict__.get('__filename__')
        # use advisory locking on this file
        i = 0
        while os.path.exists(fn+'.LOCK') and i < wait:
            i += 1
            time.sleep(1)
        if os.path.exists(fn+'.LOCK'):
            raise FileExistsError(fn + ' is locked for writing')
        else:
            with open(fn+'.LOCK', 'w') as lf:
                lf.write(time.strftime("%Y-%m-%d %H:%M:%S %Z"))
            with open(fn, 'w') as f:
                config.write(f)
            os.remove(fn+'.LOCK')
298478
def write(self, memory, addr, data, flush_queue=False):
        """"""
        wreq = _WriteRequest(memory, addr, data, self.cf)
        if memory.id not in self._write_requests:
            self._write_requests[memory.id] = []

        # Workaround until we secure the uplink and change messages for
        # mems to non-blocking
        self._write_requests_lock.acquire()
        if flush_queue:
            self._write_requests[memory.id] = self._write_requests[
                memory.id][:1]
        self._write_requests[memory.id].insert(len(self._write_requests), wreq)
        if len(self._write_requests[memory.id]) == 1:
            wreq.start()
        self._write_requests_lock.release()

        return True
1208453
def write(self, out):
        """"""
        out.write_string(self.cpu, len(self.cpu))
        out.write_string(self.os, len(self.os))
884388
def _swclock_to_hwclock():
    '''
    
    '''
    res = __salt__['cmd.run_all'](['hwclock', '--systohc'], python_shell=False)
    if res['retcode'] != 0:
        msg = 'hwclock failed to set hardware clock from software clock: {0}'.format(res['stderr'])
        raise CommandExecutionError(msg)
    return True
1066909
def write(self, s):
        
        try:
            self._write_lock.acquire()
            self.handle.sendall(s)
        except socket.timeout:
            self._connect()
        except socket.error:
            raise IOError
        finally:
            self._write_lock.release()
828019
def cpu():
    '''
    
    '''

    # Test data
    max_primes = [500, 1000, 2500, 5000]

    # Initializing the test variables
    test_command = 'sysbench --test=cpu --cpu-max-prime={0} run'
    result = None
    ret_val = {}

    # Test beings!
    for primes in max_primes:
        key = 'Prime numbers limit: {0}'.format(primes)
        run_command = test_command.format(primes)
        result = __salt__['cmd.run'](run_command)
        ret_val[key] = _parser(result)

    return ret_val
802270
function write (type, port) {
  return createAction(WRITE, writeCommand)

  /**
   * function that returns a write actions
   * @private
   * @param  {string} command
   * @param  {object} opts    move object
   * @return {object}         write action object
   */
  function writeCommand (command, opts) {
    return {
      type: type,
      command: command,
      opts: opts,
      port: port
    }
  }
}
1114394
def get_cpu_info(self) -> str:
        ''''''
        output, _ = self._execute(
            '-s', self.device_sn, 'shell', 'cat', '/proc/cpuinfo')
        return output
239262
def _sysfs_parse(path, base_attr=None, stats=False, config=False, internals=False, options=False):
    '''
    
    '''
    result = {}

    # ---------------- Parse through the interfaces list ----------------
    intfs = __salt__['sysfs.interfaces'](path)

    # Actions, we ignore
    del intfs['w']

    # -------- Sorting hat --------
    binkeys = []
    if internals:
        binkeys.extend(['inter_ro', 'inter_rw'])
    if config:
        binkeys.append('config')
    if stats:
        binkeys.append('stats')

    bintf = {}
    for key in binkeys:
        bintf[key] = []

    for intf in intfs['r']:
        if intf.startswith('internal'):
            key = 'inter_ro'
        elif 'stats' in intf:
            key = 'stats'
        else:
            # What to do with these???
            # I'll utilize 'inter_ro' as 'misc' as well
            key = 'inter_ro'

        if key in bintf:
            bintf[key].append(intf)

    for intf in intfs['rw']:
        if intf.startswith('internal'):
            key = 'inter_rw'
        else:
            key = 'config'

        if key in bintf:
            bintf[key].append(intf)

    if base_attr is not None:
        for intf in bintf:
            bintf[intf] = [sintf for sintf in bintf[intf] if sintf not in base_attr]
        bintf['base'] = base_attr

    mods = {
        'stats': ['internal/bset_tree_stats', 'writeback_rate_debug', 'metadata_written', 'nbuckets', 'written',
                  'average_key_size', 'btree_cache_size'],
    }

    for modt, modlist in mods.items():
        found = []
        if modt not in bintf:
            continue
        for mod in modlist:
            for intflist in bintf.values():
                if mod in intflist:
                    found.append(mod)
                    intflist.remove(mod)
        bintf[modt] += found

    # -------- Fetch SysFS vals --------
    bintflist = [intf for iflist in bintf.values() for intf in iflist]
    result.update(__salt__['sysfs.read'](bintflist, path))

    # -------- Parse through well known string lists --------
    for strlist in ('writeback_rate_debug', 'internal/bset_tree_stats', 'priority_stats'):
        if strlist in result:
            listres = {}
            for line in result[strlist].split('\n'):
                key, val = line.split(':', 1)
                val = val.strip()
                try:
                    val = int(val)
                except Exception:
                    try:
                        val = float(val)
                    except Exception:
                        pass
                listres[key.strip()] = val
            result[strlist] = listres

    # -------- Parse through selection lists --------
    if not options:
        for sellist in ('cache_mode', 'cache_replacement_policy', 'errors'):
            if sellist in result:
                result[sellist] = re.search(r'\[(.+)\]', result[sellist]).groups()[0]

    # -------- Parse through well known bools --------
    for boolkey in ('running', 'writeback_running', 'congested'):
        if boolkey in result:
            result[boolkey] = bool(result[boolkey])

    # -------- Recategorize results --------
    bresult = {}
    for iftype, intflist in bintf.items():
        ifres = {}
        for intf in intflist:
            if intf in result:
                ifres[intf] = result.pop(intf)
        if ifres:
            bresult[iftype] = ifres

    return bresult