From 9c6e7475ca916fb9a0b62928cb308218e4d6dc34 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Fri, 1 Sep 2023 15:01:24 +0800 Subject: [PATCH 01/22] feat: pyinstaller --- start_canvasapp.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 start_canvasapp.py diff --git a/start_canvasapp.py b/start_canvasapp.py new file mode 100644 index 0000000..3952856 --- /dev/null +++ b/start_canvasapp.py @@ -0,0 +1,4 @@ +import uvicorn + +if __name__ == "__main__": + uvicorn.run("canvas_app:app", port=9283) From de425ffc965c98fbed1f120ac8b7971fed2ac945 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sat, 2 Sep 2023 14:59:10 +0800 Subject: [PATCH 02/22] fix:update Fix/Safety Issue --- canvas_app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/canvas_app.py b/canvas_app.py index 50e2ae3..d721696 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -13,6 +13,7 @@ import json import logging from typing import List +import uvicorn """ Local function @@ -480,3 +481,6 @@ async def open_url(data: URL): except Exception as e: logging.warning(e) return JSONResponse(status_code=400, content={"message": "Failed to open"}) + +if __name__ == "__main__": + uvicorn.run(app='canvas_app:app',port=9283,reload=False) From e96e3dce66dd1161157fbf66c3cdef329f79f0af Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sat, 2 Sep 2023 15:43:14 +0800 Subject: [PATCH 03/22] feat: modifed for pyinstaller --- canvas_app.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/canvas_app.py b/canvas_app.py index d721696..a958b53 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -8,12 +8,16 @@ import urllib.parse from models import Position, Check, Course, URL from fastapi.responses import JSONResponse -from os import path, listdir, remove, mkdir +from os import path, listdir, remove, mkdir, getcwd from updater import update import json import logging from typing import List import uvicorn +from sys import path as pt + +root_path = getcwd() +pt.append(root_path) """ Local function @@ -483,4 +487,19 @@ async def open_url(data: URL): return JSONResponse(status_code=400, content={"message": "Failed to open"}) if __name__ == "__main__": - uvicorn.run(app='canvas_app:app',port=9283,reload=False) + name_app = path.basename(__file__)[0:-3] # Get the name of the script + log_config = { + "version": 1, + "disable_existing_loggers": True, + "handlers": { + "file_handler": { + "class": "logging.FileHandler", + "filename": "logfile.log", + }, + }, + "root": { + "handlers": ["file_handler"], + "level": "INFO", + }, + } + uvicorn.run(f'{name_app}:app', port=9283, reload=False,log_config=log_config) From 14800085df750f11defbb90b3c682eb197b40bfd Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sat, 2 Sep 2023 15:49:54 +0800 Subject: [PATCH 04/22] fix: rm wrong file --- start_canvasapp.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 start_canvasapp.py diff --git a/start_canvasapp.py b/start_canvasapp.py deleted file mode 100644 index 3952856..0000000 --- a/start_canvasapp.py +++ /dev/null @@ -1,4 +0,0 @@ -import uvicorn - -if __name__ == "__main__": - uvicorn.run("canvas_app:app", port=9283) From 235e8dcc77feefbe9638d905543582bf12517e40 Mon Sep 17 00:00:00 2001 From: linsyking Date: Sat, 2 Sep 2023 10:07:01 -0400 Subject: [PATCH 05/22] chore: build executables in action --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc42ed5..ebcfc94 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,3 +28,8 @@ jobs: - name: Test run run: | timeout 3 uvicorn canvas_app:app --port 9283 || [ $? -eq 124 ] + - name: Build executables + run: | + pip install pyinstaller + pyinstaller -F canvas_app.py + timeout 3 dist/canvas_app --port 9283 || [ $? -eq 124 ] From 7cadc1866f928cc59897163b93bf421471b91303 Mon Sep 17 00:00:00 2001 From: linsyking Date: Sat, 2 Sep 2023 10:18:09 -0400 Subject: [PATCH 06/22] chore: action file format --- .github/workflows/build.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56d91b9..887ec8a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,20 +14,20 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.7 - uses: actions/setup-python@v3 - with: - python-version: "3.7" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Test run - run: | - timeout 3 uvicorn canvas_app:app --port 9283 || [ $? -eq 124 ] - - name: Build executables - run: | - pip install pyinstaller - pyinstaller -F canvas_app.py - timeout 3 dist/canvas_app --port 9283 || [ $? -eq 124 ] + - uses: actions/checkout@v3 + - name: Set up Python 3.7 + uses: actions/setup-python@v3 + with: + python-version: '3.7' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test run + run: | + timeout 3 uvicorn canvas_app:app --port 9283 || [ $? -eq 124 ] + - name: Build executables + run: | + pip install pyinstaller + pyinstaller -F canvas_app.py + timeout 3 dist/canvas_app --port 9283 || [ $? -eq 124 ] From ce9ab85a73d72948b10db0557ae12b9d5afa65a9 Mon Sep 17 00:00:00 2001 From: linsyking Date: Sat, 2 Sep 2023 10:33:52 -0400 Subject: [PATCH 07/22] chore: format code --- canvas_app.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/canvas_app.py b/canvas_app.py index e9943c6..a3e14ad 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -514,20 +514,21 @@ async def open_url(data: URL): logging.warning(e) return JSONResponse(status_code=400, content={"message": "Failed to open"}) + if __name__ == "__main__": name_app = path.basename(__file__)[0:-3] # Get the name of the script log_config = { - "version": 1, - "disable_existing_loggers": True, - "handlers": { - "file_handler": { - "class": "logging.FileHandler", - "filename": "logfile.log", + "version": 1, + "disable_existing_loggers": True, + "handlers": { + "file_handler": { + "class": "logging.FileHandler", + "filename": "logfile.log", + }, + }, + "root": { + "handlers": ["file_handler"], + "level": "INFO", }, - }, - "root": { - "handlers": ["file_handler"], - "level": "INFO", - }, } - uvicorn.run(f'{name_app}:app', port=9283, reload=False,log_config=log_config) + uvicorn.run(f"{name_app}:app", port=9283, reload=False, log_config=log_config) From bab0a2f31cec77ae1a71773444730d7f102d3849 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sat, 2 Sep 2023 23:41:20 +0800 Subject: [PATCH 08/22] fix: pyinstaller dependencies --- canvas_app.py | 28 +++------------------------- start.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 start.py diff --git a/canvas_app.py b/canvas_app.py index a958b53..f83b9b8 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -8,16 +8,11 @@ import urllib.parse from models import Position, Check, Course, URL from fastapi.responses import JSONResponse -from os import path, listdir, remove, mkdir, getcwd -from updater import update +from os import path, listdir, remove, mkdir +#from updater import update import json import logging from typing import List -import uvicorn -from sys import path as pt - -root_path = getcwd() -pt.append(root_path) """ Local function @@ -60,7 +55,7 @@ def check_file(filename): conf = ConfigMGR() # Self Update -update() +#update() @app.get( @@ -486,20 +481,3 @@ async def open_url(data: URL): logging.warning(e) return JSONResponse(status_code=400, content={"message": "Failed to open"}) -if __name__ == "__main__": - name_app = path.basename(__file__)[0:-3] # Get the name of the script - log_config = { - "version": 1, - "disable_existing_loggers": True, - "handlers": { - "file_handler": { - "class": "logging.FileHandler", - "filename": "logfile.log", - }, - }, - "root": { - "handlers": ["file_handler"], - "level": "INFO", - }, - } - uvicorn.run(f'{name_app}:app', port=9283, reload=False,log_config=log_config) diff --git a/start.py b/start.py new file mode 100644 index 0000000..ac9d524 --- /dev/null +++ b/start.py @@ -0,0 +1,23 @@ +import uvicorn +from sys import path as pt +from os import getcwd, path + +root_path = getcwd() +pt.append(root_path) + +name_app = path.basename(__file__)[0:-3] # Get the name of the script +log_config = { +"version": 1, +"disable_existing_loggers": True, +"handlers": { + "file_handler": { + "class": "logging.FileHandler", + "filename": "logfile.log", + }, +}, +"root": { + "handlers": ["file_handler"], + "level": "INFO", +}, +} +uvicorn.run(f'canvas_app:app', port=9283, reload=False,log_config=log_config) From d6c7c1b9be6234b0d80cb94536ad6db55e472b53 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sat, 2 Sep 2023 23:54:19 +0800 Subject: [PATCH 09/22] fix: pyinstaller --- start.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/start.py b/start.py index ac9d524..09c8b85 100644 --- a/start.py +++ b/start.py @@ -19,5 +19,9 @@ "handlers": ["file_handler"], "level": "INFO", }, +"root": { + "handlers": ["file_handler"], + "level": "INFO", +}, } -uvicorn.run(f'canvas_app:app', port=9283, reload=False,log_config=log_config) +uvicorn.run(f"canvas_app:app", port=9283, reload=False,log_config=log_config) From 006b7b51a2f0eea5c0c67029a182490ecd4292ac Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sun, 3 Sep 2023 10:23:00 +0800 Subject: [PATCH 10/22] fix: add spec file --- .gitignore | 2 +- start.spec | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 start.spec diff --git a/.gitignore b/.gitignore index 9958c27..bd51d72 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ MANIFEST # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest -*.spec +#*.spec # Installer logs pip-log.txt diff --git a/start.spec b/start.spec new file mode 100644 index 0000000..b02119c --- /dev/null +++ b/start.spec @@ -0,0 +1,44 @@ +# -*- mode: python ; coding: utf-8 -*- + + +block_cipher = None + + +a = Analysis( + ['start.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=["fastapi","fastapi.middleware.cors","requests"], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='start', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) From fc26113aba0db48e325425ec90094227a4fe7ca7 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sun, 3 Sep 2023 11:12:11 +0800 Subject: [PATCH 11/22] fix: format the code --- canvas_app.py | 30 ++++++++++++++++-------------- start.py | 32 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/canvas_app.py b/canvas_app.py index 619a9d1..4d9a53e 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -9,7 +9,8 @@ from models import Position, Check, Course, URL from fastapi.responses import JSONResponse from os import path, listdir, remove, mkdir -#from updater import update + +# from updater import update import json import logging from typing import List @@ -73,7 +74,7 @@ def check_file(filename): conf = ConfigMGR() # Self Update -#update() +# update() @app.get( @@ -509,20 +510,21 @@ async def open_url(data: URL): logging.warning(e) return JSONResponse(status_code=400, content={"message": "Failed to open"}) + if __name__ == "__main__": name_app = path.basename(__file__)[0:-3] # Get the name of the script log_config = { - "version": 1, - "disable_existing_loggers": True, - "handlers": { - "file_handler": { - "class": "logging.FileHandler", - "filename": "logfile.log", + "version": 1, + "disable_existing_loggers": True, + "handlers": { + "file_handler": { + "class": "logging.FileHandler", + "filename": "logfile.log", + }, + }, + "root": { + "handlers": ["file_handler"], + "level": "INFO", }, - }, - "root": { - "handlers": ["file_handler"], - "level": "INFO", - }, } - uvicorn.run(f'{name_app}:app', port=9283, reload=False,log_config=log_config) + uvicorn.run(f"{name_app}:app", port=9283, reload=False, log_config=log_config) diff --git a/start.py b/start.py index 09c8b85..4a9fba9 100644 --- a/start.py +++ b/start.py @@ -7,21 +7,21 @@ name_app = path.basename(__file__)[0:-3] # Get the name of the script log_config = { -"version": 1, -"disable_existing_loggers": True, -"handlers": { - "file_handler": { - "class": "logging.FileHandler", - "filename": "logfile.log", + "version": 1, + "disable_existing_loggers": True, + "handlers": { + "file_handler": { + "class": "logging.FileHandler", + "filename": "logfile.log", + }, + }, + "root": { + "handlers": ["file_handler"], + "level": "INFO", + }, + "root": { + "handlers": ["file_handler"], + "level": "INFO", }, -}, -"root": { - "handlers": ["file_handler"], - "level": "INFO", -}, -"root": { - "handlers": ["file_handler"], - "level": "INFO", -}, } -uvicorn.run(f"canvas_app:app", port=9283, reload=False,log_config=log_config) +uvicorn.run(f"canvas_app:app", port=9283, reload=False, log_config=log_config) From 80adf71d6f8cca35d44edeb7615ff68469ae53cd Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sun, 3 Sep 2023 11:32:03 +0800 Subject: [PATCH 12/22] chore: add makefile --- .gitignore | 2 +- Makefile | 13 +++++++++++++ canvas_app.py | 4 ---- start.spec | 44 -------------------------------------------- updater.py | 33 --------------------------------- 5 files changed, 14 insertions(+), 82 deletions(-) create mode 100644 Makefile delete mode 100644 start.spec delete mode 100644 updater.py diff --git a/.gitignore b/.gitignore index bd51d72..9958c27 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ MANIFEST # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest -#*.spec +*.spec # Installer logs pip-log.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f346466 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +COMPILE_SRC=start.py + +all: + pyinstaller --onefile --hidden-import fastapi --hidden-import fastapi.middleware.cors --hidden-import requests $(COMPILE_SRC) + +clean: + rm -r build dist *.spec *.log + +format: + black *.py + +run: + ./dist/start diff --git a/canvas_app.py b/canvas_app.py index 4d9a53e..510eced 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -10,7 +10,6 @@ from fastapi.responses import JSONResponse from os import path, listdir, remove, mkdir -# from updater import update import json import logging from typing import List @@ -73,9 +72,6 @@ def check_file(filename): conf = ConfigMGR() -# Self Update -# update() - @app.get( "/config", diff --git a/start.spec b/start.spec deleted file mode 100644 index b02119c..0000000 --- a/start.spec +++ /dev/null @@ -1,44 +0,0 @@ -# -*- mode: python ; coding: utf-8 -*- - - -block_cipher = None - - -a = Analysis( - ['start.py'], - pathex=[], - binaries=[], - datas=[], - hiddenimports=["fastapi","fastapi.middleware.cors","requests"], - hookspath=[], - hooksconfig={}, - runtime_hooks=[], - excludes=[], - win_no_prefer_redirects=False, - win_private_assemblies=False, - cipher=block_cipher, - noarchive=False, -) -pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) - -exe = EXE( - pyz, - a.scripts, - a.binaries, - a.zipfiles, - a.datas, - [], - name='start', - debug=False, - bootloader_ignore_signals=False, - strip=False, - upx=True, - upx_exclude=[], - runtime_tmpdir=None, - console=True, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, -) diff --git a/updater.py b/updater.py deleted file mode 100644 index a3f23e5..0000000 --- a/updater.py +++ /dev/null @@ -1,33 +0,0 @@ -# coding=utf-8 -""" -@Author: King -@Date: 2023-02-16 12:12:05 -@Email: linsy_king@sjtu.edu.cn -""" - - -import git -import os -import logging - -""" -Update git repo automatically -""" - - -def update(): - try: - repo = git.Repo(os.path.dirname(__file__)) - current = repo.head.commit - logging.info(f"Current version: {current}") - repo.remotes.origin.pull() - new = repo.head.commit - if current != new: - logging.info(f"Updated to {new}") - except Exception as e: - logging.error(e) - logging.error("Cannot update") - - -if __name__ == "__main__": - update() From cfbb33dea30270a76379ed67ec5d6f2ef3a3f4f4 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Sun, 3 Sep 2023 21:39:16 +0800 Subject: [PATCH 13/22] fix: remove git dependency --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1580c2f..0cac294 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,3 @@ requests fastapi uvicorn python-multipart -GitPython From df7a8d85e6c9ecf63275ce5b3cd0ae5495a409bc Mon Sep 17 00:00:00 2001 From: linsyking Date: Sun, 3 Sep 2023 10:38:34 -0400 Subject: [PATCH 14/22] fix: pyinstaller --- .github/workflows/build.yml | 4 ++-- Makefile | 4 ++-- canvas_app.py | 19 --------------- models.py | 5 ---- start.py | 46 ++++++++++++++++++------------------- 5 files changed, 27 insertions(+), 51 deletions(-) mode change 100644 => 100755 start.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 887ec8a..7e40a3d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,5 +29,5 @@ jobs: - name: Build executables run: | pip install pyinstaller - pyinstaller -F canvas_app.py - timeout 3 dist/canvas_app --port 9283 || [ $? -eq 124 ] + pyinstaller -F start.py + timeout 3 dist/start --port 9283 || [ $? -eq 124 ] diff --git a/Makefile b/Makefile index f346466..fcadb62 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ COMPILE_SRC=start.py all: - pyinstaller --onefile --hidden-import fastapi --hidden-import fastapi.middleware.cors --hidden-import requests $(COMPILE_SRC) + pyinstaller -F $(COMPILE_SRC) clean: rm -r build dist *.spec *.log format: - black *.py + black . run: ./dist/start diff --git a/canvas_app.py b/canvas_app.py index 510eced..c1e0136 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -505,22 +505,3 @@ async def open_url(data: URL): except Exception as e: logging.warning(e) return JSONResponse(status_code=400, content={"message": "Failed to open"}) - - -if __name__ == "__main__": - name_app = path.basename(__file__)[0:-3] # Get the name of the script - log_config = { - "version": 1, - "disable_existing_loggers": True, - "handlers": { - "file_handler": { - "class": "logging.FileHandler", - "filename": "logfile.log", - }, - }, - "root": { - "handlers": ["file_handler"], - "level": "INFO", - }, - } - uvicorn.run(f"{name_app}:app", port=9283, reload=False, log_config=log_config) diff --git a/models.py b/models.py index 56e65cd..9f99472 100644 --- a/models.py +++ b/models.py @@ -1,9 +1,4 @@ #!/usr/bin/env python3 -""" -@Author: King -@Date: 2023-01-04 21:24:24 -@Email: linsy_king@sjtu.edu.cn -""" from pydantic import BaseModel, Field from typing import Union diff --git a/start.py b/start.py old mode 100644 new mode 100755 index 4a9fba9..eb1e931 --- a/start.py +++ b/start.py @@ -1,27 +1,27 @@ +#!/usr/bin/env python3 + import uvicorn -from sys import path as pt -from os import getcwd, path +from canvas_app import app + +""" +Start script +""" -root_path = getcwd() -pt.append(root_path) -name_app = path.basename(__file__)[0:-3] # Get the name of the script -log_config = { - "version": 1, - "disable_existing_loggers": True, - "handlers": { - "file_handler": { - "class": "logging.FileHandler", - "filename": "logfile.log", +if __name__ == "__main__": + log_config = { + "version": 1, + "disable_existing_loggers": True, + "handlers": { + "file_handler": { + "class": "logging.FileHandler", + "filename": "error.log", + }, }, - }, - "root": { - "handlers": ["file_handler"], - "level": "INFO", - }, - "root": { - "handlers": ["file_handler"], - "level": "INFO", - }, -} -uvicorn.run(f"canvas_app:app", port=9283, reload=False, log_config=log_config) + "root": { + "handlers": ["file_handler"], + "level": "INFO", + }, + } + + uvicorn.run(app, port=9283, reload=False, log_config=log_config) From 12f97ee462629a52efe5c9da8bf9b8aeb362b75f Mon Sep 17 00:00:00 2001 From: linsyking Date: Sun, 3 Sep 2023 10:41:48 -0400 Subject: [PATCH 15/22] fix: log level changed to error --- start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.py b/start.py index eb1e931..1d8cd9d 100755 --- a/start.py +++ b/start.py @@ -20,7 +20,7 @@ }, "root": { "handlers": ["file_handler"], - "level": "INFO", + "level": "ERROR", }, } From f0a096ef3b471fca013de9180edf6e442fb1e15e Mon Sep 17 00:00:00 2001 From: linsyking Date: Sun, 3 Sep 2023 11:05:14 -0400 Subject: [PATCH 16/22] fix: use makedirs instead of mkdir --- canvas_app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/canvas_app.py b/canvas_app.py index c1e0136..b41f372 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -8,7 +8,7 @@ import urllib.parse from models import Position, Check, Course, URL from fastapi.responses import JSONResponse -from os import path, listdir, remove, mkdir +from os import path, listdir, remove, makedirs import json import logging @@ -369,7 +369,7 @@ async def set_check(name: str, check: Check): """ Check - Only 1,2,3 is available + Only 1, 2, 3 is available """ if check.type < 0 or check.type > 3: return JSONResponse(status_code=400, content={"message": "Invalid check type"}) @@ -432,7 +432,7 @@ async def update_position(position: Position): ) async def upload_file(file: UploadFile): if not path.exists("./public/res"): - mkdir("./public/res") + makedirs("./public/res", exist_ok=True) tmp = check_file(file.filename) if tmp == "Illegal": return JSONResponse(status_code=404, content={"message": "Illegal file name"}) @@ -468,7 +468,7 @@ async def get_file_list(): if path.exists("./public/res"): return {"files": listdir("./public/res")} else: - mkdir("./public/res") + makedirs("./public/res", exist_ok=True) return {"files": []} From ae3263fd893437822b3917d4556d6c7cdee9243a Mon Sep 17 00:00:00 2001 From: linsyking Date: Sun, 3 Sep 2023 11:26:03 -0400 Subject: [PATCH 17/22] chore: make windows exe --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fcadb62..34ed9ce 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ -COMPILE_SRC=start.py +START_SRC=start.py all: - pyinstaller -F $(COMPILE_SRC) + pyinstaller -F $(START_SRC) + +windows: + wine pyinstaller -F $(START_SRC) clean: rm -r build dist *.spec *.log From c4cc836ddf8f490265e2438e1b411826b0bce18f Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Wed, 6 Sep 2023 15:02:19 +0800 Subject: [PATCH 18/22] feat: read net_config --- start.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/start.py b/start.py index 1d8cd9d..2b21fd1 100755 --- a/start.py +++ b/start.py @@ -2,6 +2,7 @@ import uvicorn from canvas_app import app +import json """ Start script @@ -9,6 +10,8 @@ if __name__ == "__main__": + net_config = {} + log_config = { "version": 1, "disable_existing_loggers": True, @@ -24,4 +27,10 @@ }, } - uvicorn.run(app, port=9283, reload=False, log_config=log_config) + with open("net_config.json", "r", encoding="utf-8", errors="ignore") as f: + net_config = json.load(f) + + usr_host = net_config["host"] + usr_port = net_config["port"] + + uvicorn.run(app, port=usr_port, host=usr_host, reload=False, log_config=log_config) From a27b195e50c0b969d040ce25903c04fbcf206e42 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Wed, 6 Sep 2023 15:19:10 +0800 Subject: [PATCH 19/22] feat: add default host and port --- start.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/start.py b/start.py index 2b21fd1..355508a 100755 --- a/start.py +++ b/start.py @@ -33,4 +33,9 @@ usr_host = net_config["host"] usr_port = net_config["port"] + if usr_host == "": + usr_host = "localhost" + if usr_port == "": + usr_port = 9283 + uvicorn.run(app, port=usr_port, host=usr_host, reload=False, log_config=log_config) From 1f41821dca73e0294e777b4cfeef59a848d8e124 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 7 Sep 2023 21:43:56 +0800 Subject: [PATCH 20/22] fix: condition without net_config --- start.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/start.py b/start.py index 355508a..e0e0b7c 100755 --- a/start.py +++ b/start.py @@ -3,6 +3,7 @@ import uvicorn from canvas_app import app import json +from os import path """ Start script @@ -27,15 +28,19 @@ }, } - with open("net_config.json", "r", encoding="utf-8", errors="ignore") as f: - net_config = json.load(f) + if path.exists("net_config.json"): + with open("net_config.json", "r", encoding="utf-8", errors="ignore") as f: + net_config = json.load(f) - usr_host = net_config["host"] - usr_port = net_config["port"] + usr_host = net_config["host"] + usr_port = net_config["port"] - if usr_host == "": - usr_host = "localhost" - if usr_port == "": - usr_port = 9283 + if usr_host == "": + usr_host = "localhost" + if usr_port == "": + usr_port = 9283 + else: + usr_host = "localhost" + usr_port = 9283 uvicorn.run(app, port=usr_port, host=usr_host, reload=False, log_config=log_config) From 080f12b9b607d4ab32715d5f58fcc05967482eac Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Tue, 16 Jan 2024 19:24:41 +0800 Subject: [PATCH 21/22] fix: duplicate code --- net_config.json | 4 ++++ start.py | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 net_config.json diff --git a/net_config.json b/net_config.json new file mode 100644 index 0000000..0f06303 --- /dev/null +++ b/net_config.json @@ -0,0 +1,4 @@ +{ + "host": "localhost", + "port": 9283 +} diff --git a/start.py b/start.py index e0e0b7c..8b288cf 100755 --- a/start.py +++ b/start.py @@ -32,13 +32,13 @@ with open("net_config.json", "r", encoding="utf-8", errors="ignore") as f: net_config = json.load(f) + if "host" not in net_config: + raise Exception("no host") + elif "port" not in net_config: + raise Exception("no port") + usr_host = net_config["host"] usr_port = net_config["port"] - - if usr_host == "": - usr_host = "localhost" - if usr_port == "": - usr_port = 9283 else: usr_host = "localhost" usr_port = 9283 From 25a7d112fb5fb1d7a688d037e397ed40363ae836 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Wed, 17 Jan 2024 14:13:44 +0800 Subject: [PATCH 22/22] fix: fail to upload figures --- canvas_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/canvas_app.py b/canvas_app.py index 08efd22..dd41d9c 100755 --- a/canvas_app.py +++ b/canvas_app.py @@ -37,13 +37,14 @@ # INFO: Safety check for file def check_file(filename): base_path = "/public/res/" + base_path_win = "\\public\\res\\" fullPath = path.normpath(path.join(base_path, filename)) if ( not "." in filename or not filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSION ): return "Illegal" - if not fullPath.startswith(base_path): + if not fullPath.startswith(base_path) and not fullPath.startswith(base_path_win): return "Illegal" else: return filename