Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

rpi_network_conn.py updates #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

rpi_network_conn.py updates #18

wants to merge 1 commit into from

Conversation

delirious-lettuce
Copy link
Contributor

  • Reorder imports as suggested by PEP8

get_wifi_list

  • Remove assignment to wlan_status since it wasn't being used for anything
  • Remove returncode since it wasn't being used for anything
  • Return [] if sudo ifup wlan0 fails. It would seem if the wifi is down, the next call to check nearby wifi access points will likely fail as well.
  • Remove redundant parentheses
  • Return [] if sudo iwlist wlan0 scan fails. It doesn't seem to make sense to try to iterate an empty list, create a set out of an empty list and then try to sort an empty set.
  • range loop replaced with enumerate since both the index and value are needed
  • On the worst case, iw_list[x].strip() was being created 5 times. Also, each instance was then creating another slice. To cut down on unnecessary copies, the current variable saves the stripped current line.
  • Using str.startswith doesn't create unnecessary copies either
  • end variable was created to reuse the same slice 4 times
  • Remove list(...) inside of sorted(...) since it was creating an unnecessary list instead of just creating the sorted list directly from set(wifi_list)

add_wifi

  • Create ssid once instead of creating it via concatenation on each iteration of the loop
  • Create wifi_key_info once instead of (potentially) multiple times inside the loop (also, if wifi_exists is False)
  • Use xrange instead of range
  • Remove redundant parentheses
  • Simplify network string creation using a multi-line string and textwrap.dedent to keep proper indentation
  • Use file.writelines instead of file.write for each separate line

internet_status

  • Remove assignment to response since it wasn't being used for anything
  • return False immediately if urllib2.URLError is raised
  • Move return True to the else statement (for readability and to stay consistent with other project files)

reset_wifi

  • Use a multi-line string and textwrap.dedent to create lines
  • Remove assignment to vpn_status since it wasn't being used for anything
  • Remove returncode since it wasn't being used for anything
  • return False immediately if CalledProcessError is raised
  • return True in the else since CalledProcessError is only raised for a non-zero exit code (no need to check returncode == 0)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant