Using an even easier and safer way to update dhcpd configuration
This commit is contained in:
12
main.py
12
main.py
@@ -113,15 +113,9 @@ def switch_status(turn_on):
|
||||
|
||||
|
||||
def update_dhcp_conf(turn_on):
|
||||
right_interface = False
|
||||
for line in fileinput.input(USB_DHCPD_FILENAME, inplace=True):
|
||||
if line.startswith('interface'):
|
||||
right_interface = line.strip().split(' ')[-1] == AIR_INTERFACE_NAME
|
||||
|
||||
if right_interface and 'metric' in line:
|
||||
print("\tmetric {}\n".format(METRIC_ON if turn_on else METRIC_OFF), end='')
|
||||
else:
|
||||
print(line, end='')
|
||||
with open(USB_DHCPD_FILENAME, 'w') as dhcpd_file:
|
||||
dhcpd_file.write("interface {}\n".format(AIR_INTERFACE_NAME))
|
||||
dhcpd_file.write("\tmetric {}\n".format(METRIC_ON if turn_on else METRIC_OFF))
|
||||
|
||||
|
||||
def update_usb_modem(turn_on):
|
||||
|
||||
Reference in New Issue
Block a user