import sys
import os
import json
packageName="package.json"
def commond(argv):
if len(argv)<=1:
return True
commond=argv[1]
if commond=="app":
if len(argv)==2:
return False
os.system("{} manage.py startapp {}".format("python",argv[2]))
return False
if commond=="db":
os.system("{} manage.py makemigrations".format("python"))
os.system("{} manage.py migrate".format("python"))
return False
def wiretJsonToFile(package,configdict):
info = json.dumps(configdict)
with open(package, "w") as f:
f.write(info)
def readJsonFromFile(package):
with open(package,"r") as f:
return json.loads(f.read())
def firstConfig(package=packageName):
if not os.path.exists(package):
projectname=os.getcwd().split("/")[-1].split("\\")[-1]
configdict={"projectName":projectname,"version":"1.0.0","models":[]}
wiretJsonToFile(package,configdict)
生成添加试题
def genAddView(modelDict):
#默认全部增加
pass
def genEditView(modelDict):
pass
def genDelView(modelDict):
pass
def genSearchView(modelDict):
pass
def genLoginView(modelDict):
pass
def genSignUpView(modelDict):
pass
def genModel(argv):
if not commond(argv):
return
modelresult=""
packageJson=readJsonFromFile(packageName)
modelName=input("请输入model名称:")
modelCanme=input("请输入备注名:")
modelsDict={"name":modelName,"verbose":modelCanme,"files":[]}
while True:
filename=input("请输入字段名称:")
if filename=="Q" or filename=="q":
break
modelsDict["files"].append(filename)
filetype=input("请输入{}字段类型(默认为string):(1):String,(2):int,(3):text,(4):date,(5):datetime,(6):image,(7):foregin".format(filename))
if filetype.strip()=="":
filetype="1"
if filetype in ["1","6"]:
max_length=input("请输入{}字段长度".format(filename))
verbose=input("请输入{}备注:".format(filename))
filenull=input("请输入{}字段是否为null(1/0)".format(filename))
if filenull=="1":
pass
else:
pass
fileblank=input("请输入{}字段是否为blank(1/0)".format(filename))
if fileblank=="1":
pass
else:
pass
#根据不同的方法调用不同的字段生成语句
modelresult+=""
packageJson["models"]=modelsDict
wiretJsonToFile(packageName,packageJson)
#从次数开始询问是否要生成api
if __name__=="__main__":
firstConfig(packageName)
genModel(sys.argv)