comparison sat_frontends/jp/cmd_blog.py @ 2997:cf0dda0d4cda

jp (blog/edit): fail and show error message if --preview is not working
author Goffi <goffi@goffi.org>
date Fri, 12 Jul 2019 08:55:41 +0200
parents eafea3bcf111
children a1b98772af6b
comparison
equal deleted inserted replaced
2996:afad95f257c7 2997:cf0dda0d4cda
512 meta_ori, meta_file_path = self.buildMetadataFile(content_file_path, mb_data) 512 meta_ori, meta_file_path = self.buildMetadataFile(content_file_path, mb_data)
513 513
514 # do we need a preview ? 514 # do we need a preview ?
515 if self.args.preview: 515 if self.args.preview:
516 self.disp(u"Preview requested, launching it", 1) 516 self.disp(u"Preview requested, launching it", 1)
517 # we redirect outputs to /dev/null to avoid console pollution in editor 517 # we redirect stderr to stdout and capture output to avoid console pollution
518 # if user wants to see messages, (s)he can call "blog preview" directly 518 # in editor.
519 DEVNULL = open(os.devnull, "wb") 519 # If user wants to see messages, (s)he can call "blog preview" directly
520 subprocess.Popen( 520 try:
521 [ 521 subprocess.check_output(
522 sys.argv[0], 522 [
523 "blog", 523 sys.argv[0],
524 "preview", 524 "blog",
525 "--inotify", 525 "preview",
526 "true", 526 "--inotify",
527 "-p", 527 "true",
528 self.profile, 528 "-p",
529 content_file_path, 529 self.profile,
530 ], 530 content_file_path,
531 stdout=DEVNULL, 531 ],
532 stderr=subprocess.STDOUT, 532 stderr=subprocess.STDOUT,
533 ) 533 )
534 except Exception as e:
535 self.disp(u"Can't show preview: {msg}".format(
536 msg=e.output.decode('utf-8'), err=True))
537 sys.exit(e.returncode)
534 538
535 # we launch editor 539 # we launch editor
536 self.runEditor( 540 self.runEditor(
537 "blog_editor_args", 541 "blog_editor_args",
538 content_file_path, 542 content_file_path,