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