Skip to content

Commit 97812de

Browse files
base json compiler
1 parent 424e681 commit 97812de

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed
File renamed without changes.

compiler/compiler.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
from json_compiler.Compiler import Compiler as json_compiler
2+
import sys
13
COMPILERS = {
24
"django-postgres": "under development",
35
"flask-mongo": "under development",
46
"nodejs-mongo": "under development",
5-
}
7+
"json": json_compiler
8+
}
9+
def compile(compiler_name, project_name):
10+
compiler = COMPILERS[compiler_name](project_name)
11+
compiler.compile()
12+
OPTIONS = {
13+
"compile": compile,
14+
"c": compile
15+
}
16+
def main():
17+
OPTIONS[sys.argv[1]](sys.argv[2], sys.argv[3])
18+
return
19+
20+
main()
21+
#python .\compiler.py c json ../blueprints/examples/facebook/main.app.json

compiler/json_compiler/Compiler.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import json
2+
from searcher import search_json
3+
MODELS_FIELD = "models"
4+
EXTENDS_FIELD = "__extends"
5+
6+
class Compiler:
7+
blueprint:dict = {}
8+
def __init__(self, main_file) -> None:
9+
self.main_file = main_file
10+
with open(main_file, "r") as f:
11+
self.blueprint = json.load(f)
12+
def compile_models(self):
13+
if MODELS_FIELD not in self.blueprint and EXTENDS_FIELD not in self.blueprint:
14+
raise NameError("models is not defined")
15+
for model in self.blueprint["models"]:
16+
print(model)
17+
if type(model) == str:
18+
search_json(model, self.main_file)
19+
def compile(self):
20+
self.compile_models()

compiler/searcher.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
def search_json(route, base_file):
3+
splited = route.split(".")
4+
5+
print(os.listdir(os.path.dirname(base_file)))
6+
#for step in splited:
7+
# os.listdir()

0 commit comments

Comments
 (0)