Mercurial > libervia-backend
diff sat_frontends/jp/cmd_roster.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 | 7c8773723200 |
children | fee60f17ebac |
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_roster.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat_frontends/jp/cmd_roster.py Tue Aug 13 19:08:41 2019 +0200 @@ -18,7 +18,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import base +from . import base from collections import OrderedDict from functools import partial from sat.core.i18n import _ @@ -43,7 +43,7 @@ self.host.bridge.getContacts(profile_key=self.host.profile, callback=self.gotContacts, errback=self.error) def error(self, failure): - print (_("Error while retrieving the contacts [%s]") % failure) + print((_("Error while retrieving the contacts [%s]") % failure)) self.host.quit(1) def ask_confirmation(self, no_sub, no_from, no_to): @@ -55,17 +55,17 @@ @return bool """ if no_sub: - print "There's no subscription between profile [%s] and the following contacts:" % self.host.profile - print " " + "\n ".join(no_sub) + print("There's no subscription between profile [%s] and the following contacts:" % self.host.profile) + print(" " + "\n ".join(no_sub)) if no_from: - print "There's no 'from' subscription between profile [%s] and the following contacts:" % self.host.profile - print " " + "\n ".join(no_from) + print("There's no 'from' subscription between profile [%s] and the following contacts:" % self.host.profile) + print(" " + "\n ".join(no_from)) if no_to: - print "There's no 'to' subscription between profile [%s] and the following contacts:" % self.host.profile - print " " + "\n ".join(no_to) + print("There's no 'to' subscription between profile [%s] and the following contacts:" % self.host.profile) + print(" " + "\n ".join(no_to)) message = "REMOVE them from profile [%s]'s roster" % self.host.profile while True: - res = raw_input("%s (y/N)? " % message) + res = input("%s (y/N)? " % message) if not res or res.lower() == 'n': return False if res.lower() == 'y': @@ -87,7 +87,7 @@ elif not to and self.args.no_to: no_to.append(contact) if not no_sub and not no_from and not no_to: - print "Nothing to do - there's a from and/or to subscription(s) between profile [%s] and each of its contacts" % self.host.profile + print("Nothing to do - there's a from and/or to subscription(s) between profile [%s] and each of its contacts" % self.host.profile) elif self.ask_confirmation(no_sub, no_from, no_to): for contact in no_sub + no_from + no_to: self.host.bridge.delContact(contact, profile_key=self.host.profile, callback=lambda __: None, errback=lambda failure: None) @@ -107,7 +107,7 @@ self.host.bridge.getContacts(profile_key=self.host.profile, callback=self.gotContacts, errback=self.error) def error(self, failure): - print (_("Error while retrieving the contacts [%s]") % failure) + print((_("Error while retrieving the contacts [%s]") % failure)) self.host.quit(1) def gotContacts(self, contacts): @@ -135,31 +135,31 @@ total_group_subscription += len(groups) if not groups: no_group += 1 - hosts = OrderedDict(sorted(hosts.items(), key=lambda item:-item[1])) + hosts = OrderedDict(sorted(list(hosts.items()), key=lambda item:-item[1])) - print - print "Total number of contacts: %d" % len(contacts) - print "Number of different hosts: %d" % len(hosts) - print - for host, count in hosts.iteritems(): - print "Contacts on {host}: {count} ({rate:.1f}%)".format(host=host, count=count, rate=100 * float(count) / len(contacts)) - print - print "Contacts with no 'from' subscription: %d" % no_from - print "Contacts with no 'to' subscription: %d" % no_to - print "Contacts with no subscription at all: %d" % no_sub - print - print "Total number of groups: %d" % len(unique_groups) + print() + print("Total number of contacts: %d" % len(contacts)) + print("Number of different hosts: %d" % len(hosts)) + print() + for host, count in hosts.items(): + print("Contacts on {host}: {count} ({rate:.1f}%)".format(host=host, count=count, rate=100 * float(count) / len(contacts))) + print() + print("Contacts with no 'from' subscription: %d" % no_from) + print("Contacts with no 'to' subscription: %d" % no_to) + print("Contacts with no subscription at all: %d" % no_sub) + print() + print("Total number of groups: %d" % len(unique_groups)) try: contacts_per_group = float(total_group_subscription) / len(unique_groups) except ZeroDivisionError: contacts_per_group = 0 - print "Average contacts per group: {:.1f}".format(contacts_per_group) + print("Average contacts per group: {:.1f}".format(contacts_per_group)) try: groups_per_contact = float(total_group_subscription) / len(contacts) except ZeroDivisionError: groups_per_contact = 0 - print "Average groups' subscriptions per contact: {:.1f}".format(groups_per_contact) - print "Contacts not assigned to any group: %d" % no_group + print("Average groups' subscriptions per contact: {:.1f}".format(groups_per_contact)) + print("Contacts not assigned to any group: %d" % no_group) self.host.quit() @@ -178,7 +178,7 @@ self.host.bridge.getContacts(profile_key=self.host.profile, callback=self.gotContacts, errback=self.error) def error(self, failure): - print (_("Error while retrieving the contacts [%s]") % failure) + print((_("Error while retrieving the contacts [%s]") % failure)) self.host.quit(1) def gotContacts(self, contacts): @@ -200,10 +200,10 @@ args.append("from" if C.bool(attrs["from"]) else "") args.append("to" if C.bool(attrs["to"]) else "") if self.args.name: - args.append(unicode(attrs.get("name", ""))) + args.append(str(attrs.get("name", ""))) if self.args.groups: - args.append(u"\t".join(groups) if groups else "") - print u";".join(["{}"] * field_count).format(*args).encode("utf-8") + args.append("\t".join(groups) if groups else "") + print(";".join(["{}"] * field_count).format(*args).encode("utf-8")) self.host.quit() @@ -211,14 +211,14 @@ def __init__(self, host): super(Resync, self).__init__( - host, 'resync', help=_(u'do a full resynchronisation of roster with server')) + host, 'resync', help=_('do a full resynchronisation of roster with server')) self.need_loop = True def add_parser_options(self): pass def rosterResyncCb(self): - self.disp(_(u"Roster resynchronized")) + self.disp(_("Roster resynchronized")) self.host.quit(C.EXIT_OK) def start(self): @@ -226,7 +226,7 @@ callback=self.rosterResyncCb, errback=partial( self.errback, - msg=_(u"can't resynchronise roster: {}"), + msg=_("can't resynchronise roster: {}"), exit_code=C.EXIT_BRIDGE_ERRBACK, ))