Coverage for gws-app/gws/base/action/cli.py: 0%
30 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 12:46 +0200
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 12:46 +0200
1"""Actions CLI"""
3import cProfile
5import gws
6import gws.config
7import gws.base.action
8import gws.base.auth
9import gws.base.web
10import gws.lib.jsonx
11import gws.lib.vendor.slon
14class InvokeRequest(gws.Request):
15 cmd: str
16 params: str
19class Object(gws.Node):
21 @gws.ext.command.cli('actionInvoke')
22 def invoke(self, p: InvokeRequest):
23 """Invoke a web action."""
25 res = self._invoke(p)
26 print(gws.lib.jsonx.to_pretty_string(res))
28 @gws.ext.command.cli('actionProfile')
29 def profile(self, p: InvokeRequest):
30 """Profile a web action."""
32 filename = f'{gws.c.VAR_DIR}/{p.cmd}.pstats'
34 cProfile.runctx(
35 'self._invoke(p)',
36 {},
37 locals(),
38 filename=filename
39 )
40 print(f'profile saved to {filename!r}')
42 def _invoke(self, p: InvokeRequest):
43 environ = {}
44 root = gws.config.load()
45 req = gws.base.web.wsgi.Requester(root, environ, root.app.webMgr.site)
47 fn, request = root.app.actionMgr.prepare_action(
48 gws.CommandCategory.api,
49 p.cmd,
50 gws.lib.vendor.slon.parse(p.params),
51 '',
52 req.user,
53 )
54 try:
55 return fn(req, request)
56 except:
57 gws.log.exception()