Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Error messages from stderr with scripts and included_workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Dec 4, 2017
1 parent 1bf1ae6 commit c42baf9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Imagr/Info.plist
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.10</string>
<string>1.4.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
29 changes: 23 additions & 6 deletions Imagr/MainController.py
Expand Up @@ -938,24 +938,34 @@ def getIncludedWorkflow(self, item):
target_workflow = None

if 'script' in item:
output_list = []
if progress_method:
progress_method("Running script to determine included workflow...", -1, '')
script = Utils.replacePlaceholders(item.get('script'), self.targetVolume.mountpoint)
script_file = tempfile.NamedTemporaryFile(delete=False)
script_file.write(script)
script_file.close()
os.chmod(script_file.name, 0700)

proc = subprocess.Popen(script_file.name, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
while proc.poll() is None:
output = proc.stdout.readline().strip().decode('UTF-8')
output_list.append(output)
if proc.stderr.readline():
stderr = proc.stderr.readline().strip.decode('UTF-8')
if stderr != '':
output_list.append(stderr)
if progress_method:
progress_method(None, None, output)
os.remove(script_file.name)

(out, err) = proc.communicate()
if proc.returncode != 0:
if err == None:
err = 'Unknown'
Utils.sendReport('error', 'Could not run included workflow script: %s' % err)
self.errorMessage = 'Could not run included workflow script: %s' % err
error_output = '\n'.join(output_list)
Utils.sendReport('error', 'Could not run included workflow script: %s' % error_output)
self.errorMessage = 'Could not run included workflow script: %s' % error_output
return
else:
for line in out.splitlines():
for line in output_list:
if line.startswith("ImagrIncludedWorkflow: ") or line.startswith("ImagrIncludedWorkflow:"):
included_workflow = line.replace("ImagrIncludedWorkflow: ", "").replace("ImagrIncludedWorkflow:", "").strip()
break
Expand Down Expand Up @@ -1241,6 +1251,9 @@ def RAMDisk(self, source, imaging=False):
else:
dmgsource = source.get('url')
NSLog(u"Downloading DMG file from %@", str(dmgsource))
download_string = 'Downloading {}...'.format(str(dmgsource))
self.updateProgressTitle_Percent_Detail_(
download_string, -1, '')
sourceram = self.downloadDMG(dmgsource, targetpath)
if sourceram is False:
NSLog(u"Detaching RAM Disk due to failure.")
Expand Down Expand Up @@ -1459,6 +1472,10 @@ def runScript(self, script, target, progress_method=None):
while proc.poll() is None:
output = proc.stdout.readline().strip().decode('UTF-8')
output_list.append(output)
if proc.stderr.readline():
stderr = proc.stderr.readline().strip().decode('UTF-8')
if stderr != '':
output_list.append(stderr)
if progress_method:
progress_method(None, None, output)
os.remove(script_file.name)
Expand Down

0 comments on commit c42baf9

Please sign in to comment.