Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows GNU radio backend fix with custom python2 interpreter #372

Merged
merged 11 commits into from
Dec 4, 2017
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ exclude_lines =
def mouseReleaseEvent
def on_import_samples_from_csv_action_triggered
def show_open_dialog
def on_btn_choose_python2_interpreter_clicked
def on_btn_choose_gnuradio_directory_clicked
def on_new_project_action_triggered
def on_label_non_project_mode_link_activated
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ src/urh/controller/__pycache__/
src/urh/cythonext/__pycache__/
src/urh/dev/__pycache__/
src/urh/dev/gr/__pycache__/
src/urh/dev/gr/scripts/InputHandlerThread.pyc
*.pyc
src/urh/dev/native/__pycache__/
src/urh/dev/native/lib/__pycache__/
src/urh/models/__pycache__/
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ matrix:
- DISPLAY=:99.0
- LIBOVERLAY_SCROLLBAR=0

notifications:
email: false

branches:
only:
- master
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ install:

build_script:
# Build the compiled extension
- python setup.py build_ext --inplace
- python setup.py build_ext --inplace > build_log.txt

test_script:
- python src\urh\main.py --version
Expand All @@ -68,6 +68,8 @@ artifacts:
on_success:
- IF "%APPVEYOR_REPO_TAG%" == "true" (twine upload --skip-existing dist/*.whl)

on_failure:
- type build_log.txt

deploy:
release: $(APPVEYOR_REPO_TAG_NAME)
Expand Down
26 changes: 22 additions & 4 deletions src/urh/controller/OptionsController.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QSize
from PyQt5.QtGui import QCloseEvent, QIcon, QPixmap
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QCompleter, QDirModel, QApplication, QHeaderView, QStyleFactory, \
QRadioButton, QVBoxLayout, QPlainTextEdit
QRadioButton, QFileDialog

from urh import constants, colormaps
from urh.controller.PluginController import PluginController
Expand Down Expand Up @@ -125,6 +125,8 @@ def __get_key_from_device_display_text(self, displayed_device_name):
def create_connects(self):
self.ui.doubleSpinBoxFuzzingPause.valueChanged.connect(self.on_spinbox_fuzzing_pause_value_changed)
self.ui.lineEditPython2Interpreter.editingFinished.connect(self.on_python2_exe_path_edited)
self.ui.btnChoosePython2Interpreter.clicked.connect(self.on_btn_choose_python2_interpreter_clicked)
self.ui.btnChooseGnuRadioDirectory.clicked.connect(self.on_btn_choose_gnuradio_directory_clicked)
self.ui.lineEditGnuradioDirectory.editingFinished.connect(self.on_gnuradio_install_dir_edited)
self.ui.listWidgetDevices.currentRowChanged.connect(self.on_list_widget_devices_current_row_changed)
self.ui.chkBoxDeviceEnabled.clicked.connect(self.on_chk_box_device_enabled_clicked)
Expand Down Expand Up @@ -327,6 +329,24 @@ def on_spinbox_fuzzing_pause_value_changed(self, value: float):
def on_python2_exe_path_edited(self):
self.set_gnuradio_status()

@pyqtSlot()
def on_btn_choose_python2_interpreter_clicked(self):
if sys.platform == "win32":
dialog_filter = "Executable (*.exe);;All files (*.*)"
else:
dialog_filter = ""
filename, _ = QFileDialog.getOpenFileName(self, self.tr("Choose python2 interpreter"), filter=dialog_filter)
if filename:
self.ui.lineEditPython2Interpreter.setText(filename)
self.set_gnuradio_status()

@pyqtSlot()
def on_btn_choose_gnuradio_directory_clicked(self):
directory = QFileDialog.getExistingDirectory(self, "Choose GNU Radio directory")
if directory:
self.ui.lineEditGnuradioDirectory.setText(directory)
self.set_gnuradio_status()

@pyqtSlot()
def on_chk_box_device_enabled_clicked(self):
self.selected_device.is_enabled = bool(self.ui.chkBoxDeviceEnabled.isChecked())
Expand Down Expand Up @@ -370,7 +390,7 @@ def on_gnuradio_install_dir_edited(self):
@pyqtSlot()
def on_btn_rebuild_native_clicked(self):
library_dirs = None if not self.ui.lineEditLibDirs.text() \
else list(map(str.strip, self.ui.lineEditLibDirs.text().split(",")))
else list(map(str.strip, self.ui.lineEditLibDirs.text().split(",")))
num_natives = self.backend_handler.num_native_backends
extensions = ExtensionHelper.get_device_extensions(use_cython=False, library_dirs=library_dirs)
new_natives = len(extensions) - num_natives
Expand Down Expand Up @@ -406,7 +426,6 @@ def on_btn_rebuild_native_clicked(self):
except OSError:
pass


@pyqtSlot()
def on_btn_health_check_clicked(self):
info = ExtensionHelper.perform_health_check()
Expand All @@ -417,7 +436,6 @@ def on_btn_health_check_clicked(self):
d = util.create_textbox_dialog(info, "Health check for native extensions", self)
d.show()


@staticmethod
def write_default_options():
settings = constants.SETTINGS
Expand Down
7 changes: 3 additions & 4 deletions src/urh/dev/BackendHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ def set_gnuradio_installed_status(self):
self.gnuradio_installed = False
return
else:
# we are on a nice unix with gnuradio installed to default python path
devnull = "NUL" if os.name == "nt" else "/dev/null"
if os.path.isfile(self.python2_exe) and os.access(self.python2_exe, os.X_OK):
# Subprocess.call gives memory error, so we use os.system
self.gnuradio_installed = os.system(self.python2_exe + " -c 'import gnuradio' 2>" + devnull) == 0
# Use shell=True to prevent console window popping up on windows
self.gnuradio_installed = call('"{0}" -c "import gnuradio"'.format(self.python2_exe),
shell=True, stderr=DEVNULL) == 0
constants.SETTINGS.setValue("python2_exe", self.python2_exe)
else:
self.gnuradio_installed = False
Expand Down
7 changes: 6 additions & 1 deletion src/urh/dev/gr/AbstractBaseThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ def __init__(self, freq, sample_rate, bandwidth, gain, if_gain, baseband_gain, r
self.context = None
self.socket = None

gnuradio_path_file = os.path.join(tempfile.gettempdir(), "gnuradio_path.txt")
if constants.SETTINGS.value("use_gnuradio_install_dir", False, bool):
gnuradio_dir = constants.SETTINGS.value("gnuradio_install_dir", "")
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "w") as f:
with open(gnuradio_path_file, "w") as f:
f.write(gnuradio_dir)
if os.path.isfile(os.path.join(gnuradio_dir, "gr-python27", "pythonw.exe")):
self.python2_interpreter = os.path.join(gnuradio_dir, "gr-python27", "pythonw.exe")
else:
self.python2_interpreter = os.path.join(gnuradio_dir, "gr-python27", "python.exe")
else:
try:
os.remove(gnuradio_path_file)
except OSError:
pass
self.python2_interpreter = constants.SETTINGS.value("python2_exe", "")

self.queue = Queue()
Expand Down
19 changes: 19 additions & 0 deletions src/urh/dev/gr/scripts/Initializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys

import os
import tempfile


def init_path():
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))

try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin") + os.pathsep + os.environ["PATH"]
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/airspy_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import tempfile
import os
import sys
import Initializer

try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/bladerf_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/bladerf_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/funcube-dongle_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/hackrf_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/hackrf_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/rtl-sdr_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/sdrplay_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio.eng_option import eng_option
Expand Down
16 changes: 2 additions & 14 deletions src/urh/dev/gr/scripts/usrp_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
##################################################

from optparse import OptionParser
import Initializer

import tempfile
import os
import sys
try:
with open(os.path.join(tempfile.gettempdir(), "gnuradio_path.txt"), "r") as f:
gnuradio_path = f.read().strip()

os.environ["PATH"] = os.path.join(gnuradio_path, "bin")
# Append script path at end to prevent conflicts in case of frozen interpreter
sys.path.append(sys.path.pop(0))
sys.path.insert(0, os.path.join(gnuradio_path, "lib", "site-packages"))

except IOError:
pass
Initializer.init_path()

from gnuradio import gr
from gnuradio import uhd
Expand Down
Loading