Mercurial > p > roundup > code
comparison roundup/admin.py @ 8557:f80c566f5726
feat: improve store_trace_reason with extract parameter
store_trace_reason() used embedded code to extract reason based on the
location passed to the function.
This change adds support for extract keyword that is a Python
expression eval'ed when the underlying function/method is called. All
callers now set the extract parameter. The prior embedded code has
been removed from store_trace_reason().
Failure to eval the expression results in an roundup.logcontext error
severity log. Also updated docs.
Also replaced env['REQUEST_URI'] with env['PATH_INFO'] for web based
entry points as REQUEST_URI isn't documented as a required key and
some other front end (e.g. zope, cgi) might not supply this.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 06 Apr 2026 22:10:23 -0400 |
| parents | 7a7f6ee0a09e |
| children | 9c3ec0a5c7fc |
comparison
equal
deleted
inserted
replaced
| 8556:dd0445649244 | 8557:f80c566f5726 |
|---|---|
| 54 | 54 |
| 55 try: | 55 try: |
| 56 from UserDict import UserDict | 56 from UserDict import UserDict |
| 57 except ImportError: | 57 except ImportError: |
| 58 from collections import UserDict | 58 from collections import UserDict |
| 59 | |
| 60 | |
| 61 def _safe_os_getlogin(): | |
| 62 """Run os.getlogin handling OSError exception. | |
| 63 | |
| 64 Used when calling @store_trace_reason to add username to string. | |
| 65 """ | |
| 66 | |
| 67 try: | |
| 68 return os.getlogin() | |
| 69 except OSError: | |
| 70 return "--unknown--" | |
| 59 | 71 |
| 60 | 72 |
| 61 class CommandDict(UserDict): | 73 class CommandDict(UserDict): |
| 62 """Simple dictionary that lets us do lookups using partial keys. | 74 """Simple dictionary that lets us do lookups using partial keys. |
| 63 | 75 |
| 2361 print(function.__doc__) | 2373 print(function.__doc__) |
| 2362 return 1 | 2374 return 1 |
| 2363 | 2375 |
| 2364 @set_processName("roundup-admin") | 2376 @set_processName("roundup-admin") |
| 2365 @gen_trace_id() | 2377 @gen_trace_id() |
| 2366 @store_trace_reason('admin') | 2378 @store_trace_reason("admin", extract=( |
| 2379 '"roundup-admin(%s): "' % _safe_os_getlogin() + | |
| 2380 "'%s' % args[1][:2]" | |
| 2381 )) | |
| 2367 def run_command(self, args): | 2382 def run_command(self, args): |
| 2368 """Run a single command | 2383 """Run a single command |
| 2369 """ | 2384 """ |
| 2370 command = args[0] | 2385 command = args[0] |
| 2371 | 2386 |
