common
zeus.device.common
Common utilities for device management.
DeprecatedAliasABCMeta
Bases: ABCMeta
Metaclass that combines ABC functionality with automatic deprecated alias creation.
This metaclass looks for methods decorated with @deprecated_alias and automatically
creates the old camelCase method names that emit deprecation warnings once and then
call the new snake_case methods.
Since this is frequently composed with abc.ABCMeta, this metaclass inherits from it
to avoid metaclass conflicts.
Example
class MyClass(abc.ABC, metaclass=DeprecatedAliasABCMeta):
@deprecated_alias("oldMethod")
@abc.abstractmethod
def new_method(self):
pass
class MyImplementation(MyClass):
def new_method(self):
return "implementation"
obj = MyImplementation()
obj.new_method() # No warning
obj.oldMethod() # Emits deprecation warning, calls new_method
Source code in zeus/device/common.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
__new__
__new__(mcs, name, bases, namespace)
Create the class and add deprecated alias methods.
Source code in zeus/device/common.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
has_sys_admin
cached
has_sys_admin()
Check if the current process has SYS_ADMIN capabilities.
Source code in zeus/device/common.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
deprecated_alias
deprecated_alias(old_name)
Decorator that marks a method to have a deprecated camelCase alias.
Apply this decorator to the new snake_case method. When the old camelCase name is called, it will emit a deprecation warning once and then call the new snake_case method.
Example
@deprecated_alias("getName")
def get_name(self):
return "GPU Name"
The class using this decorator should use DeprecatedAliasABCMeta as its metaclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name |
str
|
The old camelCase method name to create as a deprecated alias. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable], Callable]
|
The decorated function with the |
Source code in zeus/device/common.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
_make_deprecated_method
_make_deprecated_method(new_method, old_name, new_name)
Create a deprecated method wrapper that warns once globally per method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_method |
Callable
|
The new snake_case method to be called. |
required |
old_name |
str
|
The old camelCase method name (for the warning message). |
required |
new_name |
str
|
The new snake_case method name (for the warning message). |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A wrapper function that emits a deprecation warning and calls the new method. |
Source code in zeus/device/common.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |