comparison sat_frontends/jp/cmd_bookmarks.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children fee60f17ebac
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 import base 20 from . import base
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 22
23 __commands__ = ["Bookmarks"] 23 __commands__ = ["Bookmarks"]
24 24
25 STORAGE_LOCATIONS = ('local', 'private', 'pubsub') 25 STORAGE_LOCATIONS = ('local', 'private', 'pubsub')
31 def add_parser_options(self, location_default='all'): 31 def add_parser_options(self, location_default='all'):
32 self.parser.add_argument('-l', '--location', type=str, choices=(location_default,) + STORAGE_LOCATIONS, default=location_default, help=_("storage location (default: %(default)s)")) 32 self.parser.add_argument('-l', '--location', type=str, choices=(location_default,) + STORAGE_LOCATIONS, default=location_default, help=_("storage location (default: %(default)s)"))
33 self.parser.add_argument('-t', '--type', type=str, choices=TYPES, default=TYPES[0], help=_("bookmarks type (default: %(default)s)")) 33 self.parser.add_argument('-t', '--type', type=str, choices=TYPES, default=TYPES[0], help=_("bookmarks type (default: %(default)s)"))
34 34
35 def _errback(self, failure): 35 def _errback(self, failure):
36 print (("Something went wrong: [%s]") % failure) 36 print((("Something went wrong: [%s]") % failure))
37 self.host.quit(1) 37 self.host.quit(1)
38 38
39 class BookmarksList(BookmarksCommon): 39 class BookmarksList(BookmarksCommon):
40 40
41 def __init__(self, host): 41 def __init__(self, host):
46 mess = [] 46 mess = []
47 for location in STORAGE_LOCATIONS: 47 for location in STORAGE_LOCATIONS:
48 if not data[location]: 48 if not data[location]:
49 continue 49 continue
50 loc_mess = [] 50 loc_mess = []
51 loc_mess.append(u"%s:" % location) 51 loc_mess.append("%s:" % location)
52 book_mess = [] 52 book_mess = []
53 for book_link, book_data in data[location].items(): 53 for book_link, book_data in list(data[location].items()):
54 name = book_data.get('name') 54 name = book_data.get('name')
55 autojoin = book_data.get('autojoin', 'false') == 'true' 55 autojoin = book_data.get('autojoin', 'false') == 'true'
56 nick = book_data.get('nick') 56 nick = book_data.get('nick')
57 book_mess.append(u"\t%s[%s%s]%s" % ((name+' ') if name else '', 57 book_mess.append("\t%s[%s%s]%s" % ((name+' ') if name else '',
58 book_link, 58 book_link,
59 u' (%s)' % nick if nick else '', 59 ' (%s)' % nick if nick else '',
60 u' (*)' if autojoin else '')) 60 ' (*)' if autojoin else ''))
61 loc_mess.append(u'\n'.join(book_mess)) 61 loc_mess.append('\n'.join(book_mess))
62 mess.append(u'\n'.join(loc_mess)) 62 mess.append('\n'.join(loc_mess))
63 63
64 print u'\n\n'.join(mess) 64 print('\n\n'.join(mess))
65 65
66 66
67 class BookmarksRemove(BookmarksCommon): 67 class BookmarksRemove(BookmarksCommon):
68 68
69 def __init__(self, host): 69 def __init__(self, host):
70 super(BookmarksRemove, self).__init__(host, 'remove', help=_('remove a bookmark')) 70 super(BookmarksRemove, self).__init__(host, 'remove', help=_('remove a bookmark'))
71 self.need_loop = True 71 self.need_loop = True
72 72
73 def add_parser_options(self): 73 def add_parser_options(self):
74 super(BookmarksRemove, self).add_parser_options() 74 super(BookmarksRemove, self).add_parser_options()
75 self.parser.add_argument('bookmark', type=base.unicode_decoder, help=_('jid (for muc bookmark) or url of to remove')) 75 self.parser.add_argument('bookmark', help=_('jid (for muc bookmark) or url of to remove'))
76 76
77 def start(self): 77 def start(self):
78 self.host.bridge.bookmarksRemove(self.args.type, self.args.bookmark, self.args.location, self.host.profile, callback = lambda: self.host.quit(), errback=self._errback) 78 self.host.bridge.bookmarksRemove(self.args.type, self.args.bookmark, self.args.location, self.host.profile, callback = lambda: self.host.quit(), errback=self._errback)
79 79
80 80
84 super(BookmarksAdd, self).__init__(host, 'add', help=_('add a bookmark')) 84 super(BookmarksAdd, self).__init__(host, 'add', help=_('add a bookmark'))
85 self.need_loop = True 85 self.need_loop = True
86 86
87 def add_parser_options(self): 87 def add_parser_options(self):
88 super(BookmarksAdd, self).add_parser_options(location_default='auto') 88 super(BookmarksAdd, self).add_parser_options(location_default='auto')
89 self.parser.add_argument('bookmark', type=base.unicode_decoder, help=_('jid (for muc bookmark) or url of to remove')) 89 self.parser.add_argument('bookmark', help=_('jid (for muc bookmark) or url of to remove'))
90 self.parser.add_argument('-n', '--name', type=base.unicode_decoder, help=_("bookmark name")) 90 self.parser.add_argument('-n', '--name', help=_("bookmark name"))
91 muc_group = self.parser.add_argument_group(_('MUC specific options')) 91 muc_group = self.parser.add_argument_group(_('MUC specific options'))
92 muc_group.add_argument('-N', '--nick', type=base.unicode_decoder, help=_('nickname')) 92 muc_group.add_argument('-N', '--nick', help=_('nickname'))
93 muc_group.add_argument('-a', '--autojoin', action='store_true', help=_('join room on profile connection')) 93 muc_group.add_argument('-a', '--autojoin', action='store_true', help=_('join room on profile connection'))
94 94
95 def start(self): 95 def start(self):
96 if self.args.type == 'url' and (self.args.autojoin or self.args.nick is not None): 96 if self.args.type == 'url' and (self.args.autojoin or self.args.nick is not None):
97 # XXX: Argparse doesn't seem to manage this case, any better way ? 97 # XXX: Argparse doesn't seem to manage this case, any better way ?
98 print _(u"You can't use --autojoin or --nick with --type url") 98 print(_("You can't use --autojoin or --nick with --type url"))
99 self.host.quit(1) 99 self.host.quit(1)
100 data = {} 100 data = {}
101 if self.args.autojoin: 101 if self.args.autojoin:
102 data['autojoin'] = 'true' 102 data['autojoin'] = 'true'
103 if self.args.nick is not None: 103 if self.args.nick is not None: