Add network module (3.4), close #4
This commit is contained in:
parent
6b03e35ad2
commit
890e8a91bc
41
README.md
41
README.md
@ -99,7 +99,7 @@ Available formatters for format and alert_format_\*:
|
|||||||
|
|
||||||
|
|
||||||
* `battery_ident` — (default: `BAT0`)
|
* `battery_ident` — (default: `BAT0`)
|
||||||
* `format` — (default: `{status} {remaining}`)
|
* `format` — (default: `{status} {remaining_hm}`)
|
||||||
* `alert` — Display a libnotify-notification on low battery (default: `False`)
|
* `alert` — Display a libnotify-notification on low battery (default: `False`)
|
||||||
* `alert_percentage` — (default: `10`)
|
* `alert_percentage` — (default: `10`)
|
||||||
* `alert_format_title` — (default: `Low battery`)
|
* `alert_format_title` — (default: `Low battery`)
|
||||||
@ -224,7 +224,6 @@ The `backends` setting determines the backends to use. Currently available are:
|
|||||||
>
|
>
|
||||||
> Requires
|
> Requires
|
||||||
> * python-dbus
|
> * python-dbus
|
||||||
> * python-gobject2
|
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
@ -247,6 +246,44 @@ unread posts in any bookmark in the mods.de forums.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### network
|
||||||
|
|
||||||
|
|
||||||
|
Display network information about a interface.
|
||||||
|
|
||||||
|
Requires the PyPI package `netifaces-py3`.
|
||||||
|
|
||||||
|
Available formatters:
|
||||||
|
* {inteface} same as setting
|
||||||
|
* {name} same as setting
|
||||||
|
* {v4} IPv4 address
|
||||||
|
* {v4mask} subnet mask
|
||||||
|
* {v6} IPv6 address
|
||||||
|
* {v6mask} subnet mask
|
||||||
|
* {mac} MAC of interface
|
||||||
|
|
||||||
|
Not available addresses (i.e. no IPv6 connectivity) are replaced with empty strings.
|
||||||
|
|
||||||
|
|
||||||
|
* `interface` — Interface to obtain information for, i.e. eth0 (default: `eth0`)
|
||||||
|
* `format_up` — (default: `{interface}: {v4}`)
|
||||||
|
* `color_up` — (default: `#00FF00`)
|
||||||
|
* `format_down` — (default: `{interface}`)
|
||||||
|
* `color_down` — (default: `#FF0000`)
|
||||||
|
* `name` — (default: `eth0`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### parcel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* `instance` — Tracker instance
|
||||||
|
* `format` — (default: `{name}:{progress}`)
|
||||||
|
* `name`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### regex
|
### regex
|
||||||
|
|
||||||
|
|
||||||
|
75
i3pystatus/network.py
Normal file
75
i3pystatus/network.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
|
||||||
|
from itertools import zip_longest
|
||||||
|
|
||||||
|
# PyPI: netifaces-py3
|
||||||
|
import netifaces
|
||||||
|
|
||||||
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class Network(IntervalModule):
|
||||||
|
"""
|
||||||
|
Display network information about a interface.
|
||||||
|
|
||||||
|
Requires the PyPI package `netifaces-py3`.
|
||||||
|
|
||||||
|
Available formatters:
|
||||||
|
* {inteface} same as setting
|
||||||
|
* {name} same as setting
|
||||||
|
* {v4} IPv4 address
|
||||||
|
* {v4mask} subnet mask
|
||||||
|
* {v6} IPv6 address
|
||||||
|
* {v6mask} subnet mask
|
||||||
|
* {mac} MAC of interface
|
||||||
|
|
||||||
|
Not available addresses (i.e. no IPv6 connectivity) are replaced with empty strings.
|
||||||
|
"""
|
||||||
|
|
||||||
|
settings = (
|
||||||
|
("interface", "Interface to obtain information for, i.e. eth0"),
|
||||||
|
"format_up", "color_up",
|
||||||
|
"format_down", "color_down",
|
||||||
|
"name"
|
||||||
|
)
|
||||||
|
|
||||||
|
name = interface = "eth0"
|
||||||
|
format_up = "{interface}: {v4}"
|
||||||
|
format_down = "{interface}"
|
||||||
|
color_up = "#00FF00"
|
||||||
|
color_down = "#FF0000"
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
if self.interface not in netifaces.interfaces():
|
||||||
|
raise RuntimeError("Unknown inteface {iface}!".format(iface=self.inteface))
|
||||||
|
|
||||||
|
self.baseinfo = {
|
||||||
|
"interface": self.interface,
|
||||||
|
"name": self.name,
|
||||||
|
"mac": netifaces.ifaddresses(self.interface)[netifaces.AF_PACKET][0]["addr"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
info = netifaces.ifaddresses(self.interface)
|
||||||
|
up = netifaces.AF_INET in info or netifaces.AF_INET6 in info
|
||||||
|
fdict = dict(zip_longest(["v4", "v4mask", "v6", "v6mask"], [], fillvalue=""))
|
||||||
|
fdict.update(self.baseinfo)
|
||||||
|
|
||||||
|
if up:
|
||||||
|
format = self.format_up
|
||||||
|
color = self.color_up
|
||||||
|
if netifaces.AF_INET in info:
|
||||||
|
v4 = info[netifaces.AF_INET][0]
|
||||||
|
fdict["v4"] = v4["addr"]
|
||||||
|
fdict["v4mask"] = v4["netmask"]
|
||||||
|
if netifaces.AF_INET6 in info:
|
||||||
|
v6 = info[netifaces.AF_INET6][0]
|
||||||
|
fdict["v6"] = v6["addr"]
|
||||||
|
fdict["v6mask"] = v6["netmask"]
|
||||||
|
else:
|
||||||
|
format = self.format_down
|
||||||
|
color = self.color_down
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": format.format(**fdict),
|
||||||
|
"color": color,
|
||||||
|
"instance": self.interface
|
||||||
|
}
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(name="i3pystatus",
|
setup(name="i3pystatus",
|
||||||
version="3.3",
|
version="3.4",
|
||||||
description="Like i3status, this generates status line for i3bar / i3wm",
|
description="Like i3status, this generates status line for i3bar / i3wm",
|
||||||
url="http://github.com/enkore/i3pystatus",
|
url="http://github.com/enkore/i3pystatus",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
|
Loading…
Reference in New Issue
Block a user