Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/class/core/config.py

74 lines
1.7 KiB

7 years ago
# coding:utf-8
import sys
import io
import os
import time
7 years ago
import shutil
7 years ago
from flask import Flask
from datetime import timedelta
7 years ago
sys.path.append(os.getcwd() + "/class/core")
sys.setdefaultencoding('utf-8')
import db
import public
7 years ago
class config:
__version = '0.0.1'
__app = None
def __init__(self):
pass
def makeApp(self, name):
app = Flask(name)
app.debug = True
app.config.version = self.__version + str(time.time())
app.config['SECRET_KEY'] = os.urandom(24)
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7)
__app = app
7 years ago
self.initDB()
7 years ago
self.initInitD()
7 years ago
return app
7 years ago
def initDB(self):
try:
sql = db.Sql().dbfile('default')
csql = public.readFile('data/sql/default.sql')
csql_list = csql.split(';')
for index in range(len(csql_list)):
sql.execute(csql_list[index], ())
except Exception, ex:
print str(ex)
7 years ago
def initUser(self):
pass
def initInitD(self):
script = public.getRunDir() + '/scripts/init.d/mw.tpl'
script_bin = public.getRunDir() + '/scripts/init.d/mw'
7 years ago
if os.path.exists(script_bin):
return
7 years ago
content = public.readFile(script)
content = content.replace("{$SERVER_PATH}", public.getRunDir())
public.writeFile(script_bin, content)
public.execShell('chmod +x ' + script_bin)
7 years ago
if public.getOs() != 'darwin':
initd_bin = '/etc/init.d/mw'
if not os.path.exists(initd_bin):
shutil.copyfile(script_bin, initd_bin)
7 years ago
def getVersion(self):
return self.__version
def getApp(self):
return self.__app