Write tag information from the database to the respective files in the filesystem.
(lib, query, pretend, force)
| 12 | |
| 13 | |
| 14 | def write_items(lib, query, pretend, force): |
| 15 | """Write tag information from the database to the respective files |
| 16 | in the filesystem. |
| 17 | """ |
| 18 | items, _ = do_query(lib, query, False, False) |
| 19 | |
| 20 | for item in items: |
| 21 | # Item deleted? |
| 22 | if not os.path.exists(syspath(item.path)): |
| 23 | log.info("missing file: {.filepath}", item) |
| 24 | continue |
| 25 | |
| 26 | # Get an Item object reflecting the "clean" (on-disk) state. |
| 27 | try: |
| 28 | clean_item = library.Item.from_path(item.path) |
| 29 | except library.ReadError as exc: |
| 30 | log.error("error reading {.filepath}: {}", item, exc) |
| 31 | continue |
| 32 | |
| 33 | # Check for and display changes. |
| 34 | changed = ui.show_model_changes( |
| 35 | item, clean_item, library.Item._media_tag_fields, force |
| 36 | ) |
| 37 | if (changed or force) and not pretend: |
| 38 | # We use `try_sync` here to keep the mtime up to date in the |
| 39 | # database. |
| 40 | item.try_sync(True, False) |
| 41 | |
| 42 | |
| 43 | def write_func(lib, opts, args): |