packed ver test ok

This commit is contained in:
ridethepig 2022-12-13 00:06:37 +08:00
parent 8cfd83f768
commit 6f6949492b
9 changed files with 63 additions and 17 deletions

3
.gitignore vendored
View File

@ -11,3 +11,6 @@ venv/
__pycache__/ __pycache__/
.vscode/ .vscode/
file_storage/ file_storage/
*.egg-info/
dist/
build/

View File

@ -1,5 +1,5 @@
include src/sql/db_create.sql include ebookman/sql/db_create.sql
include src/sql/trigger.sql include ebookman/sql/trigger.sql
graft src/static graft ebookman/static
graft src/templates graft ebookman/templates
global-exclude *.pyc global-exclude *.pyc

View File

@ -1,16 +1,54 @@
# 电子书管理系统 # 电子书管理系统
> 数据库大作业 > 数据库大作业说明
## 配置文件
```py
SECRET_KEY='dev' #可以随机生成一个,比较安全
DATABASE='bigwork' #需要给它一个新的database
DATABASE_USER='root' #用户名,确保该用户对上面的数据库有权限
DATABASE_HOST='xxx.xxx.xxx.xxx' # mysql服务器地址
DATABASE_PASS='xxxxxxxxx' # 数据库用户密码
UPLOADDIR="file_storage/" # 上传后文件的存放目录
ADMIN_PASS="123456" # 管理员密码
```
文件名为`config.py`,放在某个`instance/`下面
## 运行源代码 ## 运行源代码
```shell ```shell
python -m venv venv python -m venv venv
pip install flask ./venv/Scripts/Activate.ps1
pip install flask, pymysql, cryptography
# edit config.py to
flask --app ebookman init-db
flask --app ebookman run flask --app ebookman run
``` ```
使用之前需要新整一个mysql服务器然后在里面建立一个数据库bigwork并保证该数据库被授权给了指定的用户。 使用之前需要mysql服务器然后在里面建立一个数据库并保证该数据库被授权给了指定的用户。在`./instance/config.py`里面修改对应的用户、密码、服务器地址等信息。
在config里面修改对应的用户、密码、服务器地址
## 安装whl格式的安装包
```shell
python -m venv venv
./venv/Scripts/Activate.ps1
pip install ebookman-1.0.0-py3-none-any.whl
mkdir -p ./venv/var/ebookman-instance/
# 向./venv/var/ebookman-instance/config.py中写入配置
flask --app ebookman init-db
flask --app ebookman run
```
上传的文件在`./file_storage`目录下
## 打包whl安装包
```shell
pip install wheel
python setup.py bdist_wheel
```
生成的whl在dist目录下面

View File

@ -1,4 +1,5 @@
import os import os
import sys
from flask import Flask, render_template, g, redirect, url_for from flask import Flask, render_template, g, redirect, url_for
from datetime import datetime from datetime import datetime
@ -6,6 +7,7 @@ from datetime import datetime
def create_app(test_config=None): def create_app(test_config=None):
# create and configure the app # create and configure the app
app = Flask(__name__, instance_relative_config=True) app = Flask(__name__, instance_relative_config=True)
print(app.instance_path)
if test_config is None: if test_config is None:
app.config.from_pyfile('config.py', silent=False) app.config.from_pyfile('config.py', silent=False)
else: else:
@ -14,7 +16,6 @@ def create_app(test_config=None):
if not os.path.exists(app.config['UPLOADDIR']): if not os.path.exists(app.config['UPLOADDIR']):
os.mkdir(app.config['UPLOADDIR']) os.mkdir(app.config['UPLOADDIR'])
# print(app.config.keys()) # print(app.config.keys())
print(app.instance_path)
try: try:
os.makedirs(app.instance_path) os.makedirs(app.instance_path)
except OSError: except OSError:

View File

@ -6,8 +6,8 @@ import os
from werkzeug.exceptions import abort from werkzeug.exceptions import abort
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
from src.auth import admin_login_required from ebookman.auth import admin_login_required
from src.db import get_db from ebookman.db import get_db
from datetime import datetime from datetime import datetime
import pymysql import pymysql

View File

@ -1,7 +1,7 @@
import functools import functools
from flask import Blueprint, flash, g, redirect, render_template, request, session, url_for from flask import Blueprint, flash, g, redirect, render_template, request, session, url_for
from werkzeug.security import check_password_hash from werkzeug.security import check_password_hash
from src.db import get_db from ebookman.db import get_db
from datetime import datetime from datetime import datetime
bp = Blueprint('auth', __name__, url_prefix='/auth') bp = Blueprint('auth', __name__, url_prefix='/auth')

View File

@ -3,6 +3,7 @@ import pymysql
import click import click
from flask import current_app, g from flask import current_app, g
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
import os
def get_db(): def get_db():
if 'db' not in g: if 'db' not in g:
@ -52,18 +53,19 @@ def parse_sql(filename):
@click.command('init-db') @click.command('init-db')
def init_db(): def init_db():
scriptpath = os.path.split(os.path.realpath(__file__))[0]
db = get_db() db = get_db()
cur = db.cursor() cur = db.cursor()
click.echo("PyMySQL do not support script execution...") click.echo("PyMySQL do not support script execution...")
click.echo("Initializing database schema...") click.echo("Initializing database schema...")
sqls = parse_sql("sql/db_create.sql") sqls = parse_sql(os.path.join(scriptpath,"./sql/db_create.sql"))
for sql in sqls: for sql in sqls:
cur.execute(sql) cur.execute(sql)
db.commit() db.commit()
# with current_app.open_resource('sql/db_create_sqlite.sql') as f: # with current_app.open_resource('sql/db_create_sqlite.sql') as f:
# db.executescript(f.read().decode('utf8')) # db.executescript(f.read().decode('utf8'))
click.echo("Initializing database triggers...") click.echo("Initializing database triggers...")
sqls = parse_sql("sql/trigger.sql") sqls = parse_sql(os.path.join(scriptpath,"./sql/trigger.sql"))
for sql in sqls: for sql in sqls:
cur.execute(sql) cur.execute(sql)
db.commit() db.commit()

View File

@ -3,8 +3,8 @@ from flask import (
) )
import os import os
from src.auth import login_required from ebookman.auth import login_required
from src.db import get_db from ebookman.db import get_db
import pymysql import pymysql
from datetime import datetime from datetime import datetime

View File

@ -7,5 +7,7 @@ setup(
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[
'flask', 'flask',
'cryptography',
'pymysql',
], ],
) )