From 46c6076f9516ff7aec2c893ef857c977a6a8aab0 Mon Sep 17 00:00:00 2001 From: microarm15 Date: Tue, 16 Jun 2015 19:10:48 +0200 Subject: [PATCH] check whether files exist --- i3pystatus/network.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/i3pystatus/network.py b/i3pystatus/network.py index 7059873..207490c 100644 --- a/i3pystatus/network.py +++ b/i3pystatus/network.py @@ -199,12 +199,18 @@ class NetworkTraffic(): return self.pnic.packets_recv - self.pnic_before.packets_recv def get_rx_tot_Mbytes(self, interface): - with open("/sys/class/net/{}/statistics/rx_bytes".format(interface)) as f: - return int(f.readline().split('\n')[0]) / (1024 * 1024) + try: + with open("/sys/class/net/{}/statistics/rx_bytes".format(interface)) as f: + return int(f.readline().split('\n')[0]) / (1024 * 1024) + except FileNotFoundError: + return False def get_tx_tot_Mbytes(self, interface): - with open("/sys/class/net/{}/statistics/tx_bytes".format(interface)) as f: - return int(f.readline().split('\n')[0]) / (1024 * 1024) + try: + with open("/sys/class/net/{}/statistics/tx_bytes".format(interface)) as f: + return int(f.readline().split('\n')[0]) / (1024 * 1024) + except FileNotFoundError: + return False def get_usage(self, interface): self.update_counters(interface)