Operations
Duqtools uses delayed operations for filesystem-changing operations.
They are implemented mostly with decorators, but a function could be added directly to the op_queue
.
Operation
Bases: LongDescription
Operation, simple class which has a callable action.
Usually not called directly but used through Operations.
__call__()
Execute the action with the args and kwargs.
Returns:
-
Operation
–The operation that was executed
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
92 93 94 95 96 97 98 99 100 101 102 103 |
|
Operations
Bases: deque
Operations Queue which keeps track of all the operations that need to be done.
It's basically dask_delayed, but custom made and a few drawbacks: The return value from an action is eventually discarded, communication between queue items is possible through references, or global values, but not really recommended, and no guidance for this is provided
n_actions
property
Return number of actions (no no-op).
add(**kwargs)
Convenience Operation wrapper around .append().
from duqtools.operations import add_to_op_queue.
op_queue.add(action=print, args=('Hello World,),
description="Function that prints hello world")
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
146 147 148 149 150 151 152 153 154 155 156 |
|
add_no_op(description, extra_description=None)
Adds a line to specify an action will not be undertaken.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
158 159 160 161 162 163 164 165 |
|
append(item)
Restrict our diet to Operation objects only.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
183 184 185 186 187 188 189 190 191 |
|
apply()
Apply the next operation in the queue and remove it.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
193 194 195 196 197 |
|
apply_all()
Apply all queued operations and empty the queue.
and show a fancy progress bar while applying
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
check_unconfirmed_operations()
Safety check, it should never happen that operations are not executed.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
273 274 275 276 277 278 279 |
|
confirm_apply_all()
First asks the user if he wants to apply everything.
Returns:
-
bool
(did we apply everything or not
) –
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
info(description, extra_description=None)
Adds an info line.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
167 168 169 170 171 172 |
|
put(item)
Synonym for append.
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
179 180 181 |
|
Warning
Bases: LongDescription
Warning item for screen log.
add_to_op_queue(op_desc, extra_desc=None, quiet=False)
Decorator which adds the function call to the op_queue, instead of executing it directly, the string can be a format string and use the function arguments.
from duqtools.operations import add_to_op_queue, op_queue
@add_to_op_queue("Printing hello world", "{name}")
def print_hello_world(name):
print(f"Hello World {name}")
print_hello_world("Snoozy")
op_queue.confirm_apply_all()
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
confirm_operations(func)
Decorator which confirms and applies queued operations after the function.
from duqtools.operations import confirm_operations, op_queue
@confirm_operations
def complicated_stuff()
op_queue.add(action=print, args=('Hello World,),
description="Function that prints hello world")
op_queue.add(action=print, args=('Hello World again,),
description="Function that prints hello world, again")
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
op_queue_context()
Context manager to enable the op_queue, and confirm_operations on exit Also disables the op_queue on exit.
Works more or less the same as the @confirm_operations
decorator
Source code in /home/docs/checkouts/readthedocs.org/user_builds/duqtools/envs/latest/lib/python3.11/site-packages/duqtools/operations.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|