comparison frontends/src/jp/cmd_blog.py @ 2327:dad500e7ae50

jp (blog/get): added "url" key, which compute xmpp: URL of items
author Goffi <goffi@goffi.org>
date Thu, 13 Jul 2017 21:13:35 +0200
parents 760df3a58c24
children 74c1dbabeec8
comparison
equal deleted inserted replaced
2326:91a14dab924d 2327:dad500e7ae50
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat_frontends.jp.constants import Const as C 23 from sat_frontends.jp.constants import Const as C
24 from sat_frontends.jp import common 24 from sat_frontends.jp import common
25 from sat.tools.common.ansi import ANSI as A 25 from sat.tools.common.ansi import ANSI as A
26 from sat.tools.common import data_objects 26 from sat.tools.common import data_objects
27 from sat.tools.common import uri
27 from sat.tools import config 28 from sat.tools import config
28 from ConfigParser import NoSectionError, NoOptionError 29 from ConfigParser import NoSectionError, NoOptionError
29 import json 30 import json
30 import sys 31 import sys
31 import os.path 32 import os.path
51 KEY_TO_REMOVE_METADATA = ('id','content', 'content_xhtml', 'comments_node', 'comments_service', 'updated') 52 KEY_TO_REMOVE_METADATA = ('id','content', 'content_xhtml', 'comments_node', 'comments_service', 'updated')
52 53
53 URL_REDIRECT_PREFIX = 'url_redirect_' 54 URL_REDIRECT_PREFIX = 'url_redirect_'
54 INOTIFY_INSTALL = '"pip install inotify"' 55 INOTIFY_INSTALL = '"pip install inotify"'
55 MB_KEYS = (u"id", 56 MB_KEYS = (u"id",
57 u"url",
56 u"atom_id", 58 u"atom_id",
57 u"updated", 59 u"updated",
58 u"published", 60 u"published",
59 u"language", 61 u"language",
60 u"comments", # this key is used for all comments* keys 62 u"comments", # this key is used for all comments* keys
64 u"author_email", 66 u"author_email",
65 u"author_jid_verified", 67 u"author_jid_verified",
66 u"content", 68 u"content",
67 u"content_xhtml", 69 u"content_xhtml",
68 u"title", 70 u"title",
69 u"title_xhtml") 71 u"title_xhtml",
72 )
70 OUTPUT_OPT_NO_HEADER = u'no-header' 73 OUTPUT_OPT_NO_HEADER = u'no-header'
71 74
72 75
73 class BlogCommon(object): 76 class BlogCommon(object):
74 77
141 return self.format_time(item['updated']) 144 return self.format_time(item['updated'])
142 145
143 def format_published(self, item, keys): 146 def format_published(self, item, keys):
144 return self.format_time(item['published']) 147 return self.format_time(item['published'])
145 148
149 def format_url(self, item, keys):
150 return uri.buildXMPPUri(u'pubsub',
151 subtype=u'microblog',
152 path=self.metadata[u'service'],
153 node=self.metadata[u'node'],
154 item=item[u'id'])
155
146 def get_keys(self): 156 def get_keys(self):
147 """return keys to display according to verbosity or explicit key request""" 157 """return keys to display according to verbosity or explicit key request"""
148 verbosity = self.args.verbose 158 verbosity = self.args.verbose
149 if self.args.keys: 159 if self.args.keys:
150 if not set(MB_KEYS).issuperset(self.args.keys): 160 if not set(MB_KEYS).issuperset(self.args.keys):
163 else: 173 else:
164 return MB_KEYS 174 return MB_KEYS
165 175
166 def default_output(self, data): 176 def default_output(self, data):
167 """simple key/value output""" 177 """simple key/value output"""
168 items, metadata = data 178 items, self.metadata = data
169 keys = self.get_keys() 179 keys = self.get_keys()
170 180
171 # k_cb use format_[key] methods for complex formattings 181 # k_cb use format_[key] methods for complex formattings
172 k_cb = {} 182 k_cb = {}
173 for k in keys: 183 for k in keys: