# HG changeset patch # User Goffi # Date 1457205557 -3600 # Node ID 16527dd5a81ba835f9da0e91ee45489967c929f5 # Parent f3db27508b31bf0a3e470f3d981b20a1d05d7bd0 blog (jp/edit): added --preview option to launch a "blog preview" in parallel diff -r f3db27508b31 -r 16527dd5a81b frontends/src/jp/cmd_blog.py --- a/frontends/src/jp/cmd_blog.py Sat Mar 05 19:24:10 2016 +0100 +++ b/frontends/src/jp/cmd_blog.py Sat Mar 05 20:19:17 2016 +0100 @@ -24,6 +24,7 @@ from sat.tools import config from ConfigParser import NoSectionError, NoOptionError import json +import sys import os.path import os import time @@ -124,6 +125,7 @@ def add_parser_options(self): self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword")) + self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel")) self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item")) self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item")) self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments")) @@ -212,6 +214,14 @@ tmp_ori_hash = hashlib.sha1(content_file_obj.read()).digest() content_file_obj.close() + # do we need a preview ? + if self.args.preview: + self.disp(u"Preview requested, launching it", 1) + # we redirect outputs to /dev/null to avoid console pollution in editor + # if user wants to see messages, (s)he can call "blog preview" directly + DEVNULL = open(os.devnull, 'wb') + subprocess.Popen([sys.argv[0], "blog", "preview", "--inotify", "true", content_file_path], stdout=DEVNULL, stderr=subprocess.STDOUT) + # then we launch editor editor = config.getConfig(sat_conf, 'jp', 'editor') or os.getenv('EDITOR', 'vi') try: