jp (blog/edit): a draft file can be directly specified
This commit is contained in:
parent
27cd8412d5
commit
3ab15a6aee
1 changed files with 27 additions and 26 deletions
|
|
@ -295,40 +295,41 @@ class Edit(base.CommandBase, BlogCommon):
|
|||
SYNTAX_EXT.update(config.getConfig(sat_conf, 'jp', CONF_SYNTAX_EXT, {}))
|
||||
current_syntax = None
|
||||
|
||||
if item_lower == 'current':
|
||||
# use wants to continue current draft
|
||||
content_file_path = self.getCurrentFile(sat_conf)
|
||||
content_file_obj = open(content_file_path, 'r+b')
|
||||
current_syntax = self.guessSyntaxFromPath(sat_conf, content_file_path)
|
||||
else:
|
||||
if item_lower in ('new', 'last'):
|
||||
# we get current syntax to determine file extension
|
||||
current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile)
|
||||
# we now create a temporary file
|
||||
tmp_suff = '.' + SYNTAX_EXT.get(current_syntax, SYNTAX_EXT[''])
|
||||
content_file_obj, content_file_path = self.getTmpFile(sat_conf, tmp_suff)
|
||||
if item_lower == 'new':
|
||||
self.disp(u'Editing a new blog item', 2)
|
||||
mb_data = None
|
||||
elif item_lower == 'last':
|
||||
self.disp(u'Editing last published item', 2)
|
||||
try:
|
||||
mb_data = self.host.bridge.mbGet('', '', 1, [], {}, self.profile)[0][0]
|
||||
except Exception as e:
|
||||
self.disp(u"Error while retrieving last item: {}".format(e))
|
||||
self.host.quit(1)
|
||||
|
||||
content = mb_data['content_xhtml']
|
||||
if content and current_syntax != 'XHTML':
|
||||
content = self.host.bridge.syntaxConvert(content, 'XHTML', current_syntax, False, self.profile)
|
||||
content_file_obj.write(content.encode('utf-8'))
|
||||
content_file_obj.seek(0)
|
||||
else:
|
||||
mb_data = None
|
||||
if item_lower == 'current':
|
||||
# use wants to continue current draft
|
||||
content_file_path = self.getCurrentFile(sat_conf)
|
||||
self.disp(u'Continuing edition of current draft', 2)
|
||||
else:
|
||||
# for now we taxe the item as a file path
|
||||
content_file_path = os.path.expanduser(self.args.item)
|
||||
content_file_obj = open(content_file_path, 'r+b')
|
||||
current_syntax = self.guessSyntaxFromPath(sat_conf, content_file_path)
|
||||
|
||||
self.disp(u"Syntax used: {}".format(current_syntax), 1)
|
||||
|
||||
if item_lower == 'new':
|
||||
self.disp(u'Editing a new blog item', 2)
|
||||
mb_data = None
|
||||
elif item_lower == 'current':
|
||||
self.disp(u'Continuing edition of current draft', 2)
|
||||
mb_data = None
|
||||
elif item_lower == 'last':
|
||||
self.disp(u'Editing last published item', 2)
|
||||
try:
|
||||
mb_data = self.host.bridge.mbGet('', '', 1, [], {}, self.profile)[0][0]
|
||||
except Exception as e:
|
||||
self.disp(u"Error while retrieving last item: {}".format(e))
|
||||
self.host.quit(1)
|
||||
|
||||
content = mb_data['content_xhtml']
|
||||
if content and current_syntax != 'XHTML':
|
||||
content = self.host.bridge.syntaxConvert(content, 'XHTML', current_syntax, False, self.profile)
|
||||
content_file_obj.write(content.encode('utf-8'))
|
||||
content_file_obj.seek(0)
|
||||
|
||||
self.edit(sat_conf, content_file_path, content_file_obj, mb_data=mb_data)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue