From 02c380b399791da6fb5844897fe72d5e943bf572 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Thu, 16 Mar 2017 10:22:54 -0700 Subject: [PATCH] Enhanced self.appdir code to take care of both blank launch path as well as root launch path cases. --- BlocklyPropClient.py | 8 +++++--- BlocklyServer.py | 8 ++++++-- PropellerLoad.py | 12 +++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/BlocklyPropClient.py b/BlocklyPropClient.py index cdd8084..f7c99fc 100644 --- a/BlocklyPropClient.py +++ b/BlocklyPropClient.py @@ -64,13 +64,15 @@ def __init__(self, *args, **kwargs): self.app_version = "0.0" self.connected = False - # Path to where application was launched + # Find the path from which application was launched # realpath expands to full path if __file__ or sys.argv[0] contains just a filename self.appdir = os.path.dirname(os.path.realpath(__file__)) - if self.appdir == "": + if self.appdir == "" or self.appdir == "/": + # launch path is blank; try extracting from argv self.appdir = os.path.dirname(os.path.realpath(sys.argv[0])) + self.logger.info('Logging is enabled') - self.logger.info('Application launched from %s', self.appdir) + self.logger.info('BlocklyPropClient.py: Application launched from %s', self.appdir) # initialize config variables self.ip_address = tk.StringVar() diff --git a/BlocklyServer.py b/BlocklyServer.py index 1a894fd..2936daf 100644 --- a/BlocklyServer.py +++ b/BlocklyServer.py @@ -27,11 +27,15 @@ def __init__(self, version, queue): self.version = version self.queue = queue + + # Find the path from which application was launched # realpath expands to full path if __file__ or sys.argv[0] contains just a filename self.appdir = os.path.dirname(os.path.realpath(__file__)) - if self.appdir == "": + if self.appdir == "" or self.appdir == "/": + # launch path is blank; try extracting from argv self.appdir = os.path.dirname(os.path.realpath(sys.argv[0])) - self.logger.debug("Application started from: %s", self.appdir) + + self.logger.debug("BlocklyServer.py: Application started from: %s", self.appdir) queue.put((10, 'INFO', 'Server started')) diff --git a/PropellerLoad.py b/PropellerLoad.py index fe10815..09beba5 100644 --- a/PropellerLoad.py +++ b/PropellerLoad.py @@ -18,12 +18,13 @@ def __init__(self): self.logger = logging.getLogger('blockly.loader') self.logger.info('Creating loader logger.') - # Find the path to the application launch directory + # Find the path from which application was launched # realpath expands to full path if __file__ or sys.argv[0] contains just a filename self.appdir = os.path.dirname(os.path.realpath(__file__)) - if self.appdir == "": + if self.appdir == "" or self.appdir == "/": + # launch path is blank; try extracting from argv self.appdir = os.path.dirname(os.path.realpath(sys.argv[0])) - self.logger.debug("Application running from: %s", self.appdir) + self.logger.debug("PropellerLoad.py: Application running from: %s", self.appdir) self.propeller_load_executables = { "Windows": "/propeller-tools/windows/propeller-load.exe", @@ -72,9 +73,10 @@ def load(self, action, file_to_load, com_port): # Patch until we figure out why the __init__ is not getting called if not self.appdir or self.appdir == '': - # realpath expands to full path if __file__ or sys.argv[0] contains just a filename + # realpath expands to full path if __file__ or sys.argv[0] contains just a filename self.appdir = os.path.dirname(os.path.realpath(__file__)) - if self.appdir == "": + if self.appdir == "" or self.appdir == "/": + # launch path is blank; try extracting from argv self.appdir = os.path.dirname(os.path.realpath(sys.argv[0])) executable = self.appdir + self.propeller_load_executables[platform.system()]