annotate roundup/scripts/roundup_gettext.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 32a5a54536b5
children d1c29284ccd9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1 #! /usr/bin/env python
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2 #
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
4
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
5 """Extract translatable strings from tracker templates"""
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
6
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
7 from __future__ import print_function
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
8 import os
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
9 import sys
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
10
4766
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
11
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
12 # --- patch sys.path to make sure 'import roundup' finds correct version
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
13 import os.path as osp
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
14
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
15 thisdir = osp.dirname(osp.abspath(__file__))
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
16 rootdir = osp.dirname(osp.dirname(thisdir))
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
17 if (osp.exists(thisdir + '/__init__.py') and
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
18 osp.exists(rootdir + '/roundup/__init__.py')):
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
19 # the script is located inside roundup source code
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
20 sys.path.insert(0, rootdir)
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
21 # --/
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
22
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
23
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
24 from roundup.i18n import _
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
25 from roundup.cgi.TAL import talgettext
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
26
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
27 # name of message template file.
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
28 # i don't think this will ever need to be changed, but still...
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
29 TEMPLATE_FILE = "messages.pot"
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
30
6044
32a5a54536b5 flake8 whitespace fixes.
John Rouillard <rouilj@ieee.org>
parents: 5376
diff changeset
31
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
32 def run():
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
33 # return unless command line arguments contain single directory path
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
34 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")):
6044
32a5a54536b5 flake8 whitespace fixes.
John Rouillard <rouilj@ieee.org>
parents: 5376
diff changeset
35 print(_("Usage: %(program)s <tracker home>") %
32a5a54536b5 flake8 whitespace fixes.
John Rouillard <rouilj@ieee.org>
parents: 5376
diff changeset
36 {"program": sys.argv[0]})
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
37 return
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
38 # collect file paths of html templates
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
39 home = os.path.abspath(sys.argv[1])
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
40 htmldir = os.path.join(home, "html")
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
41 if os.path.isdir(htmldir):
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
42 # glob is not used because i want to match file names
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
43 # without case sensitivity, and that is easier done this way.
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
44 htmlfiles = [filename for filename in os.listdir(htmldir)
6044
32a5a54536b5 flake8 whitespace fixes.
John Rouillard <rouilj@ieee.org>
parents: 5376
diff changeset
45 if os.path.isfile(os.path.join(htmldir, filename))
32a5a54536b5 flake8 whitespace fixes.
John Rouillard <rouilj@ieee.org>
parents: 5376
diff changeset
46 and filename.lower().endswith(".html")]
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
47 else:
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
48 htmlfiles = []
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
49 # return if no html files found
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
50 if not htmlfiles:
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
51 print(_("No tracker templates found in directory %s") % home)
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
52 return
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
53 # change to locale dir to have relative source references
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
54 locale = os.path.join(home, "locale")
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
55 if not os.path.isdir(locale):
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
56 os.mkdir(locale)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
57 os.chdir(locale)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
58 # tweak sys.argv as this is the only way to tell talgettext what to do
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
59 # Note: unix-style paths used instead of os.path.join deliberately
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
60 sys.argv[1:] = ["-o", TEMPLATE_FILE] \
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
61 + ["../html/" + filename for filename in htmlfiles]
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
62 # run
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
63 talgettext.main()
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
64
6044
32a5a54536b5 flake8 whitespace fixes.
John Rouillard <rouilj@ieee.org>
parents: 5376
diff changeset
65
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
66 if __name__ == "__main__":
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
67 run()
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
68
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
69 # vim: set et sts=4 sw=4 :

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