|
8 | 8 | import nbconvert.preprocessors |
9 | 9 |
|
10 | 10 | from typing import Optional |
| 11 | +from functools import total_ordering |
11 | 12 |
|
12 | 13 | have_pdf_kit = False |
13 | 14 | try: |
@@ -355,6 +356,7 @@ def render_as_html( |
355 | 356 | print(f'\tdone render_as_html "{html_name}" {datetime.datetime.now()}') |
356 | 357 |
|
357 | 358 |
|
| 359 | +@total_ordering |
358 | 360 | class JTask: |
359 | 361 | def __init__( |
360 | 362 | self, |
@@ -410,15 +412,43 @@ def render_as_html(self) -> None: |
410 | 412 | init_code=self.init_code, |
411 | 413 | ) |
412 | 414 |
|
| 415 | + def __getitem__(self, item): |
| 416 | + return getattr(self, item) |
| 417 | + |
| 418 | + def _is_valid_operand(self, other): |
| 419 | + return isinstance(other, JTask) |
| 420 | + |
| 421 | + def __eq__(self, other): |
| 422 | + if not self._is_valid_operand(other): |
| 423 | + return NotImplemented |
| 424 | + if str(type(self)) != str(type(other)): |
| 425 | + return False |
| 426 | + for v in ["sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"]: |
| 427 | + if self[v] != other[v]: |
| 428 | + return False |
| 429 | + return True |
| 430 | + |
| 431 | + def __lt__(self, other): |
| 432 | + if not self._is_valid_operand(other): |
| 433 | + return NotImplemented |
| 434 | + if str(type(self)) < str(type(other)): |
| 435 | + return True |
| 436 | + for v in ["sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"]: |
| 437 | + v_self = self[v] |
| 438 | + v_other = other[v] |
| 439 | + # can't order compare None to None |
| 440 | + if ((v_self is None) or (v_other is None)) and ((v_self is None) != (v_other is None)): |
| 441 | + return v_self is None |
| 442 | + if self[v] < other[v]: |
| 443 | + return True |
| 444 | + return False |
| 445 | + |
413 | 446 | def __str__(self) -> str: |
414 | 447 | args_str = ",\n".join([ |
415 | | - f" 'sheet_name': {repr(self.sheet_name)}", |
416 | | - f" 'output_suffix': {repr(self.output_suffix)}", |
417 | | - f" 'exclude_input': {repr(self.exclude_input)}", |
418 | | - f" 'init_code': {repr(self.init_code)}", |
419 | | - f" 'path_prefix': {repr(self.path_prefix)}", |
| 448 | + f" {v}= {repr(self[v])}" |
| 449 | + for v in ["sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"] |
420 | 450 | ]) |
421 | | - return 'JTask(**{\n' + args_str + ",\n})" |
| 451 | + return 'JTask(\n' + args_str + ",\n)" |
422 | 452 |
|
423 | 453 | def __repr__(self) -> str: |
424 | 454 | return self.__str__() |
|
0 commit comments