修复获取版本号并写入数据库的逻辑

main
RogerWork 10 months ago
parent 4139c71361
commit 9424d8a761
  1. 15
      update/urls.py
  2. 51
      update/utils/git_util.py
  3. 139
      update/views.py

@ -29,16 +29,17 @@ urlpatterns = [
path('update_user/', update_user), path('update_user/', update_user),
path('get_git_version/', get_git_version), path('get_git_version/', get_git_version),
path('get_operation_cmd/', get_operation_cmd), path('get_operation_cmd/', get_operation_cmd),
path('update_cine/', update_cine),
# re_path(r'^cinema/search/ip/(?P<ip>[0-9.]*?)/version/(?P<version>[\S]*?)/$', views.CinemaSearchAPIView.as_view()) # re_path(r'^cinema/search/ip/(?P<ip>[0-9.]*?)/version/(?P<version>[\S]*?)/$', views.CinemaSearchAPIView.as_view())
# 测试用的接口 # 测试用的接口
path('test/write_git_version_to_db/', write_git_version_to_db), path('test/write_git_version_to_db/', write_git_version_to_db),
path('test/write_cine_sql/', write_cine_sql), # path('test/write_cine_sql/', write_cine_sql),
path('test/db_compare/', compare_db_structor), # path('test/db_compare/', compare_db_structor),
path('test/get_cmd/', get_cmd), # path('test/get_cmd/', get_cmd),
path('test/setup_cmd/', setup_cmd), # path('test/setup_cmd/', setup_cmd),
path('test/teardown_cmd/', teardown_cmd), # path('test/teardown_cmd/', teardown_cmd),
path('test/get_client/', get_client), # path('test/get_client/', get_client),
path('test/update_cine/', update_cine) # path('test/update_cine/', update_cine)
] ]
# &version=(?P<version>[\S]*?) # &version=(?P<version>[\S]*?)

@ -44,31 +44,6 @@ class GitUtil:
r = local_repo.git.pull() r = local_repo.git.pull()
print(r) print(r)
# 获取版本并写入数据库
def set_release_to_db(self):
local_repo = Repo(self.local_code_path)
release = []
for remote in local_repo.remotes:
for ref in remote.refs:
release.append(ref.name)
saved_release = Release.objects.all()
saved_release_version_list = [rel.short_release for rel in saved_release]
for rel in release:
if rel in saved_release_version_list:
pass
else:
data = {
'release': rel,
'short_release': rel[7:-8] if '_Release' in rel else rel,
'main_ver': rel[7:18],
'ver_id': int(rel[14:18]),
'status': '0'
}
Release.objects.create(**data)
# 复制cine.sql到本地路径cine_xxx_org.sql,然后生成新数据库名称的cine_xxx.sql # 复制cine.sql到本地路径cine_xxx_org.sql,然后生成新数据库名称的cine_xxx.sql
# 如果cine.sql和cine_xxx_org.sql文件md5一致则跳过 # 如果cine.sql和cine_xxx_org.sql文件md5一致则跳过
# 如果cine.sql和cine_xxx_org.sql文件md5不一致,则重新拷贝cine_xxx_org.sql并生成cine_xxx.sql # 如果cine.sql和cine_xxx_org.sql文件md5不一致,则重新拷贝cine_xxx_org.sql并生成cine_xxx.sql
@ -164,11 +139,35 @@ class GitUtil:
class GitDbUtil: class GitDbUtil:
def __init__(self): def __init__(self):
pass self.local_code_path = os.path.join(settings.BASE_DIR, r'dx\code')
# 获取可用的版本,可用状态需要手动维护数据库
@staticmethod @staticmethod
def get_short_version(): def get_short_version():
return Release.objects.exclude(status='0').order_by('-ver_id').all() return Release.objects.exclude(status='0').order_by('-ver_id').all()
# 从git中获取版本列表后和数据库对比,添加新的版本到数据库
def set_release_to_db(self):
local_repo = Repo(self.local_code_path)
release = []
for remote in local_repo.remotes:
for ref in remote.refs:
release.append(ref.name)
saved_release = Release.objects.all()
saved_release_version_list = [rel.release for rel in saved_release]
for rel in release:
if rel in saved_release_version_list:
print('pass')
else:
data = {
'release': rel,
'short_release': rel.replace('origin/', ''),
'main_ver': rel[7:18],
'ver_id': int(rel[14:18]),
'status': '1'
}
Release.objects.create(**data)
# if __name__ == '__main__': # if __name__ == '__main__':
# git_util = GitUtil() # git_util = GitUtil()
# # git_util.clone() # # git_util.clone()

@ -83,86 +83,101 @@ def get_operation_cmd(request):
def get_git_version(request): def get_git_version(request):
git_db_util = GitDbUtil git_db_util = GitDbUtil()
git_db_util.set_release_to_db()
git_ver = git_db_util.get_short_version() git_ver = git_db_util.get_short_version()
serializer = ReleaseSerializer(instance=git_ver, many=True) serializer = ReleaseSerializer(instance=git_ver, many=True)
return JsonResponse(serializer.data, safe=False) return JsonResponse(serializer.data, safe=False)
# 测试用接口
def write_git_version_to_db(request):
git_util = GitUtil('')
git_util.set_release_to_db()
return JsonResponse({'result': 'success'})
def write_cine_sql(request):
git_util = GitUtil('2.0.33.0338_Release')
git_util.handle_create_cine()
return JsonResponse({'result': 'success'})
def compare_db_structor(request):
db_compare = DbCompare('172.16.3.88', '2.0.33.0338_Release')
db_compare.exec_diff_sql()
return JsonResponse({'result': 'success'})
def get_cmd(request):
update_cmd = UpdateCommandUtil()
update_cmd.connect('172.16.3.112')
update_cmd.disconnect()
# cmd = update_cmd.get_all_cmd()
# cmd_ser = UpdateCommandSerializer(instance=cmd, many=True)
# return JsonResponse(data=cmd_ser.data, safe=False)
cmd_list = [10, 12, 13, 14, 15, 17, 19, 20]
r = update_cmd.get_checked_cmd(cmd_list)
print(r)
return JsonResponse({'result': 'success'})
def setup_cmd(request):
update_cmd = UpdateCommandUtil()
cmd_list = [10, 11, 12, 13, 14, 15, 16, 17, 19, 20]
# exec_cmd_data = update_cmd.get_checked_cmd(cmd_list)
update_cmd.exec_cmd_by_type('172.16.3.88', 'setup', cmd_list, '2.0.33.0338_Release')
return JsonResponse({'result': 'success'})
def teardown_cmd(request):
update_cmd = UpdateCommandUtil()
cmd_list = [10, 11, 12, 13, 14, 15, 16, 17, 19, 20]
# exec_cmd_data = update_cmd.get_checked_cmd(cmd_list)
update_cmd.exec_cmd_by_type('172.16.3.88', 'teardown', cmd_list, '2.0.33.0338_Release')
return JsonResponse({'result': 'success'})
def get_client(request):
client_release = ClientUtil()
client_release.client_process('172.16.3.88', '2.0.33.0338_Release')
return JsonResponse({'result': 'success'})
def update_cine(request): def update_cine(request):
req = request.GET.dict() req = request.GET.dict()
cinema_ip = req.get('cinema_ip') cinema_ip = req.get('ip')
short_release = req.get('short_release') short_release = req.get('version')
print(cinema_ip, short_release) cmd_list = json.loads(req.get('cmd'))
print(cinema_ip, short_release, cmd_list)
# cinema_ip = '172.16.3.88' # cinema_ip = '172.16.3.88'
# short_release = '2.0.33.0338_Release' # short_release = '2.0.33.0338_Release'
cmd_list = [10, 11, 12, 13, 14, 15, 16, 17, 19, 20] # cmd_list = [10, 11, 12, 13, 14, 15, 16, 17, 19, 20]
for cmd in cmd_list:
print(type(cmd))
# 获取并写入cine.sql # 获取并写入cine.sql
print('获取并写入cine.sql')
git_util = GitUtil(short_release) git_util = GitUtil(short_release)
git_util.handle_create_cine() git_util.handle_create_cine()
# 数据库对比
db_compare = DbCompare(cinema_ip, short_release)
db_compare.exec_diff_sql()
# 执行setup # 执行setup
print('执行setup')
update_cmd = UpdateCommandUtil() update_cmd = UpdateCommandUtil()
update_cmd.exec_cmd_by_type(cinema_ip, 'setup', cmd_list, short_release) update_cmd.exec_cmd_by_type(cinema_ip, 'setup', cmd_list, short_release)
# 数据库对比
if 19 in cmd_list:
print('数据库对比')
db_compare = DbCompare(cinema_ip, short_release)
db_compare.exec_diff_sql()
# 执行teardown # 执行teardown
if 17 in cmd_list:
print('执行teardown')
update_cmd.exec_cmd_by_type(cinema_ip, 'teardown', cmd_list, short_release) update_cmd.exec_cmd_by_type(cinema_ip, 'teardown', cmd_list, short_release)
# 传输客户端 # 传输客户端
if 20 in cmd_list:
print('传输客户端')
client_release = ClientUtil() client_release = ClientUtil()
client_release.client_process(cinema_ip, short_release) client_release.client_process(cinema_ip, short_release)
return JsonResponse({'result': 'success'}) return JsonResponse({'result': 'success'})
# # 测试用接口
def write_git_version_to_db(request):
git_util = GitDbUtil()
git_util.set_release_to_db()
return JsonResponse({'result': 'success'})
#
#
# def write_cine_sql(request):
# git_util = GitUtil('2.0.33.0338_Release')
# git_util.handle_create_cine()
# return JsonResponse({'result': 'success'})
#
#
# def compare_db_structor(request):
# db_compare = DbCompare('172.16.3.88', '2.0.33.0338_Release')
# db_compare.exec_diff_sql()
# return JsonResponse({'result': 'success'})
#
#
# def get_cmd(request):
# update_cmd = UpdateCommandUtil()
# update_cmd.connect('172.16.3.112')
# update_cmd.disconnect()
# # cmd = update_cmd.get_all_cmd()
# # cmd_ser = UpdateCommandSerializer(instance=cmd, many=True)
# # return JsonResponse(data=cmd_ser.data, safe=False)
# cmd_list = [10, 12, 13, 14, 15, 17, 19, 20]
# r = update_cmd.get_checked_cmd(cmd_list)
# print(r)
# return JsonResponse({'result': 'success'})
#
#
# def setup_cmd(request):
# update_cmd = UpdateCommandUtil()
# cmd_list = [10, 11, 12, 13, 14, 15, 16, 17, 19, 20]
# # exec_cmd_data = update_cmd.get_checked_cmd(cmd_list)
# update_cmd.exec_cmd_by_type('172.16.3.88', 'setup', cmd_list, '2.0.33.0338_Release')
# return JsonResponse({'result': 'success'})
#
#
# def teardown_cmd(request):
# update_cmd = UpdateCommandUtil()
# cmd_list = [10, 11, 12, 13, 14, 15, 16, 17, 19, 20]
# # exec_cmd_data = update_cmd.get_checked_cmd(cmd_list)
# update_cmd.exec_cmd_by_type('172.16.3.88', 'teardown', cmd_list, '2.0.33.0338_Release')
# return JsonResponse({'result': 'success'})
#
#
# def get_client(request):
# client_release = ClientUtil()
# client_release.client_process('172.16.3.88', '2.0.33.0338_Release')
# return JsonResponse({'result': 'success'})

Loading…
Cancel
Save