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 php_result(request, ID): try: branch = request.GET["branch"] except: branch = '' test_release = Test.objects.all().get(id=str(ID)) host_list, repo_type, repo_url, repo_last_branch, test_auth, server_path, stdout, before_cmd, after_cmd = \ list(eval(test_release.host_list)), test_release.repo_type, test_release.repo_url.strip(), \ test_release.last_branch, test_release.auth, os.path.abspath( test_release.server_path), '', test_release.before_cmd, test_release.after_cmd the_auth = Auth.objects.get(id=test_auth) username = the_auth.username if the_auth.username else '' password = the_auth.password if the_auth.password else '' key = force_text(the_auth.key) if the_auth.key else '' local_path = os.path.join('/ops/test', server_path.lstrip('/'), str(ID)) repo_branch = repo_last_branch if not branch else branch if repo_type == 'git': git_co(repo_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, ['.svn*', '.git*']) result = stdout.replace('\n', '</br>') test_release.last_branch = repo_branch test_release.save() else: svn_co(repo_url, local_path, '', username, password) for i in host_list: stdout = rrsync(local_path, i, server_path, ['.svn*', '.git*']) result = stdout.replace('\n', '</br>') return render_to_response('release/php_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()
def git_co_task(ID): if ID != 0: the_test = Test.objects.get(id=ID) else: the_test = Test.objects.order_by('-id')[0] if the_test.repo_type == 'git': local_path = os.path.join('/ops/test', the_test.server_path.lstrip('/'), str(the_test.id)) the_auth = Auth.objects.get(id=the_test.auth) key = force_text(the_auth.key) if the_auth.key else '' git_co(the_test.repo_url, '', key, local_path) the_test.last_branch = 'master' the_test.save() else: # the_test.last_branch = 'master' the_test.save()