ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

force command to use C locale #47

Closed fdellwing closed 4 years ago

fdellwing commented 4 years ago

I have not tested this on windows, maybe there needs to be an additional check for that!

So the problem I'm trying to fix here, is that if you system uses a non English locale the LinuxParser will not give the expected results because the regex does not match anymore:

# echo $LANG
de_DE.UTF-8
# ifconfig brlan
brlan     Link encap:Ethernet  Hardware Adresse 00:50:56:a1:45:0a  
          inet Adresse:172.16.10.15  Bcast:172.16.15.255  Maske:255.255.240.0
          inet6-Adresse: fe80::250:56ff:fea1:450a/64 Gültigkeitsbereich:Verbindung
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX packets:33399 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10607 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX bytes:1732712 (1.6 MiB)  TX bytes:876186 (855.6 KiB)
# LANG=C ifconfig brlan
brlan     Link encap:Ethernet  HWaddr 00:50:56:a1:45:0a  
          inet addr:172.16.10.15  Bcast:172.16.15.255  Mask:255.255.240.0
          inet6 addr: fe80::250:56ff:fea1:450a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:33409 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10612 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1733232 (1.6 MiB)  TX bytes:876616 (856.0 KiB)

Without this change:

Python 3.7.6 (default, Feb  5 2020, 15:49:29) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ifcfg
>>> ifcfg.interfaces().get("brlan")
{'inet': None, 'inet4': [], 'ether': None, 'inet6': [], 'netmask': None, 'device': 'brlan', 'broadcast': '172.16.15.255', 'mtu': '1500', 'rxbytes': '1734110', 'txbytes': '877304'}
>>>

With this change:

Python 3.7.6 (default, Feb  5 2020, 15:49:29) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ifcfg
>>> ifcfg.interfaces().get("brlan")
{'inet': '172.16.10.15', 'inet4': ['172.16.10.15'], 'ether': '00:50:56:a1:45:0a', 'inet6': ['add', 'fe80::250:56ff:fea1:450a'], 'netmask': '255.255.240.0', 'device': 'brlan', 'broadcast': '172.16.15.255', 'mtu': '1500', 'rxbytes': '1734526', 'txbytes': '877718'}
codecov-io commented 4 years ago

Codecov Report

Merging #47 into master will increase coverage by 0.13%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
+ Coverage   83.33%   83.47%   +0.13%     
==========================================
  Files           4        4              
  Lines         240      242       +2     
==========================================
+ Hits          200      202       +2     
  Misses         40       40
Impacted Files Coverage Δ
src/ifcfg/tools.py 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e0bd672...992cbae. Read the comment docs.

benjaoming commented 4 years ago

Am really glad that you have looked into this! This seems like an important fix that we should release. Thanks!