def testapi(self): data = self.getjson() if not data: return 1 repos_url = data.get('repos_url', '') fc = data.get('files_changed', '') log = data.get('log', 0) author = data.get('author', '') date = data.get('date', '') changed = data.get('changed', '') dirs_changed = data.get('dirs_changed', '') uuid = data.get('uuid', '') youngest_revision = data.get('youngest_revision', '') checkjson = json.dumps({ 'author': author, 'log': log, 'changed': changed, 'dirs_changed': dirs_changed }) if not all([repos_url]): #判空,根据url确定属于哪个项目 return 1 project = Project.query.filter_by(repos_url=repos_url, isDelete=False).first() if not project: return 2 swtich = project.swtich #脚本开关 if swtich: return 5 fileuid = str(tooluid.uuid1()) jsonpath = os.path.join('./file', project.pname, fileuid) os.makedirs(jsonpath, exist_ok=True) with open(os.path.join(jsonpath, 'detail.json'), 'w') as f: f.write(checkjson) for i in fc: content = i.get('content', '') filepath = i.get('filepath', '') # dirname = i.get('dirname', '') if not all([filepath]): return 1 path = os.path.join('./file', project.pname, fileuid, filepath) self.savefile(path, content) data = self.runscr(project=project, uid=fileuid, pname=project.pname) shutil.rmtree(jsonpath) his = History() his.projectId = project.id his.log = log his.author = author his.date = date his.changed = json.dumps(changed) his.dirsChanged = json.dumps(dirs_changed) his.youngest_revision = youngest_revision his.result = json.dumps(data) his.uuid = uuid self.create(his) if not data: return 4 return data, his.id
def log(key, question, old_value, new_value): history = History(option='更改', key=key, old_value=old_value, new_value=new_value) history.author = g.user history.question = question db.session.add(history) db.session.commit()