Skip to content

Commit

Permalink
修正重修正安装时的重启错误;
Browse files Browse the repository at this point in the history
修正前端首页的URL错误;
新增模板切换功能;
新增后端重启按钮;
  • Loading branch information
Hackxiaoya committed Apr 2, 2019
1 parent e6aa83f commit b27ae7e
Show file tree
Hide file tree
Showing 45 changed files with 16,389 additions and 45 deletions.
55 changes: 55 additions & 0 deletions app/admin/system/logic.py
@@ -1 +1,56 @@
# -*- coding:utf-8 -*-
import os, time
import configparser



"""
Get Themes Config List
@Author: yyyvy <76836785@qq.com>
@Description:
@Time: 2019-04-02
"""
def get_themes_list():
path = os.getcwd()+"/app/templates/themes"
path_list = os.listdir(path)
data_list = []
for item in path_list:
conf = configparser.ConfigParser()
conf.read("{}/{}/config.ini".format(path, item), encoding="utf-8")
options = conf.items('config')
temp = {}
for i in options:
temp[i[0]] = i[1]
temp['img'] = "/static/themes/{}/cover.png".format(options[1][1])
data_list.append(temp)
return data_list


"""
Modify Themes Config
@Author: yyyvy <76836785@qq.com>
@Description:
@Time: 2019-04-02
name: Themes Name
"""
def modify_themes_config(name):
path = os.getcwd() + "/app/templates/themes"
path_list = os.listdir(path)
config_path = os.getcwd()+"/config.py"
result = ''
with open(config_path, 'r', encoding='UTF-8') as f:
for line in f.readlines():
if (line.find('THEMES') == 0):
line = 'THEMES = %s' % ('\"' + name + '\"\n')
result += line
with open(config_path, 'w', encoding='UTF-8') as f:
f.writelines(result)

for item in path_list:
conf = configparser.ConfigParser()
conf.read("{}/{}/config.ini".format(path, item), encoding="utf-8")
if item == name:
conf.set("config", "status", "1")
else:
conf.set("config", "status", "0")
conf.write(open("{}/{}/config.ini".format(path, item), "w"))
24 changes: 22 additions & 2 deletions app/admin/system/views.py
Expand Up @@ -4,14 +4,22 @@
import config
from .. import admin
from ..system import models
from ..system import logic
from app import common
from app import decorators



@admin.route('/system/restart', methods=['GET', 'POST']) # restart
@decorators.login_require
def restart():
common.restart()
return json.dumps({"code": 0, "msg": "成功!"})


@admin.route('/system/manage') # 管理
@decorators.login_require
def manage(): # 执行的方法
def manage():
info = common.SystemInfo
result = {
"name": info["name"],
Expand Down Expand Up @@ -85,4 +93,16 @@ def upload_bg():
file_path = os.getcwd()+"/app/static/uploads/site_background.jpg"
img.save(file_path)
url = "/static/uploads/site_background.jpg"
return json.dumps({"code": 0, "msg": "", "data": {"src": url}})
return json.dumps({"code": 0, "msg": "", "data": {"src": url}})


@admin.route('/system/themes', methods=['GET', 'POST'])
@decorators.login_require
def themes():
if request.method == 'GET':
themes_list = logic.get_themes_list()
return render_template('admin/system/themes.html', top_nav='system', activity_nav='themes', data=themes_list)
else:
name = request.form['name']
logic.modify_themes_config(name)
return json.dumps({"code": 0, "msg": "保存成功!"})
18 changes: 14 additions & 4 deletions app/common.py
Expand Up @@ -10,7 +10,7 @@
SystemInfo = {
"name": "CuteOne",
"versionType": "Free",
"versions": "1.1.0",
"versions": "1.2.0",
"server": ""
}

Expand Down Expand Up @@ -65,8 +65,6 @@ def size_cov(size):
return size




"""
执行shell指令
@Author: yyyvy <76836785@qq.com>
Expand Down Expand Up @@ -102,4 +100,16 @@ def isRunning(process_name):
@Time: 2019-03-17
"""
def get_web_site():
return systemModels.config.get_web_site()
return systemModels.config.get_web_site()



"""
restart web
@Author: yyyvy <76836785@qq.com>
@Description:
@Time: 2019-04-02
"""
def restart():
command = "python3 {}/app/task/restart.py".format(os.getcwd())
run_command(command)
13 changes: 8 additions & 5 deletions app/main/index/views.py
Expand Up @@ -5,6 +5,9 @@
from app.admin.system import models as systemModels
from ..index import index
from ..index import logic
import config
THEMES = 'themes/'+ config.THEMES +'/'


@index.before_request
def toggle_web_site():
Expand All @@ -17,7 +20,7 @@ def toggle_web_site():
if drive:
author = logic.author_judge(drive, path)
if author:
return render_template('index/author.html', drive_id=drive, path=path)
return render_template(THEMES+'index/author.html', drive_id=drive, path=path)


# 基本配置
Expand Down Expand Up @@ -49,7 +52,7 @@ def drive_list():

crumbs_list_data.append({"path": crumbs_list[i], "name": name})
else:
crumbs_url = path
crumbs_url = url_path
crumbs_list_data = []
return dict(drive_list=drive_list, crumbs_url=crumbs_url, crumbs_list_data=crumbs_list_data)

Expand Down Expand Up @@ -95,15 +98,15 @@ def _index():
data = logic.get_data(disk_id, '', search, sortTable, sortType, page_number)
current_url = '/?drive={}&disk={}&path='.format(activate.id, disk_id)

return render_template('index/index.html', activity_nav='index', drive_id=drive, disk_id=disk_id, current_url=current_url, data=data["data"], pagination=data["pagination"])
return render_template(THEMES+'index/index.html', activity_nav='index', drive_id=drive, disk_id=disk_id, current_url=current_url, data=data["data"], pagination=data["pagination"])


@index.route('/video/<int:drive_id>/<int:disk_id>/<string:id>')
def video(drive_id, disk_id, id):
data = logic.get_downloadUrl(drive_id, disk_id, id)
share_url = "/video/{}/{}/{}".format(drive_id, disk_id, id)
donw_url = "/down_file/{}/{}/{}".format(drive_id, disk_id, id)
return render_template('index/video.html', share_url=share_url, donw_url=donw_url, data=data)
return render_template(THEMES+'index/video.html', share_url=share_url, donw_url=donw_url, data=data)


@index.route('/get_downloadUrl/<int:drive_id>/<int:disk_id>/<string:id>')
Expand All @@ -117,7 +120,7 @@ def pop_video(drive_id, disk_id, id):
data = logic.get_downloadUrl(drive_id, disk_id, id)
share_url = "/video/{}/{}/{}".format(drive_id, disk_id, id)
donw_url = "/down_file/{}/{}/{}".format(drive_id, disk_id, id)
return render_template('index/pop_video.html', share_url=share_url, donw_url=donw_url, data=data)
return render_template(THEMES+'index/pop_video.html', share_url=share_url, donw_url=donw_url, data=data)


@index.route('/down_file/<int:drive_id>/<int:disk_id>/<string:id>')
Expand Down
10 changes: 3 additions & 7 deletions app/main/install/views.py
Expand Up @@ -28,11 +28,7 @@ def index():
from_data["mysql_name"])
mongo_res = "mongodb://{}:{}/cache".format(from_data["mongo_ip"], from_data["mongo_port"])
edit_config(mysql_res, mongo_res)
subprocess.Popen("killall -9 uwsgi", shell=True)
subprocess.Popen("pgrep -f uwsgi", shell=True)
time.sleep(3)
subprocess.Popen("python3 {}/app/task/uwsgi.py".format(os.getcwd()), shell=True)
time.sleep(3)
subprocess.Popen("python3 {}/app/task/restart.py".format(os.getcwd()), shell=True)
return json.dumps({"code": 0, "msg": "完成!"})
else:
return json.dumps({"code": 1, "msg": "Mysql数据库无法连接,或者未建立,请检查后重新安装!"})
Expand Down Expand Up @@ -63,14 +59,14 @@ def edit_config(mysql, mongo):
config_path = root_path + '/config.py'
install_path = root_path + '/.install'
result = ''
with open(config_path, 'r+', encoding='UTF-8') as f:
with open(config_path, 'r', encoding='UTF-8') as f:
for line in f.readlines():
if (line.find('SQLALCHEMY_DATABASE_URI') == 0):
line = 'SQLALCHEMY_DATABASE_URI = %s' % ('\"'+mysql+'\"\n')
if (line.find('MONGO_URI') == 0):
line = 'MONGO_URI = %s' % ('\"'+mongo+'\"')
result += line
with open(config_path, 'r+', encoding='UTF-8') as f:
with open(config_path, 'w', encoding='UTF-8') as f:
f.writelines(result)
open(install_path, 'w+').close()
return
Binary file added app/static/themes/default/cover.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b27ae7e

Please sign in to comment.