1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 12:23:56 +01:00

Added rename script

This commit is contained in:
Anthony Scemama 2021-03-06 14:47:11 +01:00
parent 88f1f82230
commit d7a922b24e
2 changed files with 46 additions and 0 deletions

2
docs/.gitignore vendored
View File

@ -0,0 +1,2 @@
htmlize.el
index.html

44
tools/rename.py Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python
"""
Changes the name of a function into all the org files.
This script should be run in the src directory.
"""
import sys
import os
def help():
print("Syntax : {0} OLD_FUNC_NAME NEW_FUNC_NAME".format(sys.argv[0]))
def replace_in_file(filename, old_func_name, new_func_name):
with open(filename,'r') as f:
text = f.read()
new_text = text.replace(old_func_name, new_func_name)
with open(filename,'w') as f:
f.write(new_text)
def main():
if len(sys.argv) != 3:
help()
sys.exit(-1)
old_func_name = sys.argv[1]
new_func_name = sys.argv[2]
for filename in os.listdir(os.getcwd()):
if filename.endswith(".org"):
replace_in_file(filename, old_func_name, new_func_name)
print("Done. run git diff to check what has been changed.")
if __name__ == "__main__":
main()