comparison frontends/src/jp/cmd_blog.py @ 1839:cdecf553e051

frontends (jp/blog), plugin blog_import: fixes: - argparse argument with nargs > 1 and default == {} crashes when reading the user input - separate blog import options with a new line - convert DBus strings received by the backend to unicode
author souliane <souliane@mailoo.org>
date Thu, 04 Feb 2016 11:44:43 +0100
parents 6209de5e3e25
children 9eabf7fadfdd
comparison
equal deleted inserted replaced
1838:b3b25dbac585 1839:cdecf553e051
35 self.parser.add_argument("importer", type=base.unicode_decoder, nargs='?', help=_(u"importer name, nothing to display importers list")) 35 self.parser.add_argument("importer", type=base.unicode_decoder, nargs='?', help=_(u"importer name, nothing to display importers list"))
36 self.parser.add_argument('--host', type=base.unicode_decoder, help=_(u"original blog host")) 36 self.parser.add_argument('--host', type=base.unicode_decoder, help=_(u"original blog host"))
37 self.parser.add_argument('--no-images-upload', action='store_true', help=_(u"do *NOT* upload images (default: do upload images)")) 37 self.parser.add_argument('--no-images-upload', action='store_true', help=_(u"do *NOT* upload images (default: do upload images)"))
38 self.parser.add_argument('--upload-ignore-host', help=_(u"do not upload images from this host (default: upload all images)")) 38 self.parser.add_argument('--upload-ignore-host', help=_(u"do not upload images from this host (default: upload all images)"))
39 self.parser.add_argument("--ignore-tls-errors", action="store_true", help=_("ignore invalide TLS certificate for uploads")) 39 self.parser.add_argument("--ignore-tls-errors", action="store_true", help=_("ignore invalide TLS certificate for uploads"))
40 self.parser.add_argument('-o', '--option', action='append', nargs=2, default={}, metavar=(u'NAME', u'VALUE'), 40 self.parser.add_argument('-o', '--option', action='append', nargs=2, default=[], metavar=(u'NAME', u'VALUE'),
41 help=_(u"importer specific options (see importer description)")) 41 help=_(u"importer specific options (see importer description)"))
42 self.parser.add_argument('--service', type=base.unicode_decoder, default=u'', metavar=u'PUBSUB_SERVICE', 42 self.parser.add_argument('--service', type=base.unicode_decoder, default=u'', metavar=u'PUBSUB_SERVICE',
43 help=_(u"PubSub service where the items must be uploaded (default: server)")) 43 help=_(u"PubSub service where the items must be uploaded (default: server)"))
44 self.parser.add_argument("location", type=base.unicode_decoder, nargs='?', 44 self.parser.add_argument("location", type=base.unicode_decoder, nargs='?',
45 help=_(u"importer data location (see importer description), nothing to show importer description")) 45 help=_(u"importer data location (see importer description), nothing to show importer description"))
75 if self.args.location is None: 75 if self.args.location is None:
76 for name in ('option', 'service', 'no_images_upload'): 76 for name in ('option', 'service', 'no_images_upload'):
77 if getattr(self.args, name): 77 if getattr(self.args, name):
78 self.parser.error(_(u"{name} argument can't be used without location argument").format(name=name)) 78 self.parser.error(_(u"{name} argument can't be used without location argument").format(name=name))
79 if self.args.importer is None: 79 if self.args.importer is None:
80 print u''.join([u'{}: {}'.format(name, desc) for name, desc in self.host.bridge.blogImportList()]) 80 print u'\n'.join([u'{}: {}'.format(name, desc) for name, desc in self.host.bridge.blogImportList()])
81 else: 81 else:
82 try: 82 try:
83 short_desc, long_desc = self.host.bridge.blogImportDesc(self.args.importer) 83 short_desc, long_desc = self.host.bridge.blogImportDesc(self.args.importer)
84 except Exception as e: 84 except Exception as e:
85 msg = [l for l in unicode(e).split('\n') if l][-1] # we only keep the last line 85 msg = [l for l in unicode(e).split('\n') if l][-1] # we only keep the last line
88 else: 88 else:
89 print u"{name}: {short_desc}\n\n{long_desc}".format(name=self.args.importer, short_desc=short_desc, long_desc=long_desc) 89 print u"{name}: {short_desc}\n\n{long_desc}".format(name=self.args.importer, short_desc=short_desc, long_desc=long_desc)
90 self.host.quit() 90 self.host.quit()
91 else: 91 else:
92 # we have a location, an import is requested 92 # we have a location, an import is requested
93 options = dict(self.args.option) 93 options = {key: value for key, value in self.args.option}
94 if self.args.host: 94 if self.args.host:
95 options['host'] = self.args.host 95 options['host'] = self.args.host
96 if self.args.ignore_tls_errors: 96 if self.args.ignore_tls_errors:
97 options['ignore_tls_errors'] = C.BOOL_TRUE 97 options['ignore_tls_errors'] = C.BOOL_TRUE
98 if self.args.no_images_upload: 98 if self.args.no_images_upload: