From 9e13d07b6e328d9c991f68ccc1ca19eaf882597c Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Wed, 1 May 2013 14:16:12 +0200 Subject: [PATCH] BUGFIX: Invoking Scyther scripts from non-standard directories or using symlinks should work consistently now. Before, we were using both __file__ as well as sys.argv[0] to determine the base directory for Scyther, and we were not taking symlinks into account. By using the inspect module, we can consistently pick the current frame and derive the file from that, then use realpath to strip symlinks. --- gui/Gui/Icon.py | 7 ++++++- gui/Gui/Misc.py | 6 +++++- gui/Scyther/Misc.py | 4 +++- gui/scyther-gui.py | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gui/Gui/Icon.py b/gui/Gui/Icon.py index 60919e2..036e145 100644 --- a/gui/Gui/Icon.py +++ b/gui/Gui/Icon.py @@ -35,7 +35,12 @@ import Misc def ScytherIcon(window): """ Set a nice Scyther icon """ - basedir = os.path.abspath(os.path.dirname(sys.argv[0])) + import os,inspect + + # Determine base directory (taking symbolic links into account) + cmd_file = os.path.realpath(os.path.abspath(inspect.getfile( inspect.currentframe() ))) + basedir = os.path.split(cmd_file)[0] + path = os.path.join(basedir,"Images") iconfile = Misc.mypath(os.path.join(path,"scyther-gui-32.ico")) if os.path.isfile(iconfile): diff --git a/gui/Gui/Misc.py b/gui/Gui/Misc.py index b60d8e9..ba2bc5b 100644 --- a/gui/Gui/Misc.py +++ b/gui/Gui/Misc.py @@ -60,7 +60,11 @@ def sorted(li): def mypath(file): """ Construct a file path relative to the scyther-gui main directory """ - basedir = os.path.dirname(__file__) + import os, inspect + + # Determine base directory (taking symbolic links into account) + cmd_file = os.path.realpath(os.path.abspath(inspect.getfile( inspect.currentframe() ))) + basedir = os.path.split(cmd_file)[0] return os.path.join(basedir,file) # commands: push data in, get fp.write out diff --git a/gui/Scyther/Misc.py b/gui/Scyther/Misc.py index cf37b0b..503dfc2 100644 --- a/gui/Scyther/Misc.py +++ b/gui/Scyther/Misc.py @@ -84,7 +84,9 @@ def ensurePath(pt): def mypath(file): """ Construct a file path relative to the scyther-gui main directory """ - basedir = os.path.dirname(__file__) + # Determine base directory (taking symbolic links into account) + cmd_file = os.path.realpath(os.path.abspath(inspect.getfile( inspect.currentframe() ))) + basedir = os.path.split(cmd_file)[0] return os.path.join(basedir,file) def getShell(): diff --git a/gui/scyther-gui.py b/gui/scyther-gui.py index 1a6a0c7..ff7577a 100755 --- a/gui/scyther-gui.py +++ b/gui/scyther-gui.py @@ -179,11 +179,15 @@ def isSplashNeeded(opts): class ScytherApp(wx.App): def OnInit(self): + import os, inspect wx.GetApp().SetAppName("Scyther-gui") + # Determine base directory (taking symbolic links into account) + cmd_file = os.path.realpath(os.path.abspath(inspect.getfile( inspect.currentframe() ))) + basedir = os.path.split(cmd_file)[0] + # Parse arguments - basedir = os.path.abspath(os.path.dirname(sys.argv[0])) (opts,args) = parseArgs() # License option may abort here