def execute(self): with MpdClientWrapper(self._host, self._port) as cl: status = cl.status() data = cl.currentsong() if "time" in status.keys(): elapsed, total = status["time"].split(":") # get elapsed time as a datetime.time object elapsed = int(elapsed) total = int(total) data["elapsedtime"] = Util.seconds_to_time(elapsed).strftime( self._time_format) data["totaltime"] = Util.seconds_to_time(total).strftime( self._time_format) pattern = None if status["state"] == 'play' and self._layout_playing: pattern = self._layout_playing elif status["state"] == 'pause' and self._layout_paused: pattern = self._layout_paused elif status["state"] == 'stop' and self.layout_stopped: pattern = self._layout_stopped if not pattern: return self._layout % data else: try: res = pattern % data except KeyError: res = self._layout_filenameonly % data return res
def execute(self): values = {} for f in os.listdir(self.batdir): try: batfile = open(self.batdir + f, "r") values[f] = batfile.readline().strip() batfile.close() except IOError: self.logger.error( "Encountered an error reading battery information from " + self.batdir) pass values["discharging_time_remaining"] = None values["charging_time_remaining"] = None if "remaining_running_time_now" in values.keys( ) and values["remaining_running_time_now"] != "not_discharging": values["discharging_time_remaining"] = Util.minutes_to_time( float(values["remaining_running_time_now"]) ) #.strftime(self._time_format) if "remaining_charging_time" in values.keys( ) and values["remaining_charging_time"] != "not_charging": values["charging_time_remaining"] = Util.minutes_to_time( float(values["remaining_charging_time"]) ) #.strftime(self._time_format) try: if self._format_all: return self._format_all % values if values["installed"] == "1": if self._format_installed: return self._format_installed % values elif values["state"] == "discharging": return self._format_discharging % values elif values["state"] == "charging": return self._format_charging % values else: return self._format_idle % values else: return self._format_uninstalled % values except KeyError: print("KEY ERROR:") print(values) return None
def execute(self): args = [self._interface] try: iwconfig_output = Util.execute_shell_process(self._iwconfig, args) ifconfig_output = Util.execute_shell_process(self._ifconfig, args) except IOError: self.logger.error("Error executing iwconfig or ifconfig.") return None regex = { 'essid': r'ESSID:"(\S*)"', 'quality': r'Link Quality=(\d*)/(\d*)', 'frequency': r'Frequency:(\S*)', 'ap': r'Access Point: (\S*)', 'rate': r'Bit Rate=(\d*)' } data = {} try: for key, val in regex.items(): m = re.findall(val, iwconfig_output) if len(m) > 0: data[key] = re.findall(val, iwconfig_output)[0] addr = re.findall(r'inet addr:(\S*)', ifconfig_output) if len(addr) > 0: data['address'] = addr[0] data['quality_pct'] = None if 'quality' in data.keys() and data['quality'][1] != 0: data['quality_pct'] = 100 * float(data['quality'][0]) / float( data['quality'][1]) else: data['quality_pct'] = 0 if 'essid' in data.keys(): if 'address' in data.keys() and self._layout_connected_address: return self._layout_connected_address % data if self._layout_connected: return self._layout_connected % data else: if self._layout_disconnected: return self._layout_disconnected % data except TypeError: return None
def execute(self): interfaces = self.get_interface_list() try: current_data = time.time(), self.get_transferred_data(interfaces) except NetworkInterfaceDoesntExistError as e: print("Interface " + e.iface + " disappeared...") del interfaces[e.iface] if len(interfaces) == 0: return None info = { 'DataDownloaded': current_data[1][0], 'DataUploaded': current_data[1][1], 'DownloadRate': (current_data[1][0] - self.previous_data[1][0]) / \ (current_data[0] - self.previous_data[0]), 'UploadRate': (current_data[1][1] - self.previous_data[1][1]) / \ (current_data[0] - self.previous_data[0]) } #rate = (current_data[1] - self.previous_data[1]) / \ #(current_data[0] - self.previous_data[0]) self.previous_data = current_data for key, value in info.items(): info[key] = Util.format_output(value, self._format, self._show_units, self._short_units) return self._layout % info
def execute(self): data = open("/proc/uptime", "r").readline().split() delta = datetime.fromtimestamp(time.time()) - \ datetime.fromtimestamp(time.time() - float(data[0])) t = Util.seconds_to_time(delta.seconds) return "%d days, %dh, %dm" % (delta.days, t.hour, t.minute)
def execute(self): args = [self._interface] try: ifconfig_output = Util.execute_shell_process(self._ifconfig, args) except IOError: self.logger.error("Error executing " + self._ifconfig + " with arguments " + args) down = re.findall(r'DOWN')
def execute(self): values = { # values from /sys "status": None, "charge_full": None, "charge_full_design": None, "charge_now": None, "current_now": None, "status": None, "voltage_min_design": None, "voltage_now": None, # custom values "charge_percent": None, "time_remaining": None } for key in values.keys(): if os.path.exists(self.batdir + key): batfile = open(self.batdir + key, "r") values[key] = batfile.readline() batfile.close() charging = "Charging" in values["status"] discharging = "Discharging" in values["status"] charged = "Unknown" in values["status"] if values["charge_now"] and values["charge_full"]: values["charge_percent"] = int(values["charge_now"]) * 100 / int( values["charge_full"]) # calculating remaining time time = None if values["current_now"]: if discharging: time = float(values["charge_now"]) / float( values["current_now"]) elif charging: time = (float(values["charge_full"]) - float( values["charge_now"])) / float(values["current_now"]) if time: values["time_remaining"] = Util.hours_to_time(time).strftime( self._time_format) #print values if self._format_all: return self._format_all.format(**values) if charging: return self._format_charging.format(**values) elif discharging: return self._format_discharging.format(**values) elif charged: return self._format_charged.format(**values)
def execute(self): args = ["sget", self._control] amixer_output = Util.execute_shell_process(self._amixer_command, args) regex_mute = r'\[off\]' regex_vol = r'\d{1,3}%' if re.search(regex_mute, amixer_output): return self._mute_output value = int(re.findall(regex_vol, amixer_output)[0].strip('%')) if self._show_units: return self._format % value + '%' else: return self._format % value
def execute(self): mount_file = open('/proc/mounts') for line in mount_file: if line.split()[1] == self._mount_point: break else: return None info = get_mount_point_statistics(self._mount_point) for key, value in info.items(): if key != 'UsePercent': info[key] = Util.format_output(value, self._format, self._show_units, self._short_units) if self._show_units: info['UsePercent'] = str(info['UsePercent']) + '%' return self._layout % info
def execute(self): if self._command: return Util.execute_shell_process(self._command, self._args).strip()