-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a tool to add the builtin attribute to all builtin libary file wh…
…ere it's missing
- Loading branch information
1 parent
cd155ed
commit f274849
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re, os | ||
|
||
# This is a temporary tool that adds "builtin: true" to all libraries stored as yaml files under ./backend/library/libraries. | ||
|
||
current_path = "/".join(__file__.split("/")[:-1]) | ||
library_path = os.path.join(current_path,"..","backend","library","libraries") | ||
fnames = [ | ||
fname for fname in os.listdir(library_path) | ||
if fname.endswith(".yaml") | ||
] | ||
|
||
for fname in fnames : | ||
lib = os.path.join(library_path,fname) | ||
|
||
with open(lib,"r",encoding="utf-8") as f: | ||
content = f.read() | ||
lines = content.split("\n") | ||
|
||
if not any( | ||
re.match(r"^builtin.*:.*true",line) is not None | ||
for line in lines | ||
) : | ||
lines.insert(1,"builtin: true") | ||
with open(lib,"w",encoding="utf-8") as f : | ||
f.write("\n".join(lines)) | ||
print(f"Library '{fname}' updated.") |