Beispiel #1
0
 def buildexts(self, path):
     '''
     构建数据库链接
     :param path:
     :return:
     '''
     if os.path.exists(path) == False:
         content = "from flask_sqlalchemy import SQLAlchemy\ndb = SQLAlchemy()"
         f.file_put_contents(path, content)
Beispiel #2
0
 def buildfile(self, list):
     '''
     创建文件
     :param list: 文件列表
     :return:
     '''
     for v in list:
         v = os.path.join(self.apppath, v)
         if os.path.exists(os.path.dirname(v)) == False:
             os.mkdir(os.path.dirname(v))
         if os.path.exists(v) == False:
             f.file_put_contents(v, '')
             pass
Beispiel #3
0
 def buildCommon(self, module):
     '''
     创建公用文件
     :param module: 模块名
     :return:
     '''
     config = os.path.join(self.apppath, module, 'config.py')
     self.checkDirBuild(os.path.dirname(config))
     if os.path.exists(config) == False:
         f.file_put_contents(config, "# 配置文件 \n")
     common = os.path.join(self.apppath, module, 'common.py')
     if os.path.exists(common) == False:
         content = "# 公用函数文件 \nfrom wtforms import Form\nclass FormBase(Form):    " \
                   "\n    def get_err_one(self):\n        err = self.errors.popitem()[1][0]\n        return err"
         f.file_put_contents(common, content)
Beispiel #4
0
 def buildconfig(self, path):
     '''
     构建配置文件
     :param path:
     :return:
     '''
     if os.path.exists(path) == False:
         content = "import os" \
                   "\nDEBUG       = False" \
                   "\nSECRET_KEY  = os.urandom(24)" \
                   "\nDIALECT     = 'mysql'" \
                   "\nDRIVER      = 'pymysql'" \
                   "\nUSERNAME    = '******'" \
                   "\nPASSWORD    = ''" \
                   "\nHOST        = '127.0.0.1'" \
                   "\nPORT        = '3306'" \
                   "\nDARABSE     = 'demo'" \
                   "\nSQLALCHEMY_DATABASE_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'" \
                   ".format(DIALECT,DRIVER,USERNAME,PASSWORD,HOST,PORT,DARABSE)" \
                   "\nSQLALCHEMY_TRACK_MODIFICATIONS = False"
         f.file_put_contents(path, content)
Beispiel #5
0
 def buildmanage(self, path):
     '''
         构建管理文件
     :param path:
     :return:
     '''
     if os.path.exists(path) == False:
         content = "from flask_script import Manager\n" \
                   "from flask_migrate import Migrate,MigrateCommand\n" \
                   "from think.library.build import Build\n" \
                   "from exts import db\n" \
                   "from app import app\n" \
                   "\n\nmanger = Manager(app)           ###管理" \
                   "\nmigrate = Migrate(app,db)       ###数据库映射" \
                   "\nmanger.add_command('mg',MigrateCommand)" \
                   "\[email protected]" \
                   "\ndef build():" \
                   "\n    b = Build().run()" \
                   "\n    print('创建成功')" \
                   "\n\nif __name__ == '__main__':" \
                   "\n    manger.run()"
         f.file_put_contents(path, content)
Beispiel #6
0
 def buildHello(self, module):
     filename = os.path.join(self.apppath, module, 'controller', 'index.py')
     if os.path.exists(filename) == False:
         # if module == 'home':
         #     content = "from flask import Blueprint,render_template\n\nbp = Blueprint('{}',__name__)" \
         #           "\n\[email protected]('/')\ndef index():\n    return render_template('{}/index/index.html')".format(module,module)
         # else:
         content = "from flask import Blueprint,render_template\n\nbp = Blueprint('{}',__name__)" \
                       "\n\[email protected]('/')\ndef index():\n    return '<h1 style=\"margin=200px,auto\">欢迎来到thinkpy</h1>'".format('home'+'index')
         dirpath = os.path.dirname(filename)
         tmp = self.root_path
         for d in dirpath.split('\\'):
             d = os.path.join(tmp, d)
             tmp = d
             self.checkDirBuild(d)
         import_str1 = 'from ' + '.'.join([
             self.appname, module, 'controller', 'index'
         ]) + ' import bp as ' + module + 'indexbp'
         import_str2 = 'app.register_blueprint({})'.format(module +
                                                           'indexbp')
         self.addformimport(import_str1, import_str2)
         f.file_put_contents(filename, content)
Beispiel #7
0
 def module(self, module, list):
     '''
     创建模块
     :param model:模块名称
     :param list:build 列表
     :return:
     '''
     module if module else ''
     modulepath = os.path.join(self.apppath, module)
     if os.path.exists(modulepath) == False:
         os.mkdir(modulepath)
     self.buildCommon(module)
     if list is None:
         list = {
             'file': ['config.php', 'common.php'],
             'dir': ['controller', 'model', 'view'],
         }
     for v in list:
         if 'dir' == v:
             for vv in list[v]:
                 self.checkDirBuild(os.path.join(modulepath, vv))
         elif 'file' == v:
             for vv in list[v]:
                 if os.path.exists(os.path.join(modulepath, vv)) == False:
                     f.file_put_contents(os.path.join(modulepath, vv), '')
         else:
             # 生成mvc
             for vv in list[v]:
                 vv = vv.strip()
                 filename = os.path.join(modulepath, v, ''.join([vv,
                                                                 '.py']))
                 if v == 'controller':
                     # if module == 'home':
                     #     content = "from flask import Blueprint,render_template\n\nbp = Blueprint('{}',__name__)" \
                     #               "\n\[email protected]('/')\ndef index():\n    return render_template('{}/{}/index.html')".format(
                     #         module,module, vv)
                     # else:
                     content = "from flask import Blueprint,render_template\n\nbp = Blueprint('{}',__name__,url_prefix='/{}/{}')" \
                               "\n\[email protected]('/')\ndef index():\n    return render_template('{}/{}/index.html')".format(
                         module+vv, module, vv, module, vv)
                 elif v == 'model':
                     content = "from exts import db\n"
                 elif v == 'form':
                     content = "from wtforms import StringField,IntegerField\nfrom ..common import FormBase\n" \
                               "from wtforms.validators " \
                               "import email,InputRequired,Length,EqualTo,ValidationError\n\n" \
                               "class {}Form(FormBase):\n    pass".format(vv.capitalize())
                 elif v == 'templates':
                     filename = os.path.join(v, module,
                                             ''.join([vv, '.html']))
                     tmp = self.root_path
                     for d in os.path.dirname(filename).split('\\'):
                         d = os.path.join(tmp, d)
                         tmp = d
                         self.checkDirBuild(d)
                     content = ''
                 elif v == 'static':
                     filename = os.path.join(v, module, ''.join([vv]))
                     tmp = self.root_path
                     for d in os.path.dirname(filename).split('\\'):
                         d = os.path.join(tmp, d)
                         tmp = d
                         self.checkDirBuild(d)
                     content = ''
                 else:
                     content = ''
                 if os.path.exists(filename) == False:
                     if v == 'controller':
                         import_str1 = 'from ' + '.'.join([
                             self.appname,
                             module,
                             v,
                             vv,
                         ]) + ' import bp as ' + module + vv + 'bp'
                         import_str2 = 'app.register_blueprint({})'.format(
                             module + vv + 'bp')
                         self.addformimport(import_str1, import_str2)
                     f.file_put_contents(filename, content)