# HG changeset patch # User Goffi # Date 1492358445 -7200 # Node ID 301bb52c8715f72975a45d22a618695c99849adb # Parent 87fcd4a7c7e429402e096ed60dcb9c0322987c0a jp (blog): service and node can now be specified for edit command diff -r 87fcd4a7c7e4 -r 301bb52c8715 frontends/src/jp/cmd_blog.py --- a/frontends/src/jp/cmd_blog.py Sun Apr 16 17:59:54 2017 +0200 +++ b/frontends/src/jp/cmd_blog.py Sun Apr 16 18:00:45 2017 +0200 @@ -68,7 +68,6 @@ SECURE_UNLINK_MAX = 10 * 2 # we double value as there are 2 files per draft (content and metadata) SECURE_UNLINK_DIR = ".backup" HEADER_ANSI = A.BOLD + A.FG_YELLOW -NS_MICROBLOG = u'urn:xmpp:microblog:0' MB_KEYS = (u"id", u"atom_id", u"updated", @@ -91,6 +90,10 @@ def __init__(self, host): self.host = host + def addServiceNodeArgs(self): + self.parser.add_argument("-n", "--node", type=base.unicode_decoder, default=u'', help=_(u"PubSub node to request (default: microblog namespace)")) + self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', help=_(u"JID of the PubSub service (default: request profile own blog)")) + def getTmpDir(self, sat_conf, sub_dir=None): """Return directory used to store temporary files @@ -188,25 +191,24 @@ return [] -class Get(base.CommandBase): +class Get(base.CommandBase, BlogCommon): TEMPLATE = u"blog/articles.html" def __init__(self, host): extra_outputs = {'default': self.default_output, 'fancy': self.fancy_output} base.CommandBase.__init__(self, host, 'get', use_verbose=True, use_output='complex', extra_outputs=extra_outputs, help=_(u'get blog item(s)')) + BlogCommon.__init__(self, self.host) self.need_loop=True def add_parser_options(self): - self.parser.add_argument("-n", "--node", type=base.unicode_decoder, default=NS_MICROBLOG, help=_(u"PubSub node to request")) + self.addServiceNodeArgs() self.parser.add_argument("-i", "--item", type=base.unicode_decoder, action='append', default=[], dest='items', help=_(u"item(s) id(s) to get (default: request all items)")) self.parser.add_argument("-m", "--max", type=int, default=10, help=_(u"maximum number of items to get ({} to get all items)".format(C.NO_LIMIT))) # TODO: a key(s) argument to select keys to display self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys', help=_(u"microblog data key(s) to display (default: depend of verbosity)")) - self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'', - help=_(u"JID of the PubSub service (default: request profile own blog)")) # TODO: add MAM filters def template_data_mapping(self, data): @@ -370,6 +372,7 @@ BlogCommon.__init__(self, self.host) def add_parser_options(self): + self.addServiceNodeArgs() self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword")) self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel")) self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item")) @@ -547,7 +550,8 @@ # if there are user defined extension, we use them SYNTAX_EXT.update(config.getConfig(sat_conf, 'jp', CONF_SYNTAX_EXT, {})) current_syntax = None - pubsub_service = pubsub_node = '' + pubsub_service = self.args.service + pubsub_node = self.args.node pubsub_item = None if command not in ('new', 'last', 'current'): @@ -573,6 +577,9 @@ parsed_url = urlparse.urlsplit(url) if parsed_url.scheme == 'xmpp': + if self.args.service or self.args.node: + self.parser.error(_(u"You can't use URI and --service or --node at the same time")) + self.disp(u"XMPP URI used: {}".format(url),2) # XXX: if we have not xmpp: URI here, we'll take the data as a file path pubsub_service = parsed_url.path