1 Star 0 Fork 51

cyf / cmdb

forked from 晶晶 / cmdb 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
init.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
晶晶 提交于 2022-03-17 08:35 . dockerfile
#!/usr/bin/env python
# coding=utf-8
import os
import shlex
class Initialize(object):
def bash(self,cmd):
"""
执行bash命令
"""
shlex.os.system(cmd)
def run(self):
self.bash('python manage.py makemigrations oauth asset app')
self.bash('python manage.py migrate')
try:
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
django.setup()
# 初始化
from django.contrib.auth import get_user_model
UserProfile = get_user_model()
users = UserProfile.objects.all()
if len(users) == 0: # 如果没有用户就初始化数据
# User.objects.create_superuser(
# username="admin", password="123456", email="admin@qq.com")
self.import_data()
except Exception as e:
pass
def import_data(self):
"""
导入默认配置
"""
self.bash('python manage.py loaddata doc/dumpdata.json')
# from django.db import connection # UPDATE,DELETE等SQL语句操作
# with connection.cursor() as cursor:
# with open("./update.sql") as f:
# for raw in f:
# raw = raw.strip()
# if raw:
# cursor.execute(raw.strip()) # 执行sql
if __name__ == '__main__':
Init = Initialize()
Init.run()
Python
1
https://gitee.com/cyfkobe/cmdb.git
git@gitee.com:cyfkobe/cmdb.git
cyfkobe
cmdb
cmdb
master

搜索帮助