New server architecutre build
This commit is contained in:
@@ -0,0 +1,110 @@
|
|||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
from collections import OrderedDict
|
||||||
|
from flask import Flask, jsonify, send_from_directory, request, redirect, url_for, session, render_template
|
||||||
|
from werkzeug.security import check_password_hash
|
||||||
|
import database # Imports the database.py you created earlier
|
||||||
|
|
||||||
|
# --- Path Configurations ---
|
||||||
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
FRONTEND_DIR = os.path.join(BASE_DIR, '..', 'frontend')
|
||||||
|
YML_PATH = os.path.join(BASE_DIR, '..\\mxpic\\PDKs\\Silterra\\directories.yaml')
|
||||||
|
COMPS_ROOT = os.path.join(BASE_DIR, '..\\mxpic\\PDKs\\Silterra')
|
||||||
|
|
||||||
|
# --- YAML & PDK Parsing Helper Functions (Unchanged) ---
|
||||||
|
def countSpaces(line):
|
||||||
|
"""Count leading spaces (tab=4)."""
|
||||||
|
expanded = line.expandtabs(4)
|
||||||
|
return len(expanded) - len(expanded.lstrip(' '))
|
||||||
|
|
||||||
|
def buildTree(filepath):
|
||||||
|
"""Build nested tree from indented yaml."""
|
||||||
|
if not os.path.exists(filepath):
|
||||||
|
return OrderedDict()
|
||||||
|
|
||||||
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
rootIdx = None
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if line.strip().startswith('root') and ':' in line.strip():
|
||||||
|
rootIdx = i
|
||||||
|
break
|
||||||
|
if rootIdx is None:
|
||||||
|
return OrderedDict()
|
||||||
|
|
||||||
|
entries = []
|
||||||
|
for line in lines[rootIdx + 1:]:
|
||||||
|
stripped = line.strip()
|
||||||
|
if not stripped or stripped.startswith('#'):
|
||||||
|
continue
|
||||||
|
if stripped.startswith('- '):
|
||||||
|
spaceNum = countSpaces(line)
|
||||||
|
name = stripped[2:].strip()
|
||||||
|
if name.strip():
|
||||||
|
entries.append((spaceNum, name))
|
||||||
|
|
||||||
|
if not entries:
|
||||||
|
return OrderedDict()
|
||||||
|
|
||||||
|
minIndent = min(indent for indent, _ in entries)
|
||||||
|
nest = OrderedDict()
|
||||||
|
levelStack = [(minIndent - 1, nest)]
|
||||||
|
|
||||||
|
for spaceNum, name in entries:
|
||||||
|
while levelStack and levelStack[-1][0] >= spaceNum:
|
||||||
|
levelStack.pop()
|
||||||
|
parent = levelStack[-1][1]
|
||||||
|
child = OrderedDict()
|
||||||
|
parent[name] = child
|
||||||
|
levelStack.append((spaceNum, child))
|
||||||
|
|
||||||
|
return nest
|
||||||
|
|
||||||
|
def findComps(baseDir):
|
||||||
|
"""Scan component folders, return map of paths -> component info."""
|
||||||
|
compMap = {}
|
||||||
|
refDir = os.path.dirname(baseDir)
|
||||||
|
for root, dirs, files in os.walk(baseDir):
|
||||||
|
ymlFiles = [f for f in files if f.endswith('.yml')]
|
||||||
|
if ymlFiles:
|
||||||
|
parentDir = os.path.dirname(root)
|
||||||
|
relPath = os.path.relpath(parentDir, refDir)
|
||||||
|
parts = () if relPath == '.' else tuple(relPath.split(os.sep))
|
||||||
|
compName = os.path.basename(root)
|
||||||
|
compMap[parts] = {
|
||||||
|
'folder': compName,
|
||||||
|
'yml': ymlFiles[0]
|
||||||
|
}
|
||||||
|
dirs.clear()
|
||||||
|
return compMap
|
||||||
|
|
||||||
|
def addCompsToTree(tree, compMap):
|
||||||
|
"""Insert component nodes into the tree."""
|
||||||
|
for pathSeg, compItem in compMap.items():
|
||||||
|
compName = compItem['folder']
|
||||||
|
curNode = tree
|
||||||
|
try:
|
||||||
|
for seg in pathSeg:
|
||||||
|
curNode = curNode[seg]
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
curNode[compName] = OrderedDict({
|
||||||
|
"__type__": "component",
|
||||||
|
"__name__": compName,
|
||||||
|
"__yml__": compItem['yml']
|
||||||
|
})
|
||||||
|
return tree
|
||||||
|
|
||||||
|
def readCompYaml(compName):
|
||||||
|
"""Load YAML from component folder."""
|
||||||
|
for root, dirs, files in os.walk(COMPS_ROOT):
|
||||||
|
if os.path.basename(root) == compName:
|
||||||
|
dirs.clear()
|
||||||
|
ymlFiles = [f for f in files if f.endswith('.yml')]
|
||||||
|
if ymlFiles:
|
||||||
|
ymlPath = os.path.join(root, ymlFiles[0])
|
||||||
|
with open(ymlPath, 'r', encoding='utf-8') as f:
|
||||||
|
return yaml.safe_load(f)
|
||||||
|
return None
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
level : 4
|
|
||||||
|
|
||||||
root :
|
|
||||||
- PDK_libs
|
|
||||||
- primitives
|
|
||||||
- directional_couplers
|
|
||||||
- edge_couplers
|
|
||||||
- crossings
|
|
||||||
- multimode_interferometers
|
|
||||||
- photodectors
|
|
||||||
- compotites
|
|
||||||
- MZIs
|
|
||||||
- electronics
|
|
||||||
- resistors
|
|
||||||
- capacitors
|
|
||||||
- others
|
|
||||||
- logos
|
|
||||||
+89
-21
@@ -8,8 +8,10 @@ import database # Imports the database.py you created earlier
|
|||||||
# --- Path Configurations ---
|
# --- Path Configurations ---
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
FRONTEND_DIR = os.path.join(BASE_DIR, '..', 'frontend')
|
FRONTEND_DIR = os.path.join(BASE_DIR, '..', 'frontend')
|
||||||
YML_PATH = os.path.join(BASE_DIR, 'directories.yaml')
|
|
||||||
COMPS_ROOT = os.path.join(BASE_DIR, '..\\PDK_libs')
|
# Use os.path.join exclusively for cross-platform safety
|
||||||
|
YML_PATH = os.path.join(BASE_DIR, '..', 'mxpic', 'PDKs', 'Silterra', 'directories.yaml')
|
||||||
|
COMPS_ROOT = os.path.join(BASE_DIR, '..', 'mxpic', 'PDKs', 'Silterra')
|
||||||
|
|
||||||
# Initialize Flask, pointing to the frontend folder for HTML/CSS/JS
|
# Initialize Flask, pointing to the frontend folder for HTML/CSS/JS
|
||||||
app = Flask(__name__, template_folder=FRONTEND_DIR, static_folder=FRONTEND_DIR)
|
app = Flask(__name__, template_folder=FRONTEND_DIR, static_folder=FRONTEND_DIR)
|
||||||
@@ -25,6 +27,50 @@ def countSpaces(line):
|
|||||||
expanded = line.expandtabs(4)
|
expanded = line.expandtabs(4)
|
||||||
return len(expanded) - len(expanded.lstrip(' '))
|
return len(expanded) - len(expanded.lstrip(' '))
|
||||||
|
|
||||||
|
# def buildTree(filepath):
|
||||||
|
# """Build nested tree from indented yaml."""
|
||||||
|
# if not os.path.exists(filepath):
|
||||||
|
# return OrderedDict()
|
||||||
|
|
||||||
|
# with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
|
# lines = f.readlines()
|
||||||
|
|
||||||
|
# rootIdx = None
|
||||||
|
# for i, line in enumerate(lines):
|
||||||
|
# if line.strip().startswith('root') and ':' in line.strip():
|
||||||
|
# rootIdx = i
|
||||||
|
# break
|
||||||
|
# if rootIdx is None:
|
||||||
|
# return OrderedDict()
|
||||||
|
|
||||||
|
# entries = []
|
||||||
|
# for line in lines[rootIdx + 1:]:
|
||||||
|
# stripped = line.strip()
|
||||||
|
# if not stripped or stripped.startswith('#'):
|
||||||
|
# continue
|
||||||
|
# if stripped.startswith('- '):
|
||||||
|
# spaceNum = countSpaces(line)
|
||||||
|
# name = stripped[2:].strip()
|
||||||
|
# if name.strip():
|
||||||
|
# entries.append((spaceNum, name))
|
||||||
|
|
||||||
|
# if not entries:
|
||||||
|
# return OrderedDict()
|
||||||
|
|
||||||
|
# minIndent = min(indent for indent, _ in entries)
|
||||||
|
# nest = OrderedDict()
|
||||||
|
# levelStack = [(minIndent - 1, nest)]
|
||||||
|
|
||||||
|
# for spaceNum, name in entries:
|
||||||
|
# while levelStack and levelStack[-1][0] >= spaceNum:
|
||||||
|
# levelStack.pop()
|
||||||
|
# parent = levelStack[-1][1]
|
||||||
|
# child = OrderedDict()
|
||||||
|
# parent[name] = child
|
||||||
|
# levelStack.append((spaceNum, child))
|
||||||
|
|
||||||
|
# return nest
|
||||||
|
|
||||||
def buildTree(filepath):
|
def buildTree(filepath):
|
||||||
"""Build nested tree from indented yaml."""
|
"""Build nested tree from indented yaml."""
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
@@ -48,8 +94,9 @@ def buildTree(filepath):
|
|||||||
continue
|
continue
|
||||||
if stripped.startswith('- '):
|
if stripped.startswith('- '):
|
||||||
spaceNum = countSpaces(line)
|
spaceNum = countSpaces(line)
|
||||||
name = stripped[2:].strip()
|
# FIX 1: Strip trailing colons off the string so 'composites:' becomes 'composites'
|
||||||
if name.strip():
|
name = stripped[2:].strip().rstrip(':')
|
||||||
|
if name:
|
||||||
entries.append((spaceNum, name))
|
entries.append((spaceNum, name))
|
||||||
|
|
||||||
if not entries:
|
if not entries:
|
||||||
@@ -69,10 +116,31 @@ def buildTree(filepath):
|
|||||||
|
|
||||||
return nest
|
return nest
|
||||||
|
|
||||||
|
def addCompsToTree(tree, compMap):
|
||||||
|
"""Insert component nodes into the tree."""
|
||||||
|
for pathSeg, compItem in compMap.items():
|
||||||
|
compName = compItem['folder']
|
||||||
|
curNode = tree
|
||||||
|
|
||||||
|
# FIX 2: Automatically build missing folder paths
|
||||||
|
for seg in pathSeg:
|
||||||
|
if seg not in curNode:
|
||||||
|
# If a folder like MZM_1600G isn't in the YAML, gracefully auto-create it
|
||||||
|
curNode[seg] = OrderedDict()
|
||||||
|
curNode = curNode[seg]
|
||||||
|
|
||||||
|
curNode[compName] = OrderedDict({
|
||||||
|
"__type__": "component",
|
||||||
|
"__name__": compName,
|
||||||
|
"__yml__": compItem['yml']
|
||||||
|
})
|
||||||
|
return tree
|
||||||
|
|
||||||
def findComps(baseDir):
|
def findComps(baseDir):
|
||||||
"""Scan component folders, return map of paths -> component info."""
|
"""Scan component folders, return map of paths -> component info."""
|
||||||
compMap = {}
|
compMap = {}
|
||||||
refDir = os.path.dirname(baseDir)
|
# refDir = os.path.dirname(baseDir)
|
||||||
|
refDir = baseDir
|
||||||
for root, dirs, files in os.walk(baseDir):
|
for root, dirs, files in os.walk(baseDir):
|
||||||
ymlFiles = [f for f in files if f.endswith('.yml')]
|
ymlFiles = [f for f in files if f.endswith('.yml')]
|
||||||
if ymlFiles:
|
if ymlFiles:
|
||||||
@@ -87,22 +155,22 @@ def findComps(baseDir):
|
|||||||
dirs.clear()
|
dirs.clear()
|
||||||
return compMap
|
return compMap
|
||||||
|
|
||||||
def addCompsToTree(tree, compMap):
|
# def addCompsToTree(tree, compMap):
|
||||||
"""Insert component nodes into the tree."""
|
# """Insert component nodes into the tree."""
|
||||||
for pathSeg, compItem in compMap.items():
|
# for pathSeg, compItem in compMap.items():
|
||||||
compName = compItem['folder']
|
# compName = compItem['folder']
|
||||||
curNode = tree
|
# curNode = tree
|
||||||
try:
|
# try:
|
||||||
for seg in pathSeg:
|
# for seg in pathSeg:
|
||||||
curNode = curNode[seg]
|
# curNode = curNode[seg]
|
||||||
except KeyError:
|
# except KeyError:
|
||||||
continue
|
# continue
|
||||||
curNode[compName] = OrderedDict({
|
# curNode[compName] = OrderedDict({
|
||||||
"__type__": "component",
|
# "__type__": "component",
|
||||||
"__name__": compName,
|
# "__name__": compName,
|
||||||
"__yml__": compItem['yml']
|
# "__yml__": compItem['yml']
|
||||||
})
|
# })
|
||||||
return tree
|
# return tree
|
||||||
|
|
||||||
def readCompYaml(compName):
|
def readCompYaml(compName):
|
||||||
"""Load YAML from component folder."""
|
"""Load YAML from component folder."""
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
level: 4
|
level: 4
|
||||||
root:
|
root:
|
||||||
- PDKs:
|
- EMO1_2ML_CU_Al_RDL:
|
||||||
- primitives:
|
- primitives:
|
||||||
- directional_couplers
|
- directional_couplers
|
||||||
- edge_couplers
|
- edge_couplers
|
||||||
@@ -12,5 +12,6 @@ root:
|
|||||||
- electronics:
|
- electronics:
|
||||||
- resistors
|
- resistors
|
||||||
- capacitors
|
- capacitors
|
||||||
|
- indectors
|
||||||
- others:
|
- others:
|
||||||
- logos
|
- logos
|
||||||
|
|||||||
Reference in New Issue
Block a user