def fstringify_diff_files(event): """ Show the diffs that would result from fstringifying the external files at c.p. """ c = event.get('c') if not c or not c.p: return t1 = time.process_time() tag = 'fstringify-files-diff' g.es(f"{tag}...") roots = g.findRootsWithPredicate(c, c.p) for root in roots: filename = g.fullPath(c, root) if os.path.exists(filename): print('') print(g.shortFileName(filename)) changed = leoAst.Fstringify().fstringify_file_diff(filename) changed_s = 'changed' if changed else 'unchanged' g.es_print(f"{changed_s:>9}: {g.shortFileName(filename)}") else: print('') print(f"File not found:{filename}") g.es(f"File not found:\n{filename}") t2 = time.process_time() print('') g.es_print( f"{len(roots)} file{g.plural(len(roots))} in {t2 - t1:5.2f} sec.")
def fstringify_files_silent(event): """Silently fstringifying the external files at c.p.""" c = event.get('c') if not c or not c.p: return t1 = time.process_time() tag = 'silent-fstringify-files' g.es(f"{tag}...") n_changed = 0 roots = g.findRootsWithPredicate(c, c.p) for root in roots: filename = g.fullPath(c, root) if os.path.exists(filename): changed = leoAst.Fstringify().fstringify_file_silent(filename) if changed: n_changed += 1 else: print('') print(f"File not found:{filename}") g.es(f"File not found:\n{filename}") t2 = time.process_time() print('') n_tot = len(roots) g.es_print(f"{n_tot} total file{g.plural(len(roots))}, " f"{n_changed} changed file{g.plural(n_changed)} " f"in {t2 - t1:5.2f} sec.")
def fstringify_files(event): """fstringify one or more files at c.p.""" c = event.get('c') if not c or not c.p: return t1 = time.process_time() tag = 'fstringify-files' g.es(f"{tag}...") roots = g.findRootsWithPredicate(c, c.p) n_changed = 0 for root in roots: filename = g.fullPath(c, root) if os.path.exists(filename): print('') print(g.shortFileName(filename)) changed = leoAst.Fstringify().fstringify_file(filename) changed_s = 'changed' if changed else 'unchanged' if changed: n_changed += 1 g.es_print(f"{changed_s:>9}: {g.shortFileName(filename)}") else: print('') print(f"File not found:{filename}") g.es(f"File not found:\n{filename}") t2 = time.process_time() print('') g.es_print(f"total files: {len(roots)}, " f"changed files: {n_changed}, " f"in {t2 - t1:5.2f} sec.")