Exemplo n.º 1
0
 def battery_status_read(self):
     """Get the battery status via proc/acpi."""
     try:
         path_info = self.readf("/proc/acpi/battery/BAT0/info")
         path_state = self.readf("/proc/acpi/battery/BAT0/state")
     except:
         return None
     try:
         max_cap = float(helpers.get_string_between("last full capacity:", "mWh", path_info))
         cur_cap = float(helpers.get_string_between("remaining capacity:", "mWh", path_state))
         return int(cur_cap / max_cap * 100)
     except:
         return None
Exemplo n.º 2
0
 def battery_status_read(self):
     """Get the battery status via proc/acpi."""
     try:
         path_info = self.readf("/proc/acpi/battery/BAT0/info")
         path_state = self.readf("/proc/acpi/battery/BAT0/state")
     except:
         return None
     try:
         max_cap = float(
             helpers.get_string_between("last full capacity:", "mWh",
                                        path_info))
         cur_cap = float(
             helpers.get_string_between("remaining capacity:", "mWh",
                                        path_state))
         return int(cur_cap / max_cap * 100)
     except:
         return None
Exemplo n.º 3
0
 def battery_status_acpi(self):
     """Get the battery status via acpi."""
     try:
         raw_str = subprocess.check_output(["acpi"])
     except:
         return None
     raw_str = raw_str.decode("utf-8")
     part = helpers.get_string_between(",", "%", raw_str)
     if part:
         try:
             return int(part)
         except:
             return None
     return None
Exemplo n.º 4
0
    def get_function_args(self, line_data):
        """Get list of arguments for function

        Parses a function definition in line_data and returns argument list.

        :param str line_data: The line containing the function definition.
        """
        func_name = self.get_function_name(line_data)
        raw_args = helpers.get_string_between(func_name+"(", "):", line_data)
        parts = raw_args.split(",")
        args = [part.strip() for part in parts]
        if "self" in args:
            args.pop(args.index("self"))
        return args
Exemplo n.º 5
0
    def get_function_args(self, line_data):
        """Get list of arguments for function

        Parses a function definition in line_data and returns argument list.

        :param str line_data: The line containing the function definition.
        """
        func_name = self.get_function_name(line_data)
        raw_args = helpers.get_string_between(func_name+"(", "):", line_data)
        parts = raw_args.split(",")
        args = [part.strip() for part in parts]
        if "self" in args:
            args.pop(args.index("self"))
        return args
Exemplo n.º 6
0
 def battery_status_upower(self):
     """Get the battery status via upower."""
     path = "/org/freedesktop/UPower/devices/battery_BAT0"
     try:
         raw_str = subprocess.check_output(["upower", "-i", path])
     except:
         return None
     raw_str = raw_str.decode("utf-8")
     part = helpers.get_string_between("percentage:", "%", raw_str)
     if part:
         try:
             return int(part)
         except:
             return None
     return None
Exemplo n.º 7
0
 def battery_status_upower(self):
     """Get the battery status via upower."""
     path = "/org/freedesktop/UPower/devices/battery_BAT0"
     try:
         raw_str = subprocess.check_output(["upower", "-i", path])
     except:
         return None
     raw_str = raw_str.decode("utf-8")
     raw_str = raw_str.splitlines()[0]
     part = helpers.get_string_between("percentage:", "%", raw_str)
     if part:
         try:
             return int(part)
         except:
             return None
     return None
Exemplo n.º 8
0
 def battery_status_acpi(self):
     """Get the battery status via acpi."""
     try:
         fnull = open(os.devnull, "w")
         raw_str = subprocess.check_output(["acpi"], stderr=fnull)
         fnull.close()
     except:
         return None
     raw_str = raw_str.decode("utf-8")
     part = helpers.get_string_between(",", "%", raw_str)
     if part:
         try:
             return int(part)
         except:
             return None
     return None
Exemplo n.º 9
0
 def battery_status_acpi(self):
     """Get the battery status via acpi."""
     try:
         fnull = open(os.devnull, "w")
         raw_str = subprocess.check_output(["acpi"], stderr=fnull)
         fnull.close()
     except:
         return None
     raw_str = raw_str.decode("utf-8")
     part = helpers.get_string_between(",", "%", raw_str)
     if part:
         try:
             return int(part)
         except:
             return None
     return None
Exemplo n.º 10
0
    def get_function_name(self, line_data):
        """Get the name of function defined in line_data.

        :param str line_data: The line containing the function definition.
        """
        return helpers.get_string_between("def ", "(", line_data)
Exemplo n.º 11
0
    def get_function_name(self, line_data):
        """Get the name of function defined in line_data.

        :param str line_data: The line containing the function definition.
        """
        return helpers.get_string_between("def ", "(", line_data)