Skip to content

Commit

Permalink
Fix some PEP8/pylint issues. Undo one wrong change from #494cc3164
Browse files Browse the repository at this point in the history
  • Loading branch information
firecat53 committed Jan 26, 2020
1 parent 30fb8b1 commit cdc445c
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions networkmanager_dmenu
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CLIENT = NM.Client.new(None)
LOOP = GLib.MainLoop()
CONNS = CLIENT.get_connections()


def dmenu_cmd(num_lines, prompt="Networks", active_lines=None): # pylint: disable=too-many-branches
"""Parse config.ini if it exists and add options to the dmenu command
Expand Down Expand Up @@ -119,9 +120,9 @@ def choose_adapter(client):
"""
devices = client.get_devices()
devices = [i for i in devices if i.get_device_type() == NM.DeviceType.WIFI]
if not devices:
if not devices: # pylint: disable=no-else-return
return None
elif devices:
elif len(devices) == 1:
return devices[0]
device_names = "\n".join([d.get_iface() for d in devices]).encode(ENC)
sel = Popen(dmenu_cmd(len(devices), "CHOOSE ADAPTER:"),
Expand Down Expand Up @@ -174,7 +175,7 @@ def rescan_wifi():
dev.request_scan()
except gi.repository.GLib.Error as err:
# Too frequent rescan error
if not err.code == 6: # pylint: disable=no-member
if not err.code == 6: # pylint: disable=no-member
raise err


Expand Down Expand Up @@ -216,8 +217,7 @@ class Action(): # pylint: disable=too-few-public-methods
name,
func,
args=None,
active=False,
):
active=False):
self.name = name
self.func = func
self.is_active = active
Expand Down Expand Up @@ -289,7 +289,7 @@ def create_ap_actions(aps, active_ap, active_connection, adapter): # pylint: di
bars = NM.utils_wifi_strength_bars(nm_ap.get_strength())
is_active = nm_ap.get_bssid() == active_ap_bssid
compact = conf.getboolean("dmenu", "compact") \
if conf.has_option('dmenu', 'compact') else False
if conf.has_option('dmenu', 'compact') else False
if compact:
action_name = u"{} {} {}".format(name, sec, bars)
else:
Expand Down Expand Up @@ -397,9 +397,9 @@ def get_selection(eths, aps, vpns, wgs, gsms, blues, wwan, others):
conf = configparser.ConfigParser()
conf.read(expanduser("~/.config/networkmanager-dmenu/config.ini"))
rofi_highlight = conf.getboolean('dmenu', 'rofi_highlight') \
if conf.has_option('dmenu', 'rofi_highlight') else False
if conf.has_option('dmenu', 'rofi_highlight') else False
compact = conf.getboolean("dmenu", "compact") \
if conf.has_option('dmenu', 'compact') else False
if conf.has_option('dmenu', 'compact') else False
inp = []
empty_action = [Action('', None)] if not compact else []
all_actions = []
Expand All @@ -420,7 +420,7 @@ def get_selection(eths, aps, vpns, wgs, gsms, blues, wwan, others):
active_lines = [index for index, action in enumerate(all_actions)
if action.is_active]

inp_bytes = "\n".join([i for i in inp]).encode(ENC)
inp_bytes = "\n".join(inp).encode(ENC)
command = dmenu_cmd(len(inp), active_lines=active_lines)
sel = Popen(command, stdin=PIPE, stdout=PIPE,
env=ENV).communicate(input=inp_bytes)[0].decode(ENC)
Expand All @@ -438,7 +438,7 @@ def get_selection(eths, aps, vpns, wgs, gsms, blues, wwan, others):
action = [i for i in eths + aps + vpns + wgs + gsms + blues + wwan + others
if str(i).strip() == sel.strip()]
assert len(action) == 1, \
u"Selection was ambiguous: '{}'".format(str(sel.strip()))
u"Selection was ambiguous: '{}'".format(str(sel.strip()))
return action[0]


Expand Down Expand Up @@ -508,16 +508,14 @@ def get_passphrase():
pin = ""
out = Popen(pinentry,
stdout=PIPE,
stdin=PIPE).communicate( \
input=b'setdesc Get network password\ngetpin\n')[0]
stdin=PIPE).communicate(input=b'setdesc Get network password\ngetpin\n')[0]
if out:
res = out.decode(ENC).split("\n")[2]
if res.startswith("D "):
pin = res.split("D ")[1]
return pin
else:
return Popen(dmenu_cmd(0, "Passphrase"),
stdin=PIPE, stdout=PIPE).communicate()[0].decode(ENC)
return Popen(dmenu_cmd(0, "Passphrase"),
stdin=PIPE, stdout=PIPE).communicate()[0].decode(ENC)


def delete_connection():
Expand Down

0 comments on commit cdc445c

Please sign in to comment.