def __enter__(self): self._delete() with open(self._pid_file, 'w') as out: pid = os.getpid() log(self).debug('writting pid {0} to {1}'.format( pid, self._pid_file)) out.write(str(pid))
def brightness(self, value): """ Change current brightness. """ log(self).info('changing brightness value to {0}'.format(value)) value = min(max(value, 0.0), 1.0) self.sys_b.change(int(float(self.sys_mb) * float(value)))
def change(self, val): """ Change system value. """ log(self).debug('changing {0} value to {1}'.format(self.path, val)) with open(self.path, 'w') as file: file.write("{0}\n".format(val))
def apply(self, cmd): log(self).debug('applying command: {0}'.format(cmd)) match = Command.PTN_SET.match(cmd) if match: val = float(match['val']) / 100.0 self.backlight.brightness = val return match = Command.PTN_INC.match(cmd) if match: val = float(match['val']) / 100.0 self.backlight.brightness = self.backlight.brightness + val return match = Command.PTN_DEC.match(cmd) if match: val = float(match['val']) / 100.0 self.backlight.brightness = self.backlight.brightness - val return
def __enter__(self): if os.path.exists(self._path): os.remove(self._path) log(self).debug('binding socket: {0}'.format(self._path)) self._sock.bind(self._path) try: grnam = grp.getgrnam(self._chgrp) except KeyError as err: raise RuntimeError(' '.join([ "group {0} was not found,", "can't create socket file: ", "{0}" ]).format(self._chgrp, err)) gid = grnam.gr_gid os.chown(self._path, uid=-1, gid=gid) log(self).debug('changed group owner to {0}={1}'.format( gid, self._chgrp)) os.chmod(self._path, 0o660) log(self).debug('changed socket mode to 660') return self._sock
def _delete(self): if os.path.exists(self._pid_file): log(self).debug('removing pidfile: {0}'.format(self._pid_file)) os.remove(self._pid_file)
def __enter__(self): log(self).debug('connecting to socket: {0}'.format(self._path)) self._sock.connect(self._path) return self._sock
def call(self, cmd): """ Call remote command. """ log(self).info('calling remote command: {0}'.format(cmd)) self._sock.send(cmd.encode('utf-8'))