Esempio n. 1
0
    def __init__(self, path=None):
        if path is None:
            path = common.execute_get_out(['which', 'ufw'])
            if path == '':
                raise FileNotFoundError("Couldn't find ufw.")

        super().__init__(path)
Esempio n. 2
0
def get_hid_idle_time():
    content = common.execute_get_out(
        ['/usr/sbin/ioreg', '-c', 'IOHIDSystem', '-d', '4'])

    reg = re.compile(r'"HIDIdleTime" = (\d+)')
    result = common.reg_find_one(reg, content, None)

    return int(result) / 1000000000
Esempio n. 3
0
def get_system_version():
    content = common.execute_get_out(
        ['/usr/sbin/system_profiler', 'SPSoftwareDataType'])
    result = {}
    reg = re.compile('(.*): (.*)')
    for item in reg.findall(content):
        result[item[0].strip()] = item[1].strip()
    return result
Esempio n. 4
0
def check_admin(username=None):
    args = ['/usr/bin/groups']
    if username is not None:
        args.append(username)

    content = common.execute_get_out(args)
    groups = content.split(' ')

    return 'admin' in groups
Esempio n. 5
0
def check_display_sleep():
    content = common.execute_get_out(
        ['/usr/sbin/ioreg', '-n', 'AppleBacklightDisplay', '-d', '9'])

    reg = re.compile(r'"dsyp"={"min"=(\d+),"max"=(\d+),"value"=(\d+)}')
    result = common.reg_find_one(reg, content, None)
    if result is not None:
        [min_, max_, value] = result
        return min_ == value
    else:
        return False
Esempio n. 6
0
def check_lid():
    content = common.execute_get_out(
        ['/usr/sbin/ioreg', '-c', 'IOPMrootDomain', '-d', '4'])

    reg = re.compile(r'"AppleClamshellState" = (\S+)')
    result = common.reg_find_one(reg, content, None)

    if result == 'Yes':
        return True
    elif result == 'No':
        return False
    else:
        return None
Esempio n. 7
0
 def exec_out(self, *args, **kwargs):
     return common.execute_get_out([self.path, *args], **kwargs)