@@ -58,14 +58,14 @@ def get_ports(self):
5858 self .logger .info ("Generating ports list" )
5959
6060 # Get COM ports
61- success , out , err = loader (self , "-P" )
61+ success , out , err = loader (self , [ "-P" ] )
6262 if success :
6363 self .ports = out .splitlines ()
6464 else :
6565 self .logger .debug ('COM Port request returned %s' , err )
6666
6767 # Get Wi-Fi ports
68- success , out , err = loader (self , "-W" )
68+ success , out , err = loader (self , [ "-W" ] )
6969 if success :
7070 self .wports = out .splitlines ()
7171 # Extract Wi-Fi module names and sort them
@@ -94,7 +94,11 @@ def download(self, action, file_to_load, com_port):
9494 self .appdir = os .path .dirname (os .path .realpath (sys .argv [0 ]))
9595
9696 # Set command download to RAM or EEPROM and run afterwards
97- command = [self .loaderAction [action ]["compile-options" ], "-r" ]
97+ command = []
98+ if self .loaderAction [action ]["compile-options" ] != "" :
99+ # if RAM/EEPROM compile-option not empty, add it to the list
100+ command .extend ([self .loaderAction [action ]["compile-options" ]])
101+ command .extend (["-r" ])
98102
99103 # Add requested port
100104 if com_port is not None :
@@ -120,18 +124,25 @@ def download(self, action, file_to_load, com_port):
120124
121125def loader (self , cmdOptions ):
122126 # Launch Propeller Loader with cmdOptions and return True/False, output and error string
127+ # cmdOptions must be a list
123128 try :
124- self .logger .debug ('Loader command: %s' , self .appdir + self .loaderExe [platform .system ()] + ' ' + str (cmdOptions ))
129+ # Form complete command line as a list: [path+exe, option {,more_options...} {, filename}]
130+ cmdLine = [self .appdir + self .loaderExe [platform .system ()]]
131+ cmdLine .extend (cmdOptions )
125132
133+ self .logger .info ('Running loader command: %s' , cmdLine )
134+
135+ # Run command
126136 if platform .system () == "Windows" :
127137 startupinfo = subprocess .STARTUPINFO ()
128138 startupinfo .dwFlags |= subprocess .STARTF_USESHOWWINDOW
129- process = subprocess .Popen ([ self . appdir + self . loaderExe [ platform . system ()], cmdOptions ] , stdout = subprocess .PIPE , stderr = subprocess .PIPE , startupinfo = startupinfo )
139+ process = subprocess .Popen (cmdLine , stdout = subprocess .PIPE , stderr = subprocess .PIPE , startupinfo = startupinfo )
130140 else :
131- process = subprocess .Popen ([ self . appdir + self . loaderExe [ platform . system ()], cmdOptions ] , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
141+ process = subprocess .Popen (cmdLine , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
132142
133143 out , err = process .communicate ()
134144
145+ # If error, log extra error detail
135146 if process .returncode :
136147 self .logger .error ("Error result: %s - %s" , process .returncode , err )
137148 self .logger .debug ("Loader response: %s" , out )
@@ -144,6 +155,7 @@ def loader(self, cmdOptions):
144155 return success , out or '' , err or ''
145156
146157 except OSError as ex :
158+ # Exception; log error and return fail status
147159 self .logger .error ("%s" , ex .message )
148160 return False , '' , 'Exception: OSError'
149161
0 commit comments