def _extract_battery_info_from_sys(self):
if not os.listdir(self.sys_battery_path):<EOL><INDENT>return []<EOL><DEDENT>def _parse_battery_info(sys_path):<EOL><INDENT>"""<STR_LIT>"""<EOL>raw_values = {}<EOL>with open(os.path.join(sys_path, u"<STR_LIT>")) as f:<EOL><INDENT>for var in f.read().splitlines():<EOL><INDENT>k, v = var.split("<STR_LIT:=>")<EOL>try:<EOL><INDENT>raw_values[k] = int(v)<EOL><DEDENT>except ValueError:<EOL><INDENT>raw_values[k] = v<EOL><DEDENT><DEDENT><DEDENT>return raw_values<EOL><DEDENT>battery_list = []<EOL>for path in iglob(os.path.join(self.sys_battery_path, "<STR_LIT>")):<EOL><INDENT>r = _parse_battery_info(path)<EOL>capacity = r.get(<EOL>"<STR_LIT>", r.get("<STR_LIT>")<EOL>)<EOL>present_rate = r.get(<EOL>"<STR_LIT>",<EOL>r.get("<STR_LIT>", r.get("<STR_LIT>")),<EOL>)<EOL>remaining_energy = r.get(<EOL>"<STR_LIT>", r.get("<STR_LIT>")<EOL>)<EOL>battery = {}<EOL>battery["<STR_LIT>"] = capacity<EOL>battery["<STR_LIT>"] = "<STR_LIT>" in r["<STR_LIT>"]<EOL>battery["<STR_LIT>"] = int(<EOL>math.floor(remaining_energy / capacity * <NUM_LIT:100>)<EOL>)<EOL>try:<EOL><INDENT>if battery["<STR_LIT>"]:<EOL><INDENT>time_in_secs = (capacity - remaining_energy) / present_rate * <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>time_in_secs = remaining_energy / present_rate * <NUM_LIT><EOL><DEDENT>battery["<STR_LIT>"] = self._seconds_to_hms(time_in_secs)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>battery["<STR_LIT>"] = FULLY_CHARGED<EOL><DEDENT>battery_list.append(battery)<EOL><DEDENT>return battery_list<EOL>
Extract the percent charged, charging state, time remaining,
and capacity for a battery, using Linux's kernel /sys interface

Only available in kernel 2.6.24(?) and newer. Before kernel provided
a similar, yet incompatible interface in /proc