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()
Example #2
0
    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 _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()
Example #4
0
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
Example #5
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
Example #6
0
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
Example #7
0
    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
Example #8
0
    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
Example #9
0
 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)
Example #10
0
 def mountpoints(self):
     targets = process.check_output(
         ["findmnt", "-o", "target", "-n", self.device]).split("\n")
     return [Mount(t.strip()) for t in targets]
Example #11
0
 def _tokens(self):
     tokens = process.check_output(["blkid", "-o", "export", self.device])
     return parse_varfile(tokens)
Example #12
0
 def _call(self, cmd):
     return process.check_output(cmd)