From f28293d200ef9a65b455a13007714456dde8af04 Mon Sep 17 00:00:00 2001 From: Rolando Islas Date: Sat, 3 Jun 2017 17:56:29 -0700 Subject: [PATCH] Fix install path on Travis Add status to get_key Fix #23 --- install.sh | 14 ++++++++---- src/server/ui/gui/frame/frame_about.py | 9 ++++++++ src/server/ui/gui/frame/frame_get_key.py | 18 ++++++++------- src/server/util/wpa_supplicant.py | 29 ++++++++++++++++++++++-- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/install.sh b/install.sh index 638d0d9..62a529e 100755 --- a/install.sh +++ b/install.sh @@ -16,8 +16,10 @@ # June 1, 2017 - 1.1.1 # Fix Make, cmake, and setup.py not returning on errors # Fix current directory not being restored on a git update failure +# June 2, 2017 - 1.1.2 +# Detect and install to virtualenv -VERSION="1.1" +VERSION="1.1.2" REPO_DRC_SIM="https://github.com/rolandoislas/drc-sim.git" REPO_WPA_SUPPLICANT_DRC="https://github.com/rolandoislas/drc-hostap.git" REPO_DRC_SIM_C="https://github.com/rolandoislas/drc-sim-c.git" @@ -200,7 +202,13 @@ install_drc_sim() { # Install echo "Installing drc-sim" echo "Downloading Python packages. This may take a while." - if ! python3 "${drc_dir}setup.py" install --record "${drc_dir}/install.txt" &> "/tmp/drc-sim-py-install.log"; then + prefix="" + if [ ! -z "${VIRTUAL_ENV}" ]; then + echo "Installing into virtualenv: ${VIRTUAL_ENV}" + prefix="--prefix ${VIRTUAL_ENV}" + fi + if ! python3 "${drc_dir}setup.py" install ${prefix} --record "${drc_dir}/install.txt" &> \ + "/tmp/drc-sim-py-install.log"; then cat "/tmp/drc-sim-py-install.log" return 1 fi @@ -233,7 +241,6 @@ uninstall() { exit 2 fi else - cat ${drc_install_log} echo "Could not clean Python installed files. Missing ${drc_install_log}" fi # Launcher (.desktop) @@ -241,7 +248,6 @@ uninstall() { "/usr/share/icons/hicolor/512x512/apps/drcsimbackend.png") for item in "${to_remove[@]}"; do if [[ -f "${item}" ]]; then - echo "Removing application launcher" rm -f ${item} &> /dev/null fi done diff --git a/src/server/ui/gui/frame/frame_about.py b/src/server/ui/gui/frame/frame_about.py index 3561cc3..5a0a8cf 100644 --- a/src/server/ui/gui/frame/frame_about.py +++ b/src/server/ui/gui/frame/frame_about.py @@ -9,9 +9,18 @@ def __init__(self, master=None, **kw): super().__init__(master, **kw) self.text_name = Label(self, text=constants.NAME) self.text_version = Label(self, text="v" + constants.VERSION) + self.text_license = Label(self, + text="%s is free software: you can\n" % constants.NAME + + "redistribute it and/or modify it under the\n" + "terms of the GNU General Public License as\n" + "published by the Free Software Foundation,\n" + "either version 2 of the License, or\n" + "(at your option) any later version." + ) self.text_name.grid(row=0, column=0) self.text_version.grid(row=1, column=0) + self.text_license.grid(row=2, column=0) self.grid_columnconfigure(0, weight=1) def activate(self): diff --git a/src/server/ui/gui/frame/frame_get_key.py b/src/server/ui/gui/frame/frame_get_key.py index 537525e..594bb61 100644 --- a/src/server/ui/gui/frame/frame_get_key.py +++ b/src/server/ui/gui/frame/frame_get_key.py @@ -1,5 +1,5 @@ from tkinter import PhotoImage, Button, END, messagebox -from tkinter.ttk import Entry, Progressbar, Combobox +from tkinter.ttk import Entry, Combobox, Label from src.server.data import constants from src.server.data.resource import Resource @@ -41,8 +41,8 @@ def __init__(self, master=None, **kw): self.button_delete = Button(self, text="Delete") # Code self.entry_pair_code = Entry(self, state="readonly") - # Progress bar - self.progress_bar = Progressbar(self, mode="indeterminate") + # Status Message + self.status_message = Label(self, state="readonly") # interface dropdown self.dropdown_wii_u = Combobox(self, state="readonly") # Events @@ -58,7 +58,7 @@ def __init__(self, master=None, **kw): self.button_clover.grid(column=3, row=0) self.button_delete.grid(column=4, row=0) self.entry_pair_code.grid(column=0, row=1, columnspan=5) - self.progress_bar.grid(column=0, row=3, columnspan=5) + self.status_message.grid(column=0, row=3, columnspan=5) self.dropdown_wii_u.grid(column=0, row=2, columnspan=5) # noinspection PyUnusedLocal @@ -99,7 +99,6 @@ def button_clicked(self, event): if len(code) == 4: self.getting_psk = True self.set_code_text("") - self.progress_bar.grid() self.get_psk(code, wii_u_interface) def get_psk(self, code, interface): @@ -127,19 +126,22 @@ def wpa_status_changed(self, status): self.deactivate() self.activate() messagebox.showerror("Auth Saved", "Successfully paired with Wii U.") + elif status == WpaSupplicant.SCANNING: + self.status_message["text"] = "Scanning" + elif status == WpaSupplicant.CONNECTING: + self.status_message["text"] = "Connecting" def activate(self): LoggerGui.debug("FrameTab activate called") self.getting_psk = False self.set_code_text("") - self.progress_bar.start() if not self.wpa_supplicant or not self.wpa_supplicant.get_status(): - self.progress_bar.grid_remove() + self.status_message["text"] = "" self.dropdown_wii_u["values"] = InterfaceUtil.get_wiiu_compatible_interfaces() def deactivate(self): LoggerGui.debug("FrameTab deactivate called") - self.progress_bar.stop() + self.status_message["text"] = "" self.getting_psk = False if self.wpa_supplicant: self.wpa_supplicant.stop() diff --git a/src/server/util/wpa_supplicant.py b/src/server/util/wpa_supplicant.py index d7cf630..aaf2e17 100644 --- a/src/server/util/wpa_supplicant.py +++ b/src/server/util/wpa_supplicant.py @@ -199,6 +199,8 @@ def get_psk(self, conf_path, interface, code): NOT_FOUND: wpa_supplicant_drc did not find any Wii U APs TERMINATED: wpa_supplicant_drc could not authenticate with any SSIDs DISCONNECTED: auth details were saved + SCANNING: scan has started + CONNECTING: attempting to authenticate with a Wii U :return: None """ self.connect(conf_path, interface, status_check=False) @@ -219,10 +221,19 @@ def get_psk_thread(self, code): # Scan for Wii U SSIDs scan_tries = 5 wii_u_bssids = [] + self.set_status(self.SCANNING) while self.running and scan_tries > 0: self.psk_thread_cli.sendline("scan") LoggerWpa.debug("CLI expect waiting for scan results available event") - self.psk_thread_cli.expect("<3>CTRL-EVENT-SCAN-RESULTS", timeout=60) + scan_wait_tries = 60 + while self.running: + try: + self.psk_thread_cli.expect("<3>CTRL-EVENT-SCAN-RESULTS", timeout=1) + break + except pexpect.TIMEOUT: + scan_wait_tries -= 1 + if scan_wait_tries <= 0: + raise pexpect.TIMEOUT("Scan timeout") self.psk_thread_cli.sendline("scan_results") LoggerWpa.debug("CLI expect waiting for scan results") self.psk_thread_cli.expect("bssid / frequency / signal level / flags / ssid") @@ -246,13 +257,22 @@ def get_psk_thread(self, code): self.set_status(self.NOT_FOUND) return # attempt to pair with any wii u bssid + self.set_status(self.CONNECTING) for bssid in wii_u_bssids: self.psk_thread_cli.sendline("wps_pin %s %s" % (bssid, code + "5678")) LoggerWpa.debug("CLI expect waiting for wps_pin input confirmation") self.psk_thread_cli.expect(code + "5678") LoggerWpa.debug("CLI expect waiting for authentication") try: - self.psk_thread_cli.expect("<3>WPS-CRED-RECEIVED", timeout=60) + connect_wait_tries = 60 + while self.running: + try: + self.psk_thread_cli.expect("<3>WPS-CRED-RECEIVED", timeout=1) + break + except pexpect.TIMEOUT: + connect_wait_tries -= 1 + if connect_wait_tries <= 0: + raise pexpect.TIMEOUT("Connect Timeout") # save conf LoggerWpa.debug("PSK obtained") # Save to temp config before reading from it @@ -270,6 +290,11 @@ def get_psk_thread(self, code): LoggerWpa.debug("PSK get attempt ended with an error.") LoggerWpa.exception(e) self.set_status(self.FAILED_START) + # Unexpected EOF + except pexpect.EOF as e: + if self.running: # Thread was not killed + LoggerWpa.exception(e) + return # Failed to authenticate LoggerWpa.debug("Could not authenticate with any SSIDs") self.set_status(self.TERMINATED)