summaryrefslogtreecommitdiff
path: root/grc/scripts
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2016-08-02 10:25:47 +0200
committerSebastian Koslowski <koslowski@kit.edu>2016-08-02 10:25:47 +0200
commit3c6c89c7008f5635b2fd1c8ded12ec0efeb1e6d8 (patch)
treee5e62ea743e6bda011fcd284c99eb04b96fe719f /grc/scripts
parent14bee91d2e3123703c48172d35f36e1d37a1d9d9 (diff)
grc: move startup checks into gnuradio-companion script
...where they have before some of the refactoring work. While having them in a separate file is cleaner, we can't do anything if they can't loaded from there in the first place.
Diffstat (limited to 'grc/scripts')
-rwxr-xr-xgrc/scripts/gnuradio-companion91
1 files changed, 76 insertions, 15 deletions
diff --git a/grc/scripts/gnuradio-companion b/grc/scripts/gnuradio-companion
index 04a1cb44e7..34bb0bf110 100755
--- a/grc/scripts/gnuradio-companion
+++ b/grc/scripts/gnuradio-companion
@@ -20,19 +20,80 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os
import sys
+import warnings
-script_path = os.path.dirname(os.path.abspath(__file__))
-source_tree_subpath = "/grc/scripts"
-
-if not script_path.endswith(source_tree_subpath):
- # run the installed version
- from gnuradio.grc.main import main
- from gnuradio.grc import checks
-else:
- print("Running from source tree")
- sys.path.insert(1, script_path[:-len(source_tree_subpath)])
- from grc.main import main
- from grc import checks
-
-checks.do_all()
-exit(main())
+
+GR_IMPORT_ERROR_MESSAGE = """\
+Cannot import gnuradio.
+
+Is the model path environment variable set correctly?
+ All OS: PYTHONPATH
+
+Is the library path environment variable set correctly?
+ Linux: LD_LIBRARY_PATH
+ Windows: PATH
+ MacOSX: DYLD_LIBRARY_PATH
+"""
+
+
+def die(error, message):
+ msg = "{0}\n\n({1})".format(message, error)
+ try:
+ import gtk
+ d = gtk.MessageDialog(
+ type=gtk.MESSAGE_ERROR,
+ buttons=gtk.BUTTONS_CLOSE,
+ message_format=msg,
+ )
+ d.set_title(type(error).__name__)
+ d.run()
+ exit(1)
+ except ImportError:
+ exit(type(error).__name__ + '\n\n' + msg)
+
+
+def check_gtk():
+ try:
+ warnings.filterwarnings("error")
+ import pygtk
+ pygtk.require('2.0')
+ import gtk
+ gtk.init_check()
+ warnings.filterwarnings("always")
+ except Exception as err:
+ die(err, "Failed to initialize GTK. If you are running over ssh, "
+ "did you enable X forwarding and start ssh with -X?")
+
+
+def check_gnuradio_import():
+ try:
+ from gnuradio import gr
+ except ImportError as err:
+ die(err, GR_IMPORT_ERROR_MESSAGE)
+
+
+def check_blocks_path():
+ if 'GR_DONT_LOAD_PREFS' in os.environ and not os.environ.get('GRC_BLOCKS_PATH', ''):
+ die(EnvironmentError("No block definitions available"),
+ "Can't find block definitions. Use config.conf or GRC_BLOCKS_PATH.")
+
+
+def run_main():
+ script_path = os.path.dirname(os.path.abspath(__file__))
+ source_tree_subpath = "/grc/scripts"
+
+ if not script_path.endswith(source_tree_subpath):
+ # run the installed version
+ from gnuradio.grc.main import main
+ else:
+ print("Running from source tree")
+ sys.path.insert(1, script_path[:-len(source_tree_subpath)])
+ from grc.main import main
+ exit(main())
+
+
+if __name__ == '__main__':
+ check_gnuradio_import()
+ check_gtk()
+ check_blocks_path()
+ run_main()