MCPcopy
hub / github.com/jaakkopasanen/AutoEq / rename_measurement

Method rename_measurement

dbtools/crawler.py:394–415  ·  view source on GitHub ↗

Changes measurement's name in name index and renames the file.

(self, old_name, new_name, dry_run=False)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

target_pathMethod · 0.95
update_name_indexMethod · 0.95
write_name_indexMethod · 0.95
writeMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected