Skip to content

Commit 24393f0

Browse files
committed
configure-scripts: Fixes PEP8 errors
1 parent 57a664e commit 24393f0

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

recipes-extended/configure-scripts/files/configure-network

+24-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import subprocess
1313
import sys
1414

1515

16-
## vars ########################################################################
16+
# vars ###################################################################
1717
iface = "wlan0"
1818
net_conf_dir = "/etc/systemd/network/"
1919
net_conf_file = net_conf_dir + "/20-net.network"
@@ -28,16 +28,20 @@ network={
2828
}
2929
'''
3030

31-
## functions ###################################################################
31+
# functions ##############################################################
32+
33+
3234
def pretty_print(line, prefix=""):
3335
print(prefix + line.decode('utf-8'))
3436

37+
3538
def print_ssid(line, prefix=""):
3639
if line.find(b'SSID:') >= 0:
3740
_ = line.split(b'SSID:')
3841
if len(_) > 1 and len(_[1].strip()) > 0:
3942
pretty_print(_[1], prefix)
4043

44+
4145
def call(command, interrupt=False, pp=pretty_print):
4246
print("\033[0;32m>>> %s\033[0m" % command)
4347
proc = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
@@ -50,12 +54,18 @@ def call(command, interrupt=False, pp=pretty_print):
5054
print("!!! Failure")
5155
sys.exit(1)
5256

57+
5358
def wpa_psk(ssid, password):
54-
dk = hashlib.pbkdf2_hmac('sha1', str.encode(password), str.encode(ssid), 4096, 32)
59+
dk = hashlib.pbkdf2_hmac(
60+
'sha1',
61+
str.encode(password),
62+
str.encode(ssid),
63+
4096,
64+
32)
5565
return (binascii.hexlify(dk)).decode('utf8')
5666

5767

58-
## command line options parser #################################################
68+
# command line options parser ############################################
5969
parser = argparse.ArgumentParser()
6070
parser.add_argument("-i", "--interface", dest="iface", default=iface,
6171
help=" (default: %s)" % iface)
@@ -67,13 +77,13 @@ iface = args.iface
6777
disable = args.disable
6878
wait = args.wait
6979

70-
## main ####################################################################
80+
# main #####################################################################
7181
if __name__ == "__main__":
7282
if os.geteuid() != 0:
7383
print("\033[0;31mYou need root permissions to run this command.\033")
7484
sys.exit(2)
7585

76-
if False: # Deprecated code
86+
if False: # Deprecated code
7787
call("rm -rf %s/*" % net_conf_dir)
7888
config = configparser.ConfigParser()
7989
config['Match'] = {}
@@ -90,8 +100,11 @@ if __name__ == "__main__":
90100
call("rm %s" % wpa_suplicant_conf_file % iface)
91101
else:
92102
call("iw dev %s scan" % iface, pp=print_ssid)
93-
ssid = input("\033[0;37mEnter the WiFi SSID (in iface %s):\033[0m " % iface)
94-
passphrase = input("\033[0;37mEnter the WiFi passphrase (Min. 8 chars):\033[0m ")
103+
ssid = input(
104+
"\033[0;37mEnter the WiFi SSID (in iface %s):\033[0m " %
105+
iface)
106+
passphrase = input(
107+
"\033[0;37mEnter the WiFi passphrase (Min. 8 chars):\033[0m ")
95108

96109
if not os.path.exists(wpa_suplicant_conf_dir):
97110
call("mkdir %s" % wpa_suplicant_conf_dir)
@@ -103,10 +116,11 @@ if __name__ == "__main__":
103116
call("systemctl restart -l wpa_supplicant@%s.service" % iface)
104117
call("systemctl status -l wpa_supplicant@%s.service" % iface)
105118

106-
ssid = print("\033[1;32mWaiting %s seconds to get IP in %s ...\033[0m " % (wait_seconds, iface))
119+
ssid = print(
120+
"\033[1;32mWaiting %s seconds to get IP in %s ...\033[0m " %
121+
(wait_seconds, iface))
107122
time.sleep(wait_seconds)
108123
call("ip address show %s" % iface)
109124
if wait:
110125
print("\033[1;32mPress any key to exit ...\033[0m ")
111126
input()
112-

recipes-extended/configure-scripts/files/configure-weston

+19-11
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import os
99
import subprocess
1010
import sys
1111

12-
## vars ########################################################################
12+
# vars ###################################################################
1313
configfile = '/etc/xdg/weston/weston.ini'
1414

1515

16-
## functions ###################################################################
16+
# functions ##############################################################
1717
def pretty_print(line, prefix=""):
1818
print(prefix + line.decode('utf-8'))
1919

20+
2021
def call(command, interrupt=False, pp=pretty_print):
2122
print("\033[0;32m>>> %s\033[0m" % command)
2223
proc = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
@@ -29,6 +30,7 @@ def call(command, interrupt=False, pp=pretty_print):
2930
print("!!! Failure")
3031
sys.exit(1)
3132

33+
3234
def set_option(config, section, option, defaults={}):
3335
if not config.has_section(section):
3436
config[section] = {}
@@ -37,30 +39,37 @@ def set_option(config, section, option, defaults={}):
3739
value = config.get(section, option, fallback=None)
3840
if not value:
3941
status = "default"
40-
value = defaults.get(section, {}).get(option,"")
41-
new_value = input("\033[1;33m>>> \033[0;37m[%s][%s] (%s: '%s'):\033[0m " % (section, option, status, value))
42+
value = defaults.get(section, {}).get(option, "")
43+
new_value = input(
44+
"\033[1;33m>>> \033[0;37m[%s][%s] (%s: '%s'):\033[0m " %
45+
(section, option, status, value))
4246
config[section][option] = new_value if new_value else value
4347

4448

45-
## command line options parser #################################################
49+
# command line options parser ############################################
4650
parser = argparse.ArgumentParser()
47-
parser.add_argument("-c", "--configfile", dest="configfile", default=configfile,
48-
help=" (default: %s)" % configfile)
51+
parser.add_argument(
52+
"-c",
53+
"--configfile",
54+
dest="configfile",
55+
default=configfile,
56+
help=" (default: %s)" %
57+
configfile)
4958

5059
args = parser.parse_args()
5160
configfile = args.configfile
5261

5362

54-
## main ####################################################################
63+
# main #####################################################################
5564
if __name__ == "__main__":
5665
if os.geteuid() != 0:
5766
print("\033[0;31mYou need root permissions to run this command.\033")
5867
sys.exit(2)
5968

6069
config = configparser.ConfigParser()
6170
config.read(configfile)
62-
config.get("core","idle-time", fallback=None)
63-
config.get("core","", fallback=None)
71+
config.get("core", "idle-time", fallback=None)
72+
config.get("core", "", fallback=None)
6473

6574
defaults = {}
6675
defaults['core'] = {}
@@ -92,4 +101,3 @@ if __name__ == "__main__":
92101

93102
call("diff -u %s.prev %s" % (configfile, configfile))
94103
call("systemctl restart [email protected]")
95-

0 commit comments

Comments
 (0)