|
4 | 4 | import os |
5 | 5 | import platform |
6 | 6 | import subprocess |
7 | | -import time |
| 7 | +from datetime import datetime, timezone |
8 | 8 | from pathlib import Path |
9 | 9 |
|
10 | 10 | import ramalama.oci |
@@ -547,7 +547,8 @@ def _list_models(args): |
547 | 547 | else: |
548 | 548 | name = str(path).replace("/", "://", 1) |
549 | 549 | file_epoch = path.lstat().st_mtime |
550 | | - modified = int(time.time() - file_epoch) |
| 550 | + # convert to iso format |
| 551 | + modified = datetime.fromtimestamp(file_epoch, tz=timezone.utc).isoformat() |
551 | 552 | size = get_size(path) |
552 | 553 |
|
553 | 554 | # Store data for later use |
@@ -607,26 +608,25 @@ def list_cli(args): |
607 | 608 | size_width = len("SIZE") |
608 | 609 | for model in sorted(models, key=lambda d: d['name']): |
609 | 610 | try: |
610 | | - modified = human_duration(model["modified"]) + " ago" |
| 611 | + delta = int(datetime.now(timezone.utc).timestamp() - datetime.fromisoformat(model["modified"]).timestamp()) |
| 612 | + modified = human_duration(delta) + " ago" |
| 613 | + model["modified"] = modified |
611 | 614 | except TypeError: |
612 | | - modified = model["modified"] |
| 615 | + pass |
613 | 616 | # update the size to be human readable |
614 | 617 | model["size"] = human_readable_size(model["size"]) |
615 | 618 | name_width = max(name_width, len(model["name"])) |
616 | | - modified_width = max(modified_width, len(modified)) |
| 619 | + modified_width = max(modified_width, len(model["modified"])) |
617 | 620 | size_width = max(size_width, len(model["size"])) |
618 | 621 |
|
619 | 622 | if not args.quiet and not args.noheading and not args.json: |
620 | 623 | print(f"{'NAME':<{name_width}} {'MODIFIED':<{modified_width}} {'SIZE':<{size_width}}") |
621 | 624 |
|
622 | 625 | for model in models: |
623 | | - try: |
624 | | - modified = human_duration(model["modified"]) + " ago" |
625 | | - except TypeError: |
626 | | - modified = model["modified"] |
627 | 626 | if args.quiet: |
628 | 627 | print(model["name"]) |
629 | 628 | else: |
| 629 | + modified = model['modified'] |
630 | 630 | print(f"{model['name']:<{name_width}} {modified:<{modified_width}} {model['size'].upper():<{size_width}}") |
631 | 631 |
|
632 | 632 |
|
|
0 commit comments