Mercurial > p > roundup > code
annotate roundup/dist/command/build.py @ 5543:bc3e00a3d24b
MySQL backend fixes for Python 3.
With Python 2, text sent to and from MySQL is treated as bytes in
Python. The database may be recorded by MySQL as having some other
encoding (latin1 being the default in some MySQL versions - Roundup
does not set an encoding explicitly, unlike in back_postgresql), but
as long as MySQL's notion of the connection encoding agrees with its
notion of the database encoding, no conversions actually take place
and the bytes are stored and returned as-is.
With Python 3, text sent to and from MySQL is treated as Python
Unicode strings. When the database and connection encoding is latin1,
that means the bytes stored in the database under Python 2 are
interpreted as latin1 and converted from that to Unicode, producing
incorrect results for any non-ASCII characters; furthermore, if trying
to store new non-ASCII data in the database under Python 3, any
non-latin1 characters produce errors.
This patch arranges for both the connection and database character
sets to be UTF-8 when using Python 3, and documents a need to export
and import the database when moving from Python 2 to Python 3 with
this backend.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Sun, 16 Sep 2018 16:19:20 +0000 |
| parents | f2fade4552c5 |
| children | 42bf0a707763 |
| rev | line source |
|---|---|
| 4068 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5 # | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
6 from __future__ import print_function |
| 4068 | 7 from roundup import msgfmt |
| 8 from distutils.command.build import build as base | |
| 9 import os | |
| 10 from glob import glob | |
| 11 | |
| 12 def list_message_files(suffix=".po"): | |
| 13 """Return list of all found message files and their intallation paths""" | |
| 14 _files = glob("locale/*" + suffix) | |
| 15 _list = [] | |
| 16 for _file in _files: | |
| 17 # basename (without extension) is a locale name | |
| 18 _locale = os.path.splitext(os.path.basename(_file))[0] | |
| 19 _list.append((_file, os.path.join( | |
| 20 "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) | |
| 21 return _list | |
| 22 | |
| 23 def check_manifest(): | |
| 24 """Check that the files listed in the MANIFEST are present when the | |
| 25 source is unpacked. | |
| 26 """ | |
| 27 try: | |
| 28 f = open('MANIFEST') | |
| 29 except: | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
30 print('\n*** SOURCE WARNING: The MANIFEST file is missing!') |
| 4068 | 31 return |
| 32 try: | |
| 33 manifest = [l.strip() for l in f.readlines()] | |
| 34 finally: | |
| 35 f.close() | |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
36 err = set([line for line in manifest if not os.path.exists(line)]) |
| 4068 | 37 # ignore auto-generated files |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
38 err = err - set(['roundup-admin', 'roundup-demo', 'roundup-gettext', |
|
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
39 'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server']) |
| 4068 | 40 if err: |
| 41 n = len(manifest) | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
42 print('\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%( |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
43 n-len(err), n)) |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
44 print('Missing:', '\nMissing: '.join(err)) |
| 4068 | 45 |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
46 def build_message_files(command): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
47 """For each locale/*.po, build .mo file in target locale directory""" |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
48 for (_src, _dst) in list_message_files(): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
49 _build_dst = os.path.join("build", _dst) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
50 command.mkpath(os.path.dirname(_build_dst)) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
51 command.announce("Compiling %s -> %s" % (_src, _build_dst)) |
|
5450
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
52 mo = msgfmt.Msgfmt(_src).get() |
|
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
53 open(_build_dst, 'wb').write(mo) |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
54 |
| 4068 | 55 |
| 56 class build(base): | |
| 57 | |
| 58 def run(self): | |
| 59 check_manifest() | |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
60 build_message_files(self) |
| 4068 | 61 base.run(self) |
| 62 |
