Projet

Général

Profil

0001-nanterre-pr-vient-les-erreurs-unicode-quand-on-pipe-.patch

Benjamin Dauvergne, 13 janvier 2020 11:49

Télécharger (4 ko)

Voir les différences:

Subject: [PATCH 1/2] =?UTF-8?q?nanterre:=20pr=C3=A9vient=20les=20erreurs?=
 =?UTF-8?q?=20unicode=20quand=20on=20pipe=20rsu-duplicates=20(#37038)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

 .../management/commands/rsu-duplicates.py     | 22 +++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
zoo/zoo_nanterre/management/commands/rsu-duplicates.py
16 16
# You should have received a copy of the GNU Affero General Public License
17 17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 18

  
19
from __future__ import unicode_literals
20

  
19 21
import sys
20 22
from decimal import Decimal
21 23
import datetime
......
101 103
            for t in find_duplicates(count=count, limit=limit, days=days, ids=ids,
102 104
                                     progression=True):
103 105
                if verbosity > 1:
104
                    print >>sys.stdout, (
106
                    self.stdout.write(
105 107
                        'New duplicates / persons scanned / persons total :'
106
                        ' %05d / %05d / %05d\r' % t),
107
                    sys.stdout.flush()
108
                        ' %05d / %05d / %05d\r' % t)
109
                    self.stdout.flush()
108 110
            if verbosity > 1:
109 111
                print
110 112
            if verbosity > 0 and t[0]:
111
                print 'Found %d new duplicates.' % t[0]
113
                self.stdout.write('Found %d new duplicates.' % t[0])
112 114
        elif command == 'delete':
113 115
            qs = Duplicate.objects.all()
114 116
            if limit:
......
120 122
                qs = qs[:count]
121 123
            if days:
122 124
                since = now() - datetime.timedelta(days=days)
123
                print 'Duplicates created after', since
125
                self.stdout.write('Duplicates created after', since)
124 126
                qs = qs.filter(created__gte=since)
125 127
            if false:
126 128
                qs = qs.filter(state=Duplicate.STATE_FALSE_POSITIVE)
......
133 135
                column_size = max(column_size, len(individu_caption(duplicate.first)),
134 136
                                  len(individu_caption(duplicate.second)))
135 137

  
138
            self.stdout.write('%d duplicates\n' % qs.count())
139

  
136 140
            if false:
137 141
                table = Table(['Declared false', 'ID', 'Name', 'ID', 'Name', 'Score'])
138 142
                table.add_rows([(d.modified.isoformat(), d.first_id, individu_caption(d.first),
......
142 146
                table.add_rows([(d.modified.isoformat(), d.first_id, individu_caption(d.first),
143 147
                                 d.second_id, individu_caption(d.second), d.content['dedup_choice'], d.score) for d in qs])
144 148

  
145
            print u'| %6s | %*s | %6s | %*s | %5s |' % (
149
            self.stdout.write('| %6s | %*s | %6s | %*s | %5s |' % (
146 150
                'ID',
147 151
                column_size,
148 152
                u'État civil',
......
150 154
                column_size,
151 155
                u'État civil',
152 156
                'Score',
153
            )
157
            ))
154 158
            for duplicate in qs:
155
                print '| %6d | %*s | %6d | %*s | %3d %% |' % (
159
                self.stdout.write('| %6d | %*s | %6d | %*s | %3d %% |' % (
156 160
                    duplicate.first_id,
157 161
                    column_size,
158 162
                    individu_caption(duplicate.first),
......
160 164
                    column_size,
161 165
                    individu_caption(duplicate.second),
162 166
                    duplicate.score * Decimal(100),
163
                )
167
                ))
164
-