def _exec(self, arguments): """Execute the given git command and return the output""" command = [self.command] command.extend(arguments) return process.check_output(command).strip()
def _exec(self, arguments, is_cloning=False): """Execute the given hg command and return the output""" command = [self.command] command.extend(arguments) command.extend(['--cwd', os.getcwd() if is_cloning else self.path]) return process.check_output(command).strip()
def idle_time(): # osx idle time, in seconds ioreg = check_output(["ioreg", "-c", "IOHIDSystem"], debug_log_output=False) for line in ioreg.splitlines(): # | | "HIDIdleTime" = 63319375 if line.strip(" |").startswith('"HIDIdleTime"'): return round(int(line.split("=")[-1]) / 10**9) return 0
def pid_of(): # returns pid of running launch agent, None if not installed, 0 if # installed but not running for line in check_output(["launchctl", "list"], debug_log_output=False).splitlines(): line = line.split("\t") if line[-1] == NAME and line[0] != "-": return int(line[0]) return None
def service(name, cmd, do_raise=True): """Convenience wrapper to handle service interactions """ try: kwargs = {"shell": False, "stderr": process.PIPE} r = process.check_output(["service", name, cmd], **kwargs) except process.CalledProcessError as e: r = e.returncode LOGGER.debug("Service cmd failed: %s %s" % (name, cmd), exc_info=True) LOGGER.debug("Service output: %s" % e.output) if do_raise: raise return r
def _query_vgs(self, option, pv=None): cmd = ["lvm", "vgs", "--noheadings", "-o", option] if pv: cmd.append(pv) out = process.check_output(cmd).strip() vgs = None # If not VGs are found, just simulate an empty list of VGs if "No volume groups found" in out: vgs = [] else: vgs = [x.strip() for x in out.split("\n")] return vgs
def by_label(label): """Determines whether a filesystem with a given label is present on this system """ fs = None try: Filesystem._flush() with open(os.devnull, 'wb') as DEVNULL: device = process.check_output( ["blkid", "-c", "/dev/null", "-L", label], stderr=DEVNULL).strip() fs = Filesystem(device) except process.CalledProcessError as e: LOGGER.debug("Failed to resolve disks: %s" % e.cmd, exc_info=True) return fs
def _find_device(self): try: return process.check_output( ["findmnt", "-o", "SOURCE", "-n", self.path]).strip() except: raise RuntimeError("Couldn't find mount device for %s" % self.path)
def mountpoints(self): targets = process.check_output( ["findmnt", "-o", "target", "-n", self.device]).split("\n") return [Mount(t.strip()) for t in targets]
def _tokens(self): tokens = process.check_output(["blkid", "-o", "export", self.device]) return parse_varfile(tokens)
def _call(self, cmd): return process.check_output(cmd)