blog (jp/edit): added --preview option to launch a "blog preview" in parallel
This commit is contained in:
parent
8839f38813
commit
f74fd5552a
1 changed files with 10 additions and 0 deletions
|
|
@ -24,6 +24,7 @@ from sat.core.constants import Const as C
|
|||
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 @@ class Edit(base.CommandBase, BlogCommon):
|
|||
|
||||
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 @@ class Edit(base.CommandBase, BlogCommon):
|
|||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue