changeset 1887:16527dd5a81b

blog (jp/edit): added --preview option to launch a "blog preview" in parallel
author Goffi <goffi@goffi.org>
date Sat, 05 Mar 2016 20:19:17 +0100
parents f3db27508b31
children 7b9cdde29d8b
files frontends/src/jp/cmd_blog.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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: