|
@@ -1,159 +1,131 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
"""
|
|
|
demeter web page
|
|
|
- name:score.py 积分相关
|
|
|
+ name:deploy.py 上线代码相关
|
|
|
author:rabin
|
|
|
"""
|
|
|
from .__load__ import *
|
|
|
|
|
|
-class score_path(Load):
|
|
|
+class project_path(Load):
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def get(self):
|
|
|
self.set(
|
|
|
- name = u'积分设置'
|
|
|
- ,path = '/score/score'
|
|
|
- ,width = '600'
|
|
|
- ,height = '600'
|
|
|
- ,search = (('label-1','cdate-time-start','cdate-time-end'), (u'日期范围',u'开始时间',u'截止时间'))
|
|
|
- ,thead = (u'积分名', u'规则', u'更新时间')
|
|
|
- ,tbody = ('name', 'func', 'cdate')
|
|
|
+ name = u'项目管理'
|
|
|
+ ,path = '/deploy/project'
|
|
|
+ ,width = '500'
|
|
|
+ ,height = '500'
|
|
|
+ ,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'项目名称'))
|
|
|
+ ,thead = (u'项目ID', u'项目名称', u'更新时间')
|
|
|
+ ,tbody = ('id','name', 'cdate')
|
|
|
,state = True
|
|
|
)
|
|
|
|
|
|
- menu = (
|
|
|
- {'name':'规则列表', 'url':'/score/score_rule'},
|
|
|
- )
|
|
|
-
|
|
|
- self.list('score')
|
|
|
- if self.data['list']:
|
|
|
- for key, value in enumerate(self.data['list']):
|
|
|
- id = str(value['id'])
|
|
|
- param = '?score_id=' + id + '&search_score_id-select-=' + id
|
|
|
- self.data['list'][key]['func'] = ''
|
|
|
- for i in menu:
|
|
|
- self.data['list'][key]['func'] = self.data['list'][key]['func'] + '<a href="'+i['url']+''+param+'">'+i['name']+'</a> '
|
|
|
-
|
|
|
+ self.list('project')
|
|
|
self.show('list')
|
|
|
|
|
|
-class score_update_path(Load):
|
|
|
+class project_update_path(Load):
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def get(self):
|
|
|
self.set(
|
|
|
- path = '/score/score'
|
|
|
- ,label = (u'积分名称',)
|
|
|
- ,update = ('name-input-required',)
|
|
|
+ path = '/deploy/project'
|
|
|
+ ,label = (u'项目名称',u'项目key',u'节点id',u'git地址',u'可写目录-多个用换行隔开,直接填写可写目录名称即可',u'配置目录-多个用换行隔开,直接填写配置目录名称即可')
|
|
|
+ ,update = ('name-input-required','key-input-required','node_id-checkbox-required','git-input-required','write-text--data/','config-text--config/env/')
|
|
|
+ ,update_node_id = self.service('common').list('node')
|
|
|
)
|
|
|
- self.one('score')
|
|
|
+ self.one('project')
|
|
|
self.show('update')
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def post(self):
|
|
|
- self.update('score')
|
|
|
- @Web.auth
|
|
|
- @Web.setting
|
|
|
- def delete(self):
|
|
|
- self.drop('score')
|
|
|
|
|
|
-class score_rule_path(Load):
|
|
|
- @Web.auth
|
|
|
- @Web.setting
|
|
|
- def get(self):
|
|
|
- id = str(self.input('score_id'))
|
|
|
- param = '?score_id=' + id + '&search_score_id-select-=' + id
|
|
|
- self.set(
|
|
|
- name = u'积分规则设置'
|
|
|
- ,path = '/score/score_rule'
|
|
|
- ,width = '600'
|
|
|
- ,height = '600'
|
|
|
- ,search = (('label-1','cdate-time-start','cdate-time-end','search_score_id-select-','record_type_id-select-'), (u'日期范围',u'开始时间',u'截止时间', u'选择积分', u'选择记录点类型'))
|
|
|
- ,thead = (u'积分名', u'记录点类型', u'规则', u'更新时间')
|
|
|
- ,tbody = ('name', 'type', 'rule', 'cdate')
|
|
|
- ,state = True
|
|
|
- )
|
|
|
+ if 'git_path' in Demeter.config['admin']:
|
|
|
+ path = Demeter.config['admin']['git_path']
|
|
|
+ git = self.data['update']['git']
|
|
|
+ name = self.data['update']['key']
|
|
|
+ project = path + name
|
|
|
+ if not File.exists(project):
|
|
|
+ Shell.popen('cd ' + path + ' && git clone ' + git + ' ' + name, bg=True)
|
|
|
|
|
|
- self.data['common']['search_record_type_id-select-'] = self.service('common').list('record_type')
|
|
|
-
|
|
|
- self.data['common']['search_score_id-select-'] = self.service('common').list('score')
|
|
|
-
|
|
|
- self.list('score_rule')
|
|
|
- if self.data['list']:
|
|
|
- for key, value in enumerate(self.data['list']):
|
|
|
- typeData = self.service('common').one('record_type', id=value['record_type_id'])
|
|
|
- self.data['list'][key]['type'] = typeData['name']
|
|
|
-
|
|
|
- score = self.service('common').one('score', id=value['score_id'])
|
|
|
- self.data['list'][key]['name'] = score['name']
|
|
|
-
|
|
|
- self.show('list')
|
|
|
-
|
|
|
-class score_rule_update_path(Load):
|
|
|
- @Web.auth
|
|
|
- @Web.setting
|
|
|
- def get(self):
|
|
|
- self.set(
|
|
|
- path = '/score/score_rule'
|
|
|
- ,label = (u'积分ID', u'记录点类型', u'积分规则公式')
|
|
|
- ,update = ('score_id-select-required','record_type_id-select-required','rule-text-required')
|
|
|
- ,update_record_type_id = self.service('common').list('record_type')
|
|
|
- ,update_score_id = self.service('common').list('score')
|
|
|
- )
|
|
|
- self.one('score_rule')
|
|
|
- self.show('update')
|
|
|
- @Web.auth
|
|
|
- @Web.setting
|
|
|
- def post(self):
|
|
|
- self.update('score_rule')
|
|
|
+ self.update('project')
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def delete(self):
|
|
|
- self.drop('score_rule')
|
|
|
+ self.drop('project')
|
|
|
+
|
|
|
|
|
|
-class level_path(Load):
|
|
|
+class submit_path(Load):
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def get(self):
|
|
|
- id = str(self.input('score_id'))
|
|
|
- param = '?score_id=' + id + '&search_score_id-select-=' + id
|
|
|
self.set(
|
|
|
- name = u'等级设置'
|
|
|
- ,path = '/score/level'
|
|
|
- ,width = '600'
|
|
|
- ,height = '600'
|
|
|
- ,search = (('label-1','cdate-time-start','cdate-time-end','search_score_id-select-'), (u'日期范围',u'开始时间',u'截止时间', u'选择积分'))
|
|
|
- ,thead = (u'等级名',u'积分名', u'规则', u'更新时间')
|
|
|
- ,tbody = ('name', 'score', 'rule', 'cdate')
|
|
|
+ name = u'代码提交'
|
|
|
+ ,path = '/deploy/submit'
|
|
|
+ ,width = '500'
|
|
|
+ ,height = '500'
|
|
|
+ ,search = (('label-1','cdate-time-start','cdate-time-end','file-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'提交文件'))
|
|
|
+ ,thead = (u'提交ID', u'所属项目', u'提交文件', u'提交描述', u'提交人', u'提交时间')
|
|
|
+ ,tbody = ('id','project','file','desc','admin', 'cdate')
|
|
|
,state = True
|
|
|
)
|
|
|
|
|
|
- self.data['common']['search_score_id-select-'] = self.service('common').list('score')
|
|
|
-
|
|
|
- self.list('level')
|
|
|
+ self.list('code')
|
|
|
if self.data['list']:
|
|
|
for key, value in enumerate(self.data['list']):
|
|
|
- score = self.service('common').one('score', id=value['score_id'])
|
|
|
- self.data['list'][key]['score'] = score['name']
|
|
|
+ project = self.service('common').one('project', id=value['project_id'])
|
|
|
+ self.data['list'][key]['project'] = project['name']
|
|
|
|
|
|
+ admin = self.service('common').one('manage_admin', id=value['admin'])
|
|
|
+ self.data['list'][key]['admin'] = admin['username']
|
|
|
self.show('list')
|
|
|
|
|
|
-class level_update_path(Load):
|
|
|
+class submit_update_path(Load):
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def get(self):
|
|
|
self.set(
|
|
|
- path = '/score/level'
|
|
|
- ,label = (u'等级名', u'积分ID', u'规则公式')
|
|
|
- ,update = ('name-input-required','score_id-select-required','rule-text-required')
|
|
|
- ,update_score_id = self.service('common').list('score')
|
|
|
+ path = '/deploy/submit'
|
|
|
+ ,label = (u'所属项目',u'提交文件-多个换行隔开',u'提交描述')
|
|
|
+ ,update = ('project_id-select-required','file-text-required','desc-text-required')
|
|
|
+ ,update_project_id = self.service('common').list('project')
|
|
|
)
|
|
|
- self.one('level')
|
|
|
+ self.one('code')
|
|
|
self.show('update')
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def post(self):
|
|
|
- self.update('level')
|
|
|
+
|
|
|
+ self.data['update']['admin'] = self.data['setting']['admin']
|
|
|
+ if 'git_path' in Demeter.config['admin'] and 'online_path' in Demeter.config['admin']:
|
|
|
+ path = Demeter.config['admin']['git_path']
|
|
|
+ online = Demeter.config['admin']['online_path']
|
|
|
+ project_id = self.data['update']['project_id']
|
|
|
+ project_info = self.service('common').one('project', id=project_id)
|
|
|
+ write = project_info['write'].split("\r\n")
|
|
|
+ config = project_info['config'].split("\r\n")
|
|
|
+ name = project_info['key']
|
|
|
+ file = self.data['update']['file']
|
|
|
+ project = path + name + '/'
|
|
|
+ online_project = online + name + '/'
|
|
|
+ if File.exists(project):
|
|
|
+ if not File.exists(online_project) or file == '/':
|
|
|
+ command = 'cp -R ' + project + ' ' + online_project + ' && rm -rf '+online_project+'.git/ && chmod -R 777 ' + online_project + 'data/'
|
|
|
+ else:
|
|
|
+ file = file.split("\r\n")
|
|
|
+ files = []
|
|
|
+ for i in file:
|
|
|
+ c = 'cp -R ' + project + i + ' ' + online_project + i + ' '
|
|
|
+ for j in write:
|
|
|
+ if j in i:
|
|
|
+ c = c + ' && chmod -R 777 ' + online_project + i + ' '
|
|
|
+ files.append(c)
|
|
|
+ command = '&&'.join(files)
|
|
|
+
|
|
|
+ Shell.popen('cd ' + project + ' && git pull && ' + command, bg=True)
|
|
|
+
|
|
|
+ self.update('code')
|
|
|
@Web.auth
|
|
|
@Web.setting
|
|
|
def delete(self):
|
|
|
- self.drop('level')
|
|
|
+ self.drop('code')
|