Mercurial > libervia-backend
comparison frontends/src/jp/cmd_blog.py @ 2273:5f0dbf42aa9c
jp (blog, common): various fixes in common and blog:
- parse_args has been moved to common
- cat_dir is converted to str on BaseEdit init, so it can be use to make str path for files manipulation
- fixed use of EDITOR_ARGS_MAGIC when use_metadata is False
- fixed unlink of metadata files when use_metadata is False
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 27 Jun 2017 19:38:22 +0200 |
parents | 2fae89f30b8d |
children | 4bc9a2c2d6c9 |
comparison
equal
deleted
inserted
replaced
2272:b5befe7722d3 | 2273:5f0dbf42aa9c |
---|---|
31 import os.path | 31 import os.path |
32 import os | 32 import os |
33 import time | 33 import time |
34 import tempfile | 34 import tempfile |
35 import subprocess | 35 import subprocess |
36 import shlex | |
37 from sat.tools.common import data_format | 36 from sat.tools.common import data_format |
38 | 37 |
39 __commands__ = ["Blog"] | 38 __commands__ = ["Blog"] |
40 | 39 |
41 # extensions to use with known syntaxes | 40 # extensions to use with known syntaxes |
45 "markdown": "md" | 44 "markdown": "md" |
46 } | 45 } |
47 | 46 |
48 | 47 |
49 CONF_SYNTAX_EXT = 'syntax_ext_dict' | 48 CONF_SYNTAX_EXT = 'syntax_ext_dict' |
50 BLOG_TMP_DIR=u"blog" | 49 BLOG_TMP_DIR = u"blog" |
51 # key to remove from metadata tmp file if they exist | 50 # key to remove from metadata tmp file if they exist |
52 KEY_TO_REMOVE_METADATA = ('id','content', 'content_xhtml', 'comments_node', 'comments_service', 'updated') | 51 KEY_TO_REMOVE_METADATA = ('id','content', 'content_xhtml', 'comments_node', 'comments_service', 'updated') |
53 | 52 |
54 URL_REDIRECT_PREFIX = 'url_redirect_' | 53 URL_REDIRECT_PREFIX = 'url_redirect_' |
55 INOTIFY_INSTALL = '"pip install inotify"' | 54 INOTIFY_INSTALL = '"pip install inotify"' |
94 if k and ext == v: | 93 if k and ext == v: |
95 return k | 94 return k |
96 | 95 |
97 # if not found, we use current syntax | 96 # if not found, we use current syntax |
98 return self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) | 97 return self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) |
99 | |
100 def parse_args(self, cmd_line, **format_kw): | |
101 """Parse command arguments | |
102 | |
103 @param cmd_line(unicode): command line as found in sat.conf | |
104 @param format_kw: keywords used for formmating | |
105 @return (list(unicode)): list of arguments to pass to subprocess function | |
106 """ | |
107 try: | |
108 # we split the arguments and add the known fields | |
109 # we split arguments first to avoid escaping issues in file names | |
110 return [a.format(**format_kw) for a in shlex.split(cmd_line)] | |
111 except ValueError as e: | |
112 self.disp(u"Couldn't parse editor cmd [{cmd}]: {reason}".format(cmd=cmd_line, reason=e)) | |
113 return [] | |
114 | 98 |
115 | 99 |
116 class Get(base.CommandBase, BlogCommon): | 100 class Get(base.CommandBase, BlogCommon): |
117 TEMPLATE = u"blog/articles.html" | 101 TEMPLATE = u"blog/articles.html" |
118 | 102 |
421 url = 'file:{}'.format(self.urllib.quote(self.preview_file_path)) | 405 url = 'file:{}'.format(self.urllib.quote(self.preview_file_path)) |
422 self.webbrowser.open_new_tab(url) | 406 self.webbrowser.open_new_tab(url) |
423 | 407 |
424 def _launchPreviewExt(self, cmd_line, opt_name): | 408 def _launchPreviewExt(self, cmd_line, opt_name): |
425 url = 'file:{}'.format(self.urllib.quote(self.preview_file_path)) | 409 url = 'file:{}'.format(self.urllib.quote(self.preview_file_path)) |
426 args = self.parse_args(cmd_line, url=url, preview_file=self.preview_file_path) | 410 args = common.parse_args(self.host, cmd_line, url=url, preview_file=self.preview_file_path) |
427 if not args: | 411 if not args: |
428 self.disp(u"Couln't find command in \"{name}\", abording".format(name=opt_name), error=True) | 412 self.disp(u"Couln't find command in \"{name}\", abording".format(name=opt_name), error=True) |
429 self.host.quit(1) | 413 self.host.quit(1) |
430 subprocess.Popen(args) | 414 subprocess.Popen(args) |
431 | 415 |