def view_with_less(content, color=True): """Send `content` through less.""" import subprocess cmd = ['less'] if color: cmd.append('-r') less_proc = subprocess.Popen(cmd, stdin=subprocess.PIPE) less_proc.stdin.write(maybe_encode(content)) less_proc.stdin.close() less_proc.wait()
def write(self, content): """Write content to the fh. Re-open if necessary.""" if self._fh == NullFileHandle: try: self._fh = open(self.name, 'ab') except IOError as e: log.error("Failed to open %s: %s", self.name, e) return self.last_accessed = time.time() self._fh.write(maybe_encode(content)) self.manager.update(self)
def hash_digest(content): return hashlib.sha1(maybe_encode(content)).hexdigest()