jp (blog): import now show progression + value to add to sat.conf for URLs redirection

This commit is contained in:
Goffi 2016-01-24 18:24:01 +01:00
commit 13d24075c1

View file

@ -21,13 +21,15 @@
import base
from sat.core.i18n import _
from sat.core.constants import Const as C
import json
URL_REDIRECT_PREFIX = 'url_redirect_'
__commands__ = ["Blog"]
class Import(base.CommandBase):
def __init__(self, host):
super(Import, self).__init__(host, 'import', help=_(u'import an external blog'))
super(Import, self).__init__(host, 'import', use_progress=True, help=_(u'import an external blog'))
def add_parser_options(self):
self.parser.add_argument("importer", type=base.unicode_decoder, nargs='?', help=_(u"importer name, nothing to display importers list"))
@ -42,9 +44,34 @@ class Import(base.CommandBase):
self.parser.add_argument("location", type=base.unicode_decoder, nargs='?',
help=_(u"importer data location (see importer description), nothing to show importer description"))
def onProgressStarted(self, metadata):
self.disp(_(u'Blog upload started'),2)
def onProgressFinished(self, metadata):
self.disp(_(u'Blog uploaded successfully'),2)
redirections = {k[len(URL_REDIRECT_PREFIX):]:v for k,v in metadata.iteritems()
if k.startswith(URL_REDIRECT_PREFIX)}
if redirections:
conf = u'\n'.join([
u'url_redirections_profile = {}'.format(self.profile),
u"url_redirections_dict = {}".format(
# we need to add ' ' before each new line and to double each '%' for ConfigParser
u'\n '.join(json.dumps(redirections, indent=1, separators=(',',': ')).replace(u'%', u'%%').split(u'\n'))),
])
self.disp(_(u'\nTo redirect old URLs to new ones, put the following lines in your sat.conf file, in [libervia] section:\n\n{conf}'.format(conf=conf)))
def onProgressError(self, error_msg):
self.disp(_(u'Error while uploading blog: {}').format(error_msg),error=True)
def error(self, failure):
self.disp(_("Error while trying to upload a blog: {reason}").format(reason=failure), error=True)
self.host.quit(1)
def connected(self):
"""Send files to jabber contact"""
self.need_loop=True
super(Import, self).connected()
if self.args.location is None:
for name in ('option', 'service', 'no_images_upload'):
if getattr(self.args, name):
@ -74,11 +101,10 @@ class Import(base.CommandBase):
self.parser.error(u"upload-ignore-host option can't be used when no-images-upload is set")
elif self.args.upload_ignore_host:
options['upload_ignore_host'] = self.args.upload_ignore_host
try:
self.host.bridge.blogImport(self.args.importer, self.args.location, options, self.args.service, self.profile)
except Exception as e:
print e
self.host.quit(1)
def gotId(id_):
self.progress_id = id_
self.host.bridge.blogImport(self.args.importer, self.args.location, options, self.args.service, self.profile,
callback=gotId, errback=self.error)
class Blog(base.CommandBase):