def addEntry(request, repo, type): print "sono in addEntry" print request.POST #print request.POST.keys() #print request.POST.values() #print request.POST.iterlists() results = {} for k, v in request.POST.iterlists(): results[k] = v[0].encode() results['SubmissionDate'] = str(datetime.datetime.now())[:16] results['Thumb'] = 1 print results.keys() print results.values() client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'aginfra', '4g1nfr4') entry_id = client.sequenceNext('/' + repo + '/Entries/id') client.addEntry('/' + repo + '/Entries/' + type + '/' + entry_id, results.keys(), results.values()) #c['cid'] = cid success = {'success': True, 'data': results} response = HttpResponse(json.dumps(success)) #response=HttpResponse(request.raw_post_data) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def columnas(request, repo): client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') directory = '/' + repo + '/Entries/Scans' client.selectAttr( ['/' + repo + '/Types:VisibleAttrs', 'ColumnWidth', 'ColumnLabels'], 'Path="' + directory + '"') entry = client.getSelectAttrEntry() visAttrs = entry[0].split(' ') print visAttrs atr, types = client.listAttr(directory) fields = [] columns = [] if request.method != 'OPTIONS': for i in range(len(atr)): fields.append({'name': atr[i], 'mapping': atr[i]}) columns.append({ 'header': atr[i], 'width': 30, 'dataIndex': atr[i], 'colType': types[i] }) jsonData = json.dumps({ 'metadata': { 'root': 'records', 'totalProperty': 'total', 'fields': fields }, 'columns': columns }) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def get_tree_dir(request, tree_id): client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') resultado = [] # retrieves the data of the corresponding node (parameter 'node') client.listEntries(tree_id) while not client.eot(): file, val = client.getEntry() # process the data creating the tree structure if val[0].startswith('collection'): resultado.append({'id': file, 'text': file, 'leaf': False}) else: resultado.append({'id': file, 'text': file, 'leaf': True}) # creates the jsonData structure that will be returned jsonData = json.dumps(resultado) html = "%s" % jsonData response = HttpResponse(html) return response
def get_tree(request): client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') resultado = [] if request.method != 'OPTIONS': # retrieves the data of the corresponding node (parameter 'node') client.listEntries(request.GET.getlist('node')[0]) while not client.eot(): file, val = client.getEntry() # process the data creating the tree structure if val[0].startswith('collection'): resultado.append({'id': file, 'text': file, 'leaf': False}) else: resultado.append({'id': file, 'text': file, 'leaf': True}) # creates the jsonData structure that will be returned jsonData = json.dumps(resultado) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def getLinks(request, repo, id): client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') client.cd('/' + repo + '/Replicas') resultado = {'autoEl': {'html': ''}} if request.method != 'OPTIONS': # retrieves the availables surls of the file client.selectAttr(['.:surl'], 'ID=' + id) # constructs the structure with the links of the replicas while not client.eot(): link = client.getSelectAttrEntry()[0] resultado['autoEl']['html'] = resultado['autoEl'][ 'html'] + '<a href="http://glibrary.ct.infn.it/django/download/' + link.lstrip( "https://") + '" TARGET="_blank">' + link + '</a><br>' # creates the jsonData structure and the response that will be returned jsonData = json.dumps(resultado) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' print "response: %s", response return response
def saveMetadata(request, repo, path): print "sono in saveMetadata" print "repo:", repo print "path:", path print request.POST print "method:", request.method #print request.POST.keys() #print request.POST.values() #print request.POST.iterlists() results = {} if request.method != 'OPTIONS': for k, v in request.POST.iterlists(): results[k] = v[0].encode() results['SubmissionDate'] = str(datetime.datetime.now())[:16] results['Thumb'] = 0 surl = results['Replica'] results.pop('Replica', None) print results.keys() print results.values() client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'glibraryadmin', 'r3p0@dm1N') entry_id = client.sequenceNext('/' + repo + '/Entries/id') client.addEntry('/' + repo + '/' + path + '/' + entry_id, results.keys(), results.values()) #c['cid'] = cid rep_id = client.sequenceNext('/' + repo + '/Replicas/rep') client.addEntry('/' + repo + '/Replicas/' + rep_id, ['surl', 'ID', 'enabled'], [surl, entry_id, True]) success = {'success': True, 'data': results} response = HttpResponse(json.dumps(success)) #response=HttpResponse(request.raw_post_data) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def getTree(request, repo): client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') resultado = [] # access to the directory client.cd(repo + '/Types') if request.method != 'OPTIONS': # retrieve information of the selected node client.selectAttr(['.:TypeName', 'FILE', 'Path', 'VisibleAttrs'], 'ParentID=' + request.GET.getlist('node')[0]) # process information to create the tree structure while not client.eot(): entry = client.getSelectAttrEntry() resultado.append({ 'text': entry[0], 'id': entry[1], 'path': entry[2], 'leaf': False, 'visibleAttrs': entry[3] }) # check if the selected node is a leaf to mark it as that for i in range(len(resultado)): client.selectAttr(['.:TypeName', 'FILE'], 'ParentID=' + resultado[i]['id']) if (client.eot()): resultado[i]['leaf'] = True resultado[i]['iconCls'] = 'folder-icon' else: while not client.eot(): client.getSelectAttrEntry() # creates the jsonData structure and the response that will be returned jsonData = json.dumps(resultado) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def getLinks2(request, repo, id): client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') storages = [] # gets information of the enabled hosts (SE)... client.selectAttr(['/deroberto2/Storages:Host', 'Enabled'], '') # ...and creates a structure with that info while not client.eot(): entry = client.getSelectAttrEntry() storages.append({'name': entry[0], 'enabled': entry[1]}) client.cd('/' + repo + '/Replicas') resultado = [] if request.method != 'OPTIONS': # retrieves the links of the replicas of the selected file client.selectAttr(['.:surl', 'enabled'], 'ID=' + id) while not client.eot(): entry = client.getSelectAttrEntry() link = entry[0] enabled = entry[1] #downLink=link.lstrip("https://") if link.startswith('https://'): downLink = link[8:] else: downLink = link[7:] print "downlink: ", downLink #print "link is: ", downLink # checks if the SE of the current replica is enabled... #for i in range(len(storages)): # if downLink.startswith(storages[i]['name']): # enabled=storages[i]['enabled'] #...and adds the data of that replica to the data structure to be returned if downLink.startswith("infn-se-03"): resultado.append({ 'link': '<a href="http://glibrary.ct.infn.it/django/download/' + downLink + '" TARGET="_blank">Download</a>', 'lat': '37.524971', 'lng': '15.071976', 'name': 'INFN-CATANIA', 'enabled': enabled }) elif downLink.startswith("prod-se-03"): resultado.append({ 'link': '<a href=/glibrary/download/' + downLink + ' TARGET="_blank">Download</a>', 'lat': '37.525077', 'lng': '15.073253', 'name': 'INFN-SE', 'enabled': enabled }) elif downLink.startswith("gridsrv3-4.dir.garr.it"): resultado.append({ 'link': '<a href=/glibrary/download/' + downLink + ' TARGET="_blank">Download</a>', 'lat': '41.899131', 'lng': '12.511935', 'name': 'GARR-SE', 'enabled': enabled }) elif downLink.startswith("se.reef.man.poznan.pl"): resultado.append({ 'link': '<a href=/glibrary/download/' + downLink + ' TARGET="_blank">Download</a>', 'lat': '52.411922', 'lng': '16.916131', 'name': 'POZNAN-SE', 'enabled': enabled }) elif downLink.startswith("unict-dmi-se-01"): resultado.append({ 'link': '<a href="/glibrary/download/' + downLink + '"/ TARGET="_blank">Download</a>', 'lat': '37.525077', 'lng': '15.073253', 'name': 'DMI UNICT', 'enabled': enabled }) elif downLink.startswith("unime-se-01"): resultado.append({ 'link': '<a href="http://glibrary.ct.infn.it/django/download/' + downLink + '" TARGET="_blank">Download</a>', 'lat': '38.259842', 'lng': '15.599223', 'name': 'UNIME', 'enabled': "0" }) elif downLink.startswith("unict-diit-se-01"): resultado.append({ 'link': '<a href="http://glibrary.ct.infn.it/django/download/' + downLink + '" TARGET="_blank">Download</a>', 'lat': '37.525077', 'lng': '15.073253', 'name': 'DIIT', 'enabled': "0" }) elif downLink.startswith("inaf-se-01"): resultado.append({ 'link': '<a href="http://glibrary.ct.infn.it/django/download/' + downLink + '" TARGET="_blank">Download</a>', 'lat': '37.528779', 'lng': '15.071746', 'name': 'INAF', 'enabled': "0" }) elif downLink.startswith("unipa-se-01"): resultado.append({ 'link': '<a href="http://glibrary.ct.infn.it/django/download/' + downLink + '" TARGET="_blank">Download</a>', 'lat': '38.1166667', 'lng': '13.3666667', 'name': 'UNIPA', 'enabled': "0" }) elif downLink.startswith("eunode4"): resultado.append({ 'link': '<a href="http://glibrary.ct.infn.it/django/download/' + downLink + '" TARGET="_blank">Download</a>', 'lat': '39.970806', 'lng': '116.411133', 'name': 'BEIJING', 'enabled': enabled }) elif downLink.startswith("earth.eo.esa.int"): resultado.append({ 'link': '<a href="http://' + downLink + '" TARGET="_blank">Download</a>', 'lat': '41.900233', 'lng': '12.683287', 'name': 'ESA', 'enabled': enabled }) else: resultado.append({ 'link': '<a href="http://' + downLink + '" TARGET="_blank">Download</a>', 'lat': '37.4907111', 'lng': '15.0772719', 'name': 'INFN', 'enabled': enabled }) #print "resultado:", resultado # creates the jsonData structure and the response that will be returned jsonData = json.dumps(resultado) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def metadata(request, directory): repoArr = directory.split('/') repo = repoArr[0] client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') #dirVisAttrs='/'+repo+'/Entries' # retrieving information of the attributes and the columns client.selectAttr([ '/' + repo + '/Types:VisibleAttrs', 'ColumnWidth', 'FilterAttrs', 'ColumnLabels' ], 'Path="/' + directory + '"') entry = client.getSelectAttrEntry() visAttrs = entry[0].split(' ') lenAttrs = entry[1].split(' ') filterAttrs = entry[2].split(' ') labelAttrs = entry[3].split(',') atr, types = client.listAttr(directory) #atr.append('/'+directory+':FILE') #types.append('int') fields = [] columns = [] filters = [] if request.method != 'OPTIONS': # starting building the data structured to be returned, the 'fields' array that will # have the info for the store of the database attributes to be mapped and the 'columns' one # that with the information to display the columns of the grid on ExtJS for i in range(len(atr)): # setting the type of data of the fields if types[i] == 'int': fields.append({ 'name': atr[i], 'mapping': atr[i], 'type': 'int' }) else: fields.append({'name': atr[i], 'mapping': atr[i]}) # default column definition columns.append({ 'align': 'left', 'css': 'vertical-align: middle;', 'header': '<font face="verdana">' + atr[i] + '</font>', 'width': 80, 'dataIndex': atr[i], 'colType': types[i], 'hidden': True, 'sortable': True }) if (atr[i].endswith('Description')): columns[i]['id'] = 'descrip' # setting visible attributes for j in range(len(visAttrs)): if visAttrs[j] == atr[i]: columns[i]['width'] = int(lenAttrs[j]) columns[i]['hidden'] = False # extra fields to be able to display the thumbnails fields.append({ 'name': '/' + repo + '/Thumbs:Data', 'mapping': '/' + repo + '/Thumbs:Data' }) fields.append({ 'name': '/' + directory + ':FILE', 'mapping': '/' + directory + ':FILE' }) # reordering the attributes so that they will be displayed in the proper order (VisibleAttrs) for i in range(len(visAttrs)): for j in range(len(columns)): if (visAttrs[i] == columns[j]['dataIndex']): # correction to display the thumbnails if (columns[j]['dataIndex'] == 'Thumb'): columns[j]['id'] = 'thumb' columns[j]['dataIndex'] = '/' + repo + '/Thumbs:Data' col = columns[j] columns.remove(col) columns.insert(i, col) # constructing data for the filters configuration for i in range(len(filterAttrs)): options = [] if filterAttrs[i] != 'PagNum' and filterAttrs[i] != 'Size': # retrieving the possible values for the actual filter (filterAttrs[i] client.selectAttr([directory + ':' + filterAttrs[i]], 'distinct') while not client.eot(): entry = client.getSelectAttrEntry() if entry[0] != '': options.append([entry[0]]) # adding the configuration of the current filter to the filters array filters.append({ 'type': 'list', 'dataIndex': filterAttrs[i], 'labelField': 'filter' + filterAttrs[i], 'filterList': options }) else: filters.append({ 'type': 'numeric', 'dataIndex': filterAttrs[i] }) # creates the jsonData structure and the response that will be returned jsonData = json.dumps({ 'metadata': { 'root': 'records', 'totalProperty': 'total', 'fields': fields, 'custom': 'pruebaaaa' }, 'columns': columns, 'filters': filters }) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def getFilterValues(request, directory): repoArr = directory.split('/') repo = str(repoArr[0]) #takes the filterData parameter with the data of the currently applied filters if request.GET.has_key('filterData'): filterData = json.loads(request.GET.getlist('filterData')[0]) client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') #directory='/'+repo+'/Entries' result = [] if request.method != 'OPTIONS': # retrieves the filterable attributes client.selectAttr(['/' + repo + '/Types:FilterAttrs'], 'Path="/' + directory + '"') entry = client.getSelectAttrEntry() filterAttrs = entry[0].split(' ') # for each of the filterable attributes (list ones) we have to update their possible values... for k in range(len(filterAttrs)): pet = '' #...so for each active filter, we check that same attribute is not one of the active... for i in range(len(filterData)): #...filters. (We don't need to update the values of the active filters) if filterAttrs[k] != filterData[i]['field']: if filterData[i]['data']['type'] != 'numeric': # We start creating the query. Adding the current active filters... for j in range(len(filterData[i]['data']['value'])): #...with all the different values selected in that active filter if j < len(filterData[i]['data']['value']) - 1: pet = pet + str( filterData[i]['field']) + '="' + str( filterData[i]['data']['value'] [j]) + '" or ' else: pet = pet + str( filterData[i]['field']) + '="' + str( filterData[i]['data']['value'] [j]) + '" ' # If it is not the last filter active, we keep on creating the whole query. if i < len(filterData) - 1 and ( filterData[i + 1]['field'] != filterAttrs[k] or i + 1 < len(filterData) - 1 ) and filterData[i + 1]['data']['type'] != 'numeric': pet = pet + ' and ' # finally we add the distinct clause to the query and execute it... if pet.endswith('and '): pet = pet[0:-4] client.selectAttr([directory + ':' + filterAttrs[k]], pet + 'distinct') options = [] #...retrieving all the new possible filter options for that attribute... while not client.eot(): entry = client.getSelectAttrEntry() if entry[0] != '': options.append(entry) #...and adding those options to the result structure, repeating the process for the... #...rest of the filterable attributes result.append(options) # creates the jsonData structure and the response that will be returned jsonData = json.dumps(result) html = "%s" % jsonData response = HttpResponse(html) response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'GET,POST' response['Access-Control-Allow-Headers'] = 'x-requested-with' return response
def getData(request, directory): repoArr = directory.split('/') repo = str(repoArr[0]) client = mdclient.MDClient('glibrary.ct.infn.it', 8822, 'miguel', 'p1pp0') atr, types = client.listAttr(directory) # Taking the possible parameters if request.GET.has_key('start'): start = int(request.GET.getlist('start')[0]) else: start = 0 #if request.GET.has_key('limit'): # limit=start+int(request.GET.getlist('limit')[0]) #else: limit = 50 filterList = [] i = 0 # Retrieving the possible filters while request.GET.has_key('filter[' + str(i) + '][field]'): filter = { 'data': { 'type': '', 'value': '', 'comparison': 'eq' }, 'field': '' } filter['field'] = request.GET.getlist('filter[' + str(i) + '][field]')[0] filter['data']['type'] = request.GET.getlist('filter[' + str(i) + '][data][type]')[0] if filter['data']['type'] == 'numeric': filter['data']['comparison'] = request.GET.getlist( 'filter[' + str(i) + '][data][comparison]')[0] filter['data']['value'] = request.GET.getlist('filter[' + str(i) + '][data][value]') filterList.append(filter) i = i + 1 #print 'filter->',filter['field'],'=',filter['data']['value'] cad = '' # Creating the query from the filters' information for i in range(len(filterList)): longit = len(filterList[i]['data']['value']) for j in range(longit): if filterList[i]['data']['comparison'] == 'eq': comparator = '=' elif filterList[i]['data']['comparison'] == 'lt': comparator = '<' elif filterList[i]['data']['comparison'] == 'gt': comparator = '>' if j == (longit - 1): cad = cad + filterList[i][ 'field'] + comparator + '"' + filterList[i]['data'][ 'value'][j] + '" ' #print 'filterList',filterList[i]['field'],'="',filterList[i]['data']['value'][j],'"' else: cad = cad + filterList[i][ 'field'] + comparator + '"' + filterList[i]['data'][ 'value'][j] + '" or ' #print 'filterList',filterList[i]['field'],'="',filterList[i]['data']['value'][j],'" or' cad = cad + 'and ' j = 0 resultado = [] #client.getattr(directory,atr) atr0 = atr[0] atr[0] = '/' + directory + ':' + atr[0] atr.append('/' + directory + ':FILE') atr.append('/' + repo + '/Thumbs:Data') # Making the query to the gLibrary server if (directory == 'miguel'): client.selectAttr(atr, 'limit ' + str(limit) + ' offset ' + str(start)) else: client.selectAttr( atr, str(cad) + 'Thumb=' + repo + '/Thumbs:FILE limit ' + str(limit) + ' offset ' + str(start)) # Obtaining the data received and preparing it to be returned to the server while not client.eot(): val = client.getSelectAttrEntry() #file,val=client.getEntry() resultado.insert(j, {}) for i in range(len(val)): resultado[j][atr[i]] = val[i] resultado[j][atr0] = val[0] j = j + 1 # Asking for the number of entries returned if len(cad) > 5: client.selectAttr(['count(' + directory + ':FILE)'], str(cad[0:-5])) else: client.selectAttr(['count(' + directory + ':FILE)'], '') total = client.getSelectAttrEntry() # Making the jsonData structure to be returned jsonData = json.dumps({'total': total, 'records': resultado}) if request.GET.has_key('callback'): html = request.GET.getlist('callback')[0] + "(%s);" % jsonData return HttpResponse(html, content_type="text/javascript") else: html = "%s" % jsonData return HttpResponse(html)