Skip to content

Commit

Permalink
Enhanced self.appdir code to take care of both blank launch path as w…
Browse files Browse the repository at this point in the history
…ell as root launch path cases.
  • Loading branch information
PropGit committed Mar 16, 2017
1 parent 8d4146c commit 02c380b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions BlocklyPropClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions BlocklyServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
12 changes: 7 additions & 5 deletions PropellerLoad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()]
Expand Down

0 comments on commit 02c380b

Please sign in to comment.