Coverage for gws-app/gws/base/action/cli.py: 0%
31 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +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 site = root.app.webMgr.site_from_environ(environ)
46 req = gws.base.web.wsgi.Requester(root, environ, site)
48 fn, request = root.app.actionMgr.prepare_action(
49 'api',
50 p.cmd,
51 gws.lib.vendor.slon.parse(p.params),
52 req.user
53 )
54 try:
55 return fn(req, request)
56 except:
57 gws.log.exception()