def test_release(request, ID): the_release = Test.objects.get(id=str(ID)) try: branch = request.GET["branch"] except: branch = '' if PreRecord.objects.all().filter(project=the_release.project): return http_error(request, u'发布失败,请查看预发布记录') else: host_list, server_path, stdout, before_cmd, after_cmd = list( eval(the_release.host_list)), os.path.abspath( the_release.server_path ), '', the_release.before_cmd, the_release.after_cmd the_project = Project.objects.get(name=the_release.project) the_auth = Auth.objects.get(id=the_project.auth) key = force_text(the_auth.key) if the_auth.key else '' local_path = os.path.join('/ops/%s' % the_project.name, server_path.lstrip('/'), str(ID)) repo_branch = the_release.last_branch if not branch else branch git_co(the_project.url, repo_branch, key, local_path) if before_cmd: os.chdir(local_path) os.system(before_cmd) for i in host_list: stdout = rrsync(local_path, i, server_path, ['.git*']) result = stdout.replace('\n', '</br>') the_release.last_branch = repo_branch the_release.last_hash = git_hash(local_path) the_release.save() return render_to_response('release/release_result.html', locals(), RequestContext(request))
def test_release(request, ID): the_release = Test.objects.get(id=str(ID)) try: branch = request.GET["branch"] except: branch = '' if PreRecord.objects.all().filter(project=the_release.project): return http_error(request, u'发布失败,请查看预发布记录') else: host_list, server_path, stdout, before_cmd, after_cmd = list(eval(the_release.host_list)), os.path.abspath( the_release.server_path), '', the_release.before_cmd, the_release.after_cmd the_project = Project.objects.get(name=the_release.project) the_auth = Auth.objects.get(id=the_project.auth) key = force_text(the_auth.key) if the_auth.key else '' local_path = os.path.join('/ops/%s' % the_project.name, server_path.lstrip('/'), str(ID)) repo_branch = the_release.last_branch if not branch else branch git_co(the_project.url, repo_branch, key, local_path) if before_cmd: os.chdir(local_path) os.system(before_cmd) for i in host_list: stdout = rrsync(local_path, i, server_path, ['.git*']) result = stdout.replace('\n', '</br>') the_release.last_branch = repo_branch the_release.last_hash = git_hash(local_path) the_release.save() return render_to_response('release/release_result.html', locals(), RequestContext(request))
def git_co_task(ID): if ID != 0: the_test = Test.objects.get(id=ID) else: the_test = Test.objects.order_by('-id')[0] the_project = Project.objects.get(name=the_test.project) the_auth = Auth.objects.get(id=the_project.auth) local_path = os.path.join('/ops/%s' % the_test.project, the_test.server_path.lstrip('/'), str(the_test.id)) key = force_text(the_auth.key) if the_auth.key else '' git_co(the_project.url, '', key, local_path) the_test.last_branch = 'master' the_test.last_hash = git_hash(local_path) the_test.save()