comparison frontends/src/jp/cmd_blog.py @ 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
comparison
equal deleted inserted replaced
1886:f3db27508b31 1887:16527dd5a81b
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat.core.constants import Const as C 23 from sat.core.constants import Const as C
24 from sat.tools import config 24 from sat.tools import config
25 from ConfigParser import NoSectionError, NoOptionError 25 from ConfigParser import NoSectionError, NoOptionError
26 import json 26 import json
27 import sys
27 import os.path 28 import os.path
28 import os 29 import os
29 import time 30 import time
30 import tempfile 31 import tempfile
31 import subprocess 32 import subprocess
122 def __init__(self, host): 123 def __init__(self, host):
123 super(Edit, self).__init__(host, 'edit', use_verbose=True, help=_(u'edit an existing or new blog post')) 124 super(Edit, self).__init__(host, 'edit', use_verbose=True, help=_(u'edit an existing or new blog post'))
124 125
125 def add_parser_options(self): 126 def add_parser_options(self):
126 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword")) 127 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword"))
128 self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel"))
127 self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item")) 129 self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item"))
128 self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item")) 130 self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item"))
129 self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments")) 131 self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments"))
130 132
131 def getTmpFile(self, sat_conf, tmp_suff): 133 def getTmpFile(self, sat_conf, tmp_suff):
209 # then we calculate hashes to check for modifications 211 # then we calculate hashes to check for modifications
210 import hashlib 212 import hashlib
211 content_file_obj.seek(0) 213 content_file_obj.seek(0)
212 tmp_ori_hash = hashlib.sha1(content_file_obj.read()).digest() 214 tmp_ori_hash = hashlib.sha1(content_file_obj.read()).digest()
213 content_file_obj.close() 215 content_file_obj.close()
216
217 # do we need a preview ?
218 if self.args.preview:
219 self.disp(u"Preview requested, launching it", 1)
220 # we redirect outputs to /dev/null to avoid console pollution in editor
221 # if user wants to see messages, (s)he can call "blog preview" directly
222 DEVNULL = open(os.devnull, 'wb')
223 subprocess.Popen([sys.argv[0], "blog", "preview", "--inotify", "true", content_file_path], stdout=DEVNULL, stderr=subprocess.STDOUT)
214 224
215 # then we launch editor 225 # then we launch editor
216 editor = config.getConfig(sat_conf, 'jp', 'editor') or os.getenv('EDITOR', 'vi') 226 editor = config.getConfig(sat_conf, 'jp', 'editor') or os.getenv('EDITOR', 'vi')
217 try: 227 try:
218 # is there custom arguments in sat.conf ? 228 # is there custom arguments in sat.conf ?