mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-22 14:43:08 +00:00
Shell: do not access properties on startup
Change the way the shell finds methods to add to the locals on startup: the methods are queried on the object’s class, rather than the object itself. This allows detecting if an object’s member is a property and ignore it, rather than accessing the property. Attributes whose name starts by ‘_’ are also now ignored, which avoids importing private methods or Python magic methods in the shell namespace. Fixes spurious accesses to ProxyUtils’s SIMD properties (b, h, etc) on shell startup, which caused a ProxyCommandError if m1n1 is not recent enough. Signed-off-by: Vincent Duvert <vincent@duvert.net>
This commit is contained in:
parent
4b5c016368
commit
1a95a9fc17
1 changed files with 13 additions and 7 deletions
|
@ -65,13 +65,19 @@ def run_shell(locals, msg=None, exitmsg=None):
|
|||
if "utils" in locals and "u" not in locals:
|
||||
locals["u"] = locals["utils"]
|
||||
|
||||
for obj in ("iface", "p", "u"):
|
||||
if obj in locals:
|
||||
for attr in dir(locals[obj]):
|
||||
if attr not in locals:
|
||||
v = getattr(locals[obj], attr)
|
||||
if callable(v):
|
||||
locals[attr] = v
|
||||
for obj_name in ("iface", "p", "u"):
|
||||
obj = locals.get(obj_name)
|
||||
obj_class = type(obj)
|
||||
if obj is None:
|
||||
continue
|
||||
|
||||
for attr in dir(obj_class):
|
||||
if attr in locals or attr.startswith('_'):
|
||||
continue
|
||||
|
||||
member = getattr(obj_class, attr)
|
||||
if callable(member) and not isinstance(member, property):
|
||||
locals[attr] = getattr(obj, attr)
|
||||
|
||||
for attr in dir(sysreg):
|
||||
locals[attr] = getattr(sysreg, attr)
|
||||
|
|
Loading…
Reference in a new issue