示例#1
0
def metaadd(req):
    '''
    :param req:
    :return:
    '''
    uname = req.GET['id'].encode('utf-8')
    name_token = '_'.join([uname, 'token'])
    name_url = '_'.join([uname,'url'])
    token = cache.get(name_token)
    url = cache.get(name_url)
    pattern = re.compile('\(.+\)')
    if req.method == 'POST':
        mf = MetaForm(req.POST,req.FILES)
        if mf.is_valid():
            name = req.POST.get('object_name').encode('utf-8')
            secfiled = req.POST.get('parent_secl_id').encode('utf-8')
            seclevel = req.POST.get('obj_seclevel').encode('utf-8')
            meta_info = dict(req.FILES).values()[0]
            stype = pattern.findall(str(meta_info))[0].strip('()')
            path = str(meta_info).split(' ')[1]
            print stype,path,name,secfiled,seclevel,meta_info,stype
            values=(path, name, secfiled, seclevel, stype, token, str(url)+'/sun/%s'% path)
            print values
            print url
            content = popen("curl -X PUT -T ~/%s -D- -H 'object_name:%s' -H 'parent_secl_id:%s' -H \
            'obj_seclevel:%s' -H 'Content-Type:%s' -H '%s' %s" % values).readlines()
            print content
            return HttpResponse(content[-1])
    else:
        mf = MetaForm()
    return render_to_response('addmetadb.html', {'mf':mf})
示例#2
0
文件: views.py 项目: hbhdytf/mac-web2
def metaadd(req):
    """
    :param req:
    :return:
    """
    header = {}
    if req.method=='GET':
        uname=req.GET['id'].encode('utf-8')
    if req.method=='POST':
        uname = req.POST['id'].encode('utf-8')
    name_token = '_'.join([uname, 'token'])
    print "metaadd===============:"
    name_url = '_'.join([uname, 'url'])
    token = cache.get(name_token)
    '''url = cache.get(name_url)'''
    url = 'http://127.0.0.1:8080/v1/AUTH_mac'
    pattern = re.compile('\(.+\)')
    print req.method
    if req.method == 'POST':
        mf = MetaForm(req.POST, req.FILES)
        if mf.is_valid():
            filename = handle_upload_file(req.FILES['path'])
            if not filename:
                return HttpResponse("Upload Failed!")
            name = req.POST.get('object_name').encode('utf-8')
            secfiled = req.POST.get('parent_secl_id').encode('utf-8')
            seclevel = req.POST.get('obj_seclevel').encode('utf-8')
            meta_info = dict(req.FILES).values()[0]
            stype = pattern.findall(str(meta_info))[0].strip('()')
            #path = str(meta_info).split(' ')[1]
            path = filename
            header['object_name'] = name
            header['parent_secl_id'] = secfiled
            header['obj_seclevel'] = seclevel
            print "path=========="+path 
	        #print "name=========="+name
            #print "secfiled======"+secfiled
            #print "seclevel======"+seclevel
	        #print "Url==========="+url
            #print meta_info
            # tt = client.put_object(url, token, contents=mf.cleaned_data['path'], headers=header)
            # return HttpResponse(tt)
            if token is None:
                return HttpResponse("Token is timeout, Please try to regain token.")
            values = (path, name, secfiled, seclevel, stype, token, str(url)+'/ytf%s' % path)
            print values
            content = popen("curl -X PUT -T %s -D- -H 'object_name:%s' -H 'parent_secl_id:%s' -H \
            'obj_seclevel:%s' -H 'Content-Type:%s' -H '%s' %s" % values).readlines()
            return HttpResponse('<h1>文件上传结果: %s</h1></ br><p>%s</p>' % (content[0], content[-1]))
    else:
        mf = MetaForm()
    return render_to_response('addmetadb.html', {'mf': mf,'uname':uname})