-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c68bf9
commit 4ba4658
Showing
13 changed files
with
253 additions
and
38 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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ results | |
logs | ||
summary-logs | ||
wwwroot | ||
wwwdata | ||
.idea | ||
dist | ||
pyenv | ||
|
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
# core dependencies | ||
click==8.1.7 | ||
pydantic==2.6.4 | ||
mypy==1.9.0 | ||
mypy==1.9.0 | ||
|
||
# servers dependencies | ||
Flask==3.0.2 | ||
tornado==6.4 | ||
Flask-Cors==4.0.0 | ||
Flask-Compress==1.14 |
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,29 @@ | ||
from datetime import datetime | ||
import os | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
|
||
root = Path(__file__).parent.parent | ||
|
||
mainSrc = root / "src" / "aexpy" | ||
toolSrc = mainSrc / "tools" | ||
serverSrc = root / "src" / "servers" | ||
|
||
webDist = root / "src" / "web" / "dist" | ||
serverWww = serverSrc / "wwwroot" | ||
|
||
|
||
def frontend(): | ||
shutil.rmtree(serverWww) | ||
shutil.copytree(webDist, serverWww) | ||
|
||
|
||
def server(): | ||
target = toolSrc / "servers" | ||
shutil.copytree(serverSrc, target) | ||
|
||
|
||
if __name__ == "__main__": | ||
frontend() | ||
server() |
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,33 @@ | ||
from datetime import datetime | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
|
||
root = Path(__file__).parent.parent | ||
|
||
webDist = root / "src" / "web" / "dist" | ||
webEnv = root / "src" / "web" / ".env" | ||
serverWww = root / "src" / "servers" / "wwwroot" | ||
|
||
|
||
def build(): | ||
originalText = webEnv.read_text() | ||
webEnv.write_text( | ||
f""" | ||
VITE_NOSERVER=0 | ||
VITE_COMMIT_ID=on-line | ||
VITE_BUILD_DATE={datetime.now().isoformat()} | ||
""" | ||
) | ||
subprocess.run("npm run build", shell=True, cwd=webDist.parent, check=True) | ||
webEnv.write_text(originalText) | ||
|
||
|
||
def copy(): | ||
shutil.rmtree(serverWww) | ||
shutil.copytree(webDist, serverWww) | ||
|
||
|
||
if __name__ == "__main__": | ||
build() | ||
copy() |
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,13 @@ | ||
import mimetypes | ||
|
||
from flask import Flask | ||
from flask_compress import Compress | ||
from flask_cors import CORS | ||
|
||
mimetypes.add_type("text/css", ".css") | ||
mimetypes.add_type("text/javascript", ".js") | ||
mimetypes.add_type("text/javascript", ".mjs") | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
Compress(app) |
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,4 @@ | ||
from .cli import serve as main | ||
|
||
if __name__ == "__main__": | ||
main() |
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,37 @@ | ||
import os | ||
from pathlib import Path | ||
from flask import Blueprint, Response, jsonify, request, send_file, send_from_directory | ||
|
||
wwwdata = Path(__file__).parent.parent.joinpath("wwwdata") | ||
|
||
if not wwwdata.is_dir(): | ||
os.makedirs(wwwdata, exist_ok=True) | ||
|
||
api = Blueprint("api", __name__) | ||
|
||
|
||
@api.route("/data/<path:path>", methods=["GET"]) | ||
def wwwrootFiles(path: str = "index.html"): | ||
return send_from_directory(wwwdata, path) | ||
|
||
|
||
@api.route("/tasks/extract", methods=["POST"]) | ||
def extract(): | ||
return "" | ||
|
||
|
||
@api.route("/tasks/diff", methods=["POST"]) | ||
def diff(): | ||
return "" | ||
|
||
|
||
@api.route("/info", methods=["GET"]) | ||
def info(): | ||
from aexpy import COMMIT_ID, BUILD_DATE | ||
|
||
return jsonify( | ||
{ | ||
"commitId": COMMIT_ID, | ||
"buildDate": BUILD_DATE.isoformat(), | ||
} | ||
) |
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,11 @@ | ||
import click | ||
|
||
|
||
@click.command() | ||
@click.option("-d", "--debug", is_flag=True, help="Debug mode.") | ||
@click.option("-p", "--port", type=int, default=8008, help="Port to listen on.") | ||
def serve(debug: "bool" = False, port: "int" = 8008): | ||
"""Serve web server.""" | ||
from .entrypoint import serve as inner, buildApp | ||
|
||
inner(buildApp(), debug, port) |
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,34 @@ | ||
import os | ||
import pathlib | ||
import shutil | ||
|
||
import click | ||
import tornado.httpserver | ||
import tornado.ioloop | ||
import tornado.wsgi | ||
from flask import Flask | ||
|
||
|
||
def buildApp(): | ||
from . import app | ||
from .api import api | ||
from .frontend import frontend | ||
|
||
app.register_blueprint(api, url_prefix="/api") | ||
app.register_blueprint(frontend, url_prefix="/") | ||
|
||
return app | ||
|
||
|
||
def serve(app: Flask, debug: bool = False, port: int = 8008): | ||
if debug: | ||
app.run(host="0.0.0.0", port=port, debug=debug) | ||
|
||
else: | ||
click.echo(f"Listening on port {port}...") | ||
click.echo(f"Visit http://localhost:{port} to AexPy.") | ||
|
||
container = tornado.wsgi.WSGIContainer(app) | ||
http_server = tornado.httpserver.HTTPServer(container) | ||
http_server.listen(port) | ||
tornado.ioloop.IOLoop.current().start() |
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,18 @@ | ||
import pathlib | ||
|
||
from flask import Blueprint, send_file, send_from_directory | ||
|
||
wwwroot = pathlib.Path(__file__).parent.joinpath("wwwroot") | ||
|
||
frontend = Blueprint("frontend", __name__) | ||
|
||
|
||
@frontend.route("/", methods=["GET"]) | ||
@frontend.route("/<path:path>", methods=["GET"]) | ||
def wwwrootFiles(path: str = "index.html"): | ||
return send_from_directory(wwwroot, path) | ||
|
||
|
||
@frontend.errorhandler(404) | ||
def pageNotFound(error): | ||
return send_file(wwwroot.joinpath("index.html")) |
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
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