mirror of
https://github.com/Kakune55/ComiPy.git
synced 2025-05-06 10:19:27 +08:00
更改配置文件的存取方式
This commit is contained in:
parent
30d99c1f08
commit
b8904c32e3
9
app_conf.py
Normal file
9
app_conf.py
Normal file
@ -0,0 +1,9 @@
|
||||
import configparser , os
|
||||
|
||||
def conf():
|
||||
conf = configparser.ConfigParser()
|
||||
if os.path.exists('./conf/app.ini'):
|
||||
conf.read('./conf/app.ini')
|
||||
else:
|
||||
conf.read('./conf/app_d.ini')
|
||||
return conf
|
@ -1,12 +1,11 @@
|
||||
import sqlite3, configparser
|
||||
import db.util as util
|
||||
import db.util as util, app_conf
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("./conf/app.ini")
|
||||
conf = app_conf.conf()
|
||||
|
||||
|
||||
def getConn():
|
||||
return sqlite3.connect(config.get("database", "path"))
|
||||
return sqlite3.connect(conf.get("database", "path"))
|
||||
|
||||
|
||||
def new(username: str, password: int):
|
||||
|
@ -1,11 +1,11 @@
|
||||
import sqlite3, configparser
|
||||
import app_conf
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("./conf/app.ini")
|
||||
conf = app_conf.conf()
|
||||
|
||||
|
||||
def getConn():
|
||||
return sqlite3.connect(config.get("database", "path"))
|
||||
return sqlite3.connect(conf.get("database", "path"))
|
||||
|
||||
|
||||
def init():
|
||||
|
31
file.py
31
file.py
@ -1,33 +1,31 @@
|
||||
import shutil, os, configparser, zipfile, io
|
||||
import db.file
|
||||
import shutil, os, zipfile, io
|
||||
import db.file, app_conf
|
||||
from PIL import Image
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("./conf/app.ini")
|
||||
|
||||
app_conf = app_conf.conf()
|
||||
|
||||
def init():
|
||||
try:
|
||||
os.makedirs(config.get("file", "inputdir"))
|
||||
os.makedirs(config.get("file", "storedir"))
|
||||
os.makedirs(config.get("file", "tmpdir"))
|
||||
os.makedirs(app_conf.get("file", "inputdir"))
|
||||
os.makedirs(app_conf.get("file", "storedir"))
|
||||
os.makedirs(app_conf.get("file", "tmpdir"))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def auotLoadFile():
|
||||
fileList = os.listdir(config.get("file", "inputdir"))
|
||||
fileList = os.listdir(app_conf.get("file", "inputdir"))
|
||||
for item in fileList:
|
||||
if zipfile.is_zipfile(
|
||||
config.get("file", "inputdir") + "/" + item
|
||||
app_conf.get("file", "inputdir") + "/" + item
|
||||
): # 判断是否为压缩包
|
||||
with zipfile.ZipFile(
|
||||
config.get("file", "inputdir") + "/" + item, "r"
|
||||
app_conf.get("file", "inputdir") + "/" + item, "r"
|
||||
) as zip_ref:
|
||||
db.file.new(item, len(zip_ref.namelist())) # 添加数据库记录 移动到存储
|
||||
shutil.move(
|
||||
config.get("file", "inputdir") + "/" + item,
|
||||
config.get("file", "storedir") + "/" + item,
|
||||
app_conf.get("file", "inputdir") + "/" + item,
|
||||
app_conf.get("file", "storedir") + "/" + item,
|
||||
)
|
||||
print("已添加 " + item)
|
||||
else:
|
||||
@ -36,7 +34,7 @@ def auotLoadFile():
|
||||
|
||||
def raedZip(bookid: str, index: int):
|
||||
bookinfo = db.file.searchByid(bookid)
|
||||
zippath = config.get("file", "storedir") + "/" + bookinfo[0][2]
|
||||
zippath = app_conf.get("file", "storedir") + "/" + bookinfo[0][2]
|
||||
|
||||
try:
|
||||
# 创建一个ZipFile对象
|
||||
@ -68,7 +66,7 @@ def raedZip(bookid: str, index: int):
|
||||
return str(e), ""
|
||||
|
||||
|
||||
def thumbnail(input,size=(400,800)):
|
||||
def thumbnail(input,size=(420,600)):
|
||||
im = Image.open(io.BytesIO(input))
|
||||
del input
|
||||
newimg = im.convert('RGB')
|
||||
@ -80,11 +78,12 @@ def thumbnail(input,size=(400,800)):
|
||||
output_io.seek(0)
|
||||
return output_io
|
||||
|
||||
def imageToWebP(input):
|
||||
def imageToWebP(input,size=(2100,3000)):
|
||||
with Image.open(io.BytesIO(input)) as img:
|
||||
newimg = img.convert('RGB')
|
||||
img.close()
|
||||
output_io = io.BytesIO()
|
||||
newimg.thumbnail(size)
|
||||
newimg.save(output_io,format='WEBP')
|
||||
newimg.close()
|
||||
output_io.seek(0)
|
||||
|
14
main.py
14
main.py
@ -1,4 +1,4 @@
|
||||
import configparser
|
||||
import app_conf
|
||||
import db.util
|
||||
import db.file, file
|
||||
from flask import *
|
||||
@ -8,9 +8,7 @@ from web.page import page_bp
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("./conf/app.ini")
|
||||
|
||||
conf = app_conf.conf()
|
||||
|
||||
def appinit():
|
||||
file.init()
|
||||
@ -24,8 +22,8 @@ app.register_blueprint(page_bp)
|
||||
if __name__ == "__main__":
|
||||
appinit()
|
||||
app.run(
|
||||
debug=config.getboolean("server", "debug"),
|
||||
host=config.get("server", "host"),
|
||||
port=config.get("server", "port"),
|
||||
threaded=config.getboolean("server", "threaded"),
|
||||
debug=conf.getboolean("server", "debug"),
|
||||
host=conf.get("server", "host"),
|
||||
port=conf.get("server", "port"),
|
||||
threaded=conf.getboolean("server", "threaded"),
|
||||
)
|
||||
|
14
web/page.py
14
web/page.py
@ -1,13 +1,11 @@
|
||||
from flask import *
|
||||
from flask import Blueprint
|
||||
import configparser, time
|
||||
import db.file, file
|
||||
import time
|
||||
import db.file, file , app_conf
|
||||
|
||||
page_bp = Blueprint("page_bp", __name__)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("./conf/app.ini")
|
||||
|
||||
conf = app_conf.conf()
|
||||
|
||||
@page_bp.route("/overview/<page>")
|
||||
def overview(page): # 概览
|
||||
@ -67,7 +65,7 @@ def upload_file():
|
||||
uploaded_file = request.files.getlist("files[]") # 获取上传的文件列表
|
||||
for fileitem in uploaded_file:
|
||||
if fileitem.filename != "":
|
||||
fileitem.save(config.get("file", "inputdir") + "/" + fileitem.filename)
|
||||
fileitem.save(conf.get("file", "inputdir") + "/" + fileitem.filename)
|
||||
file.auotLoadFile()
|
||||
return redirect("/")
|
||||
|
||||
@ -79,9 +77,9 @@ def login(): # 登录页面
|
||||
return redirect("/overview/1")
|
||||
return render_template("login.html")
|
||||
elif request.method == "POST":
|
||||
if request.form["username"] == config.get("user", "username") and request.form[
|
||||
if request.form["username"] == conf.get("user", "username") and request.form[
|
||||
"password"
|
||||
] == config.get("user", "password"):
|
||||
] == conf.get("user", "password"):
|
||||
resp = make_response(redirect("/overview/1"))
|
||||
resp.set_cookie("islogin", "True")
|
||||
return resp
|
||||
|
Loading…
x
Reference in New Issue
Block a user