annotate roundup/dist/command/build.py @ 6433:c1d3fbcdbfbd

issue2551142 - Import of retired node ... unique constraint failure. Title: Import of retired node with username after active node fails with unique constraint failure. More fixes needed for mysql and postgresql. mysql: add unique constraint for (keyvalue, __retired__) when creating class in the database. On schema change if class is changed, remove the unique constraint too. upgrade version of rdbms database from 5 to 6 to add constraint to all version 5 databases that were created as version 5 and didn't get the unique constraint. Make no changes on version 5 databases upgraded from version 4, the upgrade process to 5 added the constraint. Make no changes to other databases (sqlite, postgres) during upgrade from version 5 to 6. postgres: Handle the exception raised on unique constraint violation. The exception invalidates the database connection so it can't be used to recover from the exception. Added two new database methods: checkpoint_data - performs a db.commit under postgres does nothing on other backends restore_connection_on_error - does a db.rollback on postgres, does nothing on other backends with the rollback() done on the connection I can use the database connection to fixup the import that failed on the unique constraint. This makes postgres slower but without the commit after every imported object, the rollback will delete all the entries done up to this point. Trying to figure out how to make the caller do_import batch and recover from this failure is beyond me. Also dismissed having to process the export csv file before importing. Pushing that onto a user just seems wrong. Also since import/export isn't frequently done the lack of surprise on having a failing import and reduced load/frustration for the user seems worth it. Also the import can be run in verbose mode where it prints out a row as it is processed, so it may take a while, ut the user can get feedback. db_test-base.py: add test for upgrade from 5 to 6.
author John Rouillard <rouilj@ieee.org>
date Thu, 10 Jun 2021 12:52:05 -0400
parents f2fade4552c5
children 42bf0a707763
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4068
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
1 #
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
2 # Copyright (C) 2009 Stefan Seefeld
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
3 # All rights reserved.
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
4 # For license terms see the file COPYING.txt.
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
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
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
7 from roundup import msgfmt
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
8 from distutils.command.build import build as base
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
9 import os
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
10 from glob import glob
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
11
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
12 def list_message_files(suffix=".po"):
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
13 """Return list of all found message files and their intallation paths"""
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
14 _files = glob("locale/*" + suffix)
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
15 _list = []
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
16 for _file in _files:
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
17 # basename (without extension) is a locale name
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
18 _locale = os.path.splitext(os.path.basename(_file))[0]
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
19 _list.append((_file, os.path.join(
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
20 "share", "locale", _locale, "LC_MESSAGES", "roundup.mo")))
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
21 return _list
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
22
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
23 def check_manifest():
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
24 """Check that the files listed in the MANIFEST are present when the
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
25 source is unpacked.
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
26 """
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
27 try:
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
28 f = open('MANIFEST')
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
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
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
31 return
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
32 try:
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
33 manifest = [l.strip() for l in f.readlines()]
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
34 finally:
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
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
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
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
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
40 if err:
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
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
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
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
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
55
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
56 class build(base):
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
57
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
58 def run(self):
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
59 check_manifest()
4516
85dfe17c182e Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4394
diff changeset
60 build_message_files(self)
4068
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
61 base.run(self)
e233d7a66343 Refactor setup.py.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
62

Roundup Issue Tracker: http://roundup-tracker.org/