Changes measurement's name in name index and renames the file.
(self, old_name, new_name, dry_run=False)
| 392 | print(f'Removed "{file_path}"') |
| 393 | |
| 394 | def rename_measurement(self, old_name, new_name, dry_run=False): |
| 395 | """Changes measurement's name in name index and renames the file.""" |
| 396 | items = self.name_index.find(name=old_name) |
| 397 | renamed_file = False |
| 398 | for item in items: |
| 399 | old_path = self.target_path(item) |
| 400 | new_path = old_path.parent.joinpath(f'{new_name}.csv') |
| 401 | if not dry_run: |
| 402 | item.name = new_name |
| 403 | self.update_name_index(item, write=False) |
| 404 | if not renamed_file: |
| 405 | if not dry_run: |
| 406 | with open(old_path) as fh: |
| 407 | s = fh.read() |
| 408 | old_path.unlink() |
| 409 | with open(new_path, 'w') as fh: |
| 410 | fh.write(s) |
| 411 | if not renamed_file: |
| 412 | print(f'Moved "{old_path}" to "{new_path}"') |
| 413 | renamed_file = True |
| 414 | if not dry_run: |
| 415 | self.write_name_index() |
| 416 | |
| 417 | # UI methods |
| 418 |
nothing calls this directly
no test coverage detected