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)
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
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
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
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
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
def exec_out(self, *args, **kwargs): return common.execute_get_out([self.path, *args], **kwargs)