annotate roundup/scripts/roundup_gettext.py @ 5710:0b79bfcb3312

Add support for making an idempotent POST. This allows retrying a POST that was interrupted. It involves creating a post once only (poe) url /rest/data/<class>/@poe/<random_token>. This url acts the same as a post to /rest/data/<class>. However once the @poe url is used, it can't be used for a second POST. To make these changes: 1) Take the body of post_collection into a new post_collection_inner function. Have post_collection call post_collection_inner. 2) Add a handler for POST to rest/data/class/@poe. This will return a unique POE url. By default the url expires after 30 minutes. The POE random token is only good for a specific user and is stored in the session db. 3) Add a handler for POST to rest/data/<class>/@poe/<random token>. The random token generated in 2 is validated for proper class (if token is not generic) and proper user and must not have expired. If everything is valid, call post_collection_inner to process the input and generate the new entry. To make recognition of 2 stable (so it's not confused with rest/data/<:class_name>/<:item_id>), removed @ from Routing::url_to_regex. The current Routing.execute method stops on the first regular expression to match the URL. Since item_id doesn't accept a POST, I was getting 405 bad method sometimes. My guess is the order of the regular expressions is not stable, so sometime I would get the right regexp for /data/<class>/@poe and sometime I would get the one for /data/<class>/<item_id>. By removing the @ from the url_to_regexp, there was no way for the item_id case to match @poe. There are alternate fixes we may need to look at. If a regexp matches but the method does not, return to the regexp matching loop in execute() looking for another match. Only once every possible match has failed should the code return a 405 method failure. Another fix is to implement a more sophisticated mechanism so that @Routing.route("/data/<:class_name>/<:item_id>/<:attr_name>", 'PATCH') has different regexps for matching <:class_name> <:item_id> and <:attr_name>. Currently the regexp specified by url_to_regex is used for every component. Other fixes: Made failure to find any props in props_from_args return an empty dict rather than throwing an unhandled error. Make __init__ for SimulateFieldStorageFromJson handle an empty json doc. Useful for POSTing to rest/data/class/@poe with an empty document. Testing: added testPostPOE to test/rest_common.py that I think covers all the code that was added. Documentation: Add doc to rest.txt in the "Client API" section titled: Safely Re-sending POST". Move existing section "Adding new rest endpoints" in "Client API" to a new second level section called "Programming the REST API". Also a minor change to the simple rest client moving the header setting to continuation lines rather than showing one long line.
author John Rouillard <rouilj@ieee.org>
date Sun, 14 Apr 2019 21:07:11 -0400
parents 64b05e24dbd8
children 32a5a54536b5
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
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
31 def run():
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
32 # 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
33 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")):
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
34 print(_("Usage: %(program)s <tracker home>") % {"program": sys.argv[0]})
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
35 return
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
36 # collect file paths of html templates
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
37 home = os.path.abspath(sys.argv[1])
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
38 htmldir = os.path.join(home, "html")
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
39 if os.path.isdir(htmldir):
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
40 # 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
41 # 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
42 htmlfiles = [filename for filename in os.listdir(htmldir)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
43 if os.path.isfile(os.path.join(htmldir, filename))
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
44 and filename.lower().endswith(".html")]
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
45 else:
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
46 htmlfiles = []
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
47 # return if no html files found
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
48 if not htmlfiles:
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
49 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
50 return
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
51 # 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
52 locale = os.path.join(home, "locale")
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
53 if not os.path.isdir(locale):
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
54 os.mkdir(locale)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
55 os.chdir(locale)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
56 # 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
57 # 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
58 sys.argv[1:] = ["-o", TEMPLATE_FILE] \
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
59 + ["../html/" + filename for filename in htmlfiles]
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
60 # run
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
61 talgettext.main()
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
62
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
63 if __name__ == "__main__":
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
64 run()
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
65
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
66 # vim: set et sts=4 sw=4 :

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