Ejemplo n.º 1
0
def add_git_repo(request):
    if request.method == 'POST':
        form=GitInfoForm(request.POST)
	if form.is_valid():
	    if RepoModel.objects.filter(repoName=form.cleaned_data['repoName']).count() == 1:
		form.errors['repoName']=u'已经存在该库名!请重新命名'
		return render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
	    git_is_ok,message=check_git_validated(form.cleaned_data['repoAddress'].strip())
	    if not git_is_ok:
		form.errors['repoAddress']=message
		return render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
	    if not check_ip_reachable(form.cleaned_data['testDeployIP']):
		form.errors['testDeployIP']=u'本机无法连接到此 IP: %s !!!' %form.cleaned_data['testDeployIP']
		return render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
	    if not check_ip_reachable(form.cleaned_data['preDeployIP']):
		form.errors['preDeployIP']=u'本机无法连接到此 IP: %s !!!' %form.cleaned_data['preDeployIP']
		return render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
	    for ip in form.cleaned_data['onlineDeployIP'].split(' '):
		if ip != '':
		    if not check_ip_reachable(ip):
		        form.errors['onlineDeployIP']=u'本机到IP:%s  无法连通!!!' %ip
		        return render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
	    addDate=datetime.now()
	    repo_dict={}
	    for items in form.cleaned_data:
		repo_dict[items]=form.cleaned_data[items].strip(' ')
	    repoinfo=RepoModel(repoName=repo_dict['repoName'],repoAddress=repo_dict['repoAddress'],wwwDir=repo_dict['wwwDir'],testDeployIP=repo_dict['testDeployIP'],preDeployIP=repo_dict['preDeployIP'],onlineDeployIP=repo_dict['onlineDeployIP'],excludeDir=repo_dict['excludeDir'],repoType='git',localCheckoutDir=repo_dict['localCheckoutDir'],addDate=addDate)
	    try:
		repoinfo.save()
	    except e:
		return HttpResponse(u'添加库信息失败')
	    return HttpResponseRedirect(reverse('deploy:list_repo_info'))
	return  render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
    form=GitInfoForm()
    return render_to_response('add_git_repo.html',RequestContext(request,{'form':form}))
Ejemplo n.º 2
0
def add_svn_repo(request):
    if request.method == 'POST':
        form=SvnInfoForm(request.POST)
	if form.is_valid():
	    if RepoModel.objects.filter(repoName=form.cleaned_data['repoName']).count() == 1:
		form.errors['repoName']=u'已经存在该库名!请重新命名'
		return render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))
	    svn_is_ok,message=check_svn_validated(user=form.cleaned_data['repoUser'].strip(),
		    password=form.cleaned_data['repoPassword'].strip(),
		    url=form.cleaned_data['repoAddress'].strip())
	    if not svn_is_ok:
		form.errors['repoAddress']=message
		return render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))
	    if not check_ip_reachable(form.cleaned_data['testDeployIP']):
		form.errors['testDeployIP']=u'本机无法连接到此 IP: %s !!!' %form.cleaned_data['testDeployIP']
		return render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))
	    if not check_ip_reachable(form.cleaned_data['preDeployIP']):
		form.errors['preDeployIP']=u'本机无法连接到此 IP: %s !!!' %form.cleaned_data['preDeployIP']
		return render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))
	    for ip in form.cleaned_data['onlineDeployIP'].split(' '):
		if ip != '':
		    if not check_ip_reachable(ip):
		        form.errors['onlineDeployIP']=u'本机到IP:%s  无法连通!!!' %ip
		        return render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))
	    addDate=datetime.now()
	    repo_dict={}
	    for items in form.cleaned_data:
		repo_dict[items]=form.cleaned_data[items].strip(' ')
	    repoinfo=RepoModel(repoName=repo_dict['repoName'],
		    repoAddress=repo_dict['repoAddress'],
		    repoUser=repo_dict['repoUser'],
		    repoPassword=repo_dict['repoPassword'],
		    wwwDir=repo_dict['wwwDir'],
		    testDeployIP=repo_dict['testDeployIP'],
		    preDeployIP=repo_dict['preDeployIP'],
		    onlineDeployIP=repo_dict['onlineDeployIP'],
		    excludeDir=repo_dict['excludeDir'],
		    repoType='svn',
		    localCheckoutDir=repo_dict['localCheckoutDir'],
		    addDate=addDate)
	    try:
		repoinfo.save()
	    except e:
		return HttpResponse(u'添加库信息失败')
	    return HttpResponseRedirect(reverse('deploy:list_repo_info'))
	return  render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))
    form=SvnInfoForm()
    return render_to_response('add_svn_repo.html',RequestContext(request,{'form':form}))