packed ver test ok
This commit is contained in:
parent
8cfd83f768
commit
6f6949492b
5
.gitignore
vendored
5
.gitignore
vendored
@ -10,4 +10,7 @@ $*
|
||||
venv/
|
||||
__pycache__/
|
||||
.vscode/
|
||||
file_storage/
|
||||
file_storage/
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
@ -1,5 +1,5 @@
|
||||
include src/sql/db_create.sql
|
||||
include src/sql/trigger.sql
|
||||
graft src/static
|
||||
graft src/templates
|
||||
include ebookman/sql/db_create.sql
|
||||
include ebookman/sql/trigger.sql
|
||||
graft ebookman/static
|
||||
graft ebookman/templates
|
||||
global-exclude *.pyc
|
||||
46
README.md
46
README.md
@ -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
|
||||
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
|
||||
```
|
||||
|
||||
使用之前,需要新整一个mysql服务器,然后在里面建立一个数据库bigwork并保证该数据库被授权给了指定的用户。
|
||||
在config里面修改对应的用户、密码、服务器地址
|
||||
使用之前,需要mysql服务器,然后在里面建立一个数据库并保证该数据库被授权给了指定的用户。在`./instance/config.py`里面修改对应的用户、密码、服务器地址等信息。
|
||||
|
||||
## 安装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目录下面
|
||||
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from flask import Flask, render_template, g, redirect, url_for
|
||||
from datetime import datetime
|
||||
@ -6,6 +7,7 @@ from datetime import datetime
|
||||
def create_app(test_config=None):
|
||||
# create and configure the app
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
print(app.instance_path)
|
||||
if test_config is None:
|
||||
app.config.from_pyfile('config.py', silent=False)
|
||||
else:
|
||||
@ -14,7 +16,6 @@ def create_app(test_config=None):
|
||||
if not os.path.exists(app.config['UPLOADDIR']):
|
||||
os.mkdir(app.config['UPLOADDIR'])
|
||||
# print(app.config.keys())
|
||||
print(app.instance_path)
|
||||
try:
|
||||
os.makedirs(app.instance_path)
|
||||
except OSError:
|
||||
|
||||
@ -6,8 +6,8 @@ import os
|
||||
from werkzeug.exceptions import abort
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
from src.auth import admin_login_required
|
||||
from src.db import get_db
|
||||
from ebookman.auth import admin_login_required
|
||||
from ebookman.db import get_db
|
||||
from datetime import datetime
|
||||
import pymysql
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import functools
|
||||
from flask import Blueprint, flash, g, redirect, render_template, request, session, url_for
|
||||
from werkzeug.security import check_password_hash
|
||||
from src.db import get_db
|
||||
from ebookman.db import get_db
|
||||
from datetime import datetime
|
||||
|
||||
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||
|
||||
@ -3,6 +3,7 @@ import pymysql
|
||||
import click
|
||||
from flask import current_app, g
|
||||
from werkzeug.security import generate_password_hash
|
||||
import os
|
||||
|
||||
def get_db():
|
||||
if 'db' not in g:
|
||||
@ -52,18 +53,19 @@ def parse_sql(filename):
|
||||
|
||||
@click.command('init-db')
|
||||
def init_db():
|
||||
scriptpath = os.path.split(os.path.realpath(__file__))[0]
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
click.echo("PyMySQL do not support script execution...")
|
||||
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:
|
||||
cur.execute(sql)
|
||||
db.commit()
|
||||
# with current_app.open_resource('sql/db_create_sqlite.sql') as f:
|
||||
# db.executescript(f.read().decode('utf8'))
|
||||
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:
|
||||
cur.execute(sql)
|
||||
db.commit()
|
||||
|
||||
@ -3,8 +3,8 @@ from flask import (
|
||||
)
|
||||
|
||||
import os
|
||||
from src.auth import login_required
|
||||
from src.db import get_db
|
||||
from ebookman.auth import login_required
|
||||
from ebookman.db import get_db
|
||||
import pymysql
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user