Exemple #1
0
def addfiles(request):
    
    import os
    from os.path import basename
    from os import path
    from tardis.tardis_portal.models import Dataset_File
    import itertools
    from tardis.hpctardis.metadata import process_all_experiments
    from tardis.hpctardis.metadata import process_experimentX
    
    if 'username' in request.POST and \
            'password' in request.POST:
        authMethod = request.POST['authMethod']
        
        user = auth_service.authenticate(
            authMethod=authMethod, request=request)

    if user:
        eid    = request.POST['eid']
        desc   = request.POST['desc']
        folder = request.POST['folder']
        eid  = int(eid)
        
#   TODO Use the try and except
        auth_key = settings.DEFAULT_AUTH
        try:
            exp = Experiment.objects.get(pk=eid)
            author = exp.created_by 
        except Experiment.DoesNotExist:
            logger.exception('Experiment for eid %i in addfiles does not exist' % eid)
            return  HttpResponse("Experiment Not Found")

        current_user = str(user) 
        created_user = str(author)
        
        if current_user == created_user: 
            staging = path.join(settings.STAGING_PATH,str(user),str(eid),str(folder))
            filelist = []
            ds_desc  = {} 
 #          import pdb
 #          pdb.set_trace()
            for root, dirs, files in os.walk(staging):                       
                for named in files:  
                    filelist.append(named)
                
            next = str(filelist)   
            ds_desc[desc] = filelist
            
#TODO If needed for security - Metadata from the folder can be extracted 
#to check the folder name  

            for d, df in ds_desc.items():
                dataset = models.Dataset(description=d,
                                     experiment=exp)
                dataset.save()
                for f in df:
                    logger.debug('f = %s' %f)
                    filepath = path.join(staging,f)                    
                    size = path.getsize(filepath)
                    filename = path.basename(filepath)
    
                    datafile = Dataset_File(dataset=dataset, filename=filename,
                                               url=filepath, size=size, protocol='staging')
                    datafile.save()
                
            next = next + ' File path :' + staging 
        
            process_experimentX(exp) ;
        
            next = next + ' The Author is : ' + str(author) + ',' + ' The User is : ' + str(user)         
            return  HttpResponse(next)
        else:
            next = 'The author of the experiment can only add the files (From Tardis)'
            return HttpResponse(next)
    else:
        return  HttpResponse("UnSuccessful") 
Exemple #2
0
def addfiles(request):

    import os
    from os.path import basename
    from os import path
    from tardis.tardis_portal.models import Dataset_File
    import itertools
    from tardis.hpctardis.metadata import process_all_experiments
    from tardis.hpctardis.metadata import process_experimentX

    if 'username' in request.POST and \
            'password' in request.POST:
        authMethod = request.POST['authMethod']

        user = auth_service.authenticate(authMethod=authMethod,
                                         request=request)

    if user:
        eid = request.POST['eid']
        desc = request.POST['desc']
        folder = request.POST['folder']
        eid = int(eid)

        #   TODO Use the try and except
        auth_key = settings.DEFAULT_AUTH
        try:
            exp = Experiment.objects.get(pk=eid)
            author = exp.created_by
        except Experiment.DoesNotExist:
            logger.exception(
                'Experiment for eid %i in addfiles does not exist' % eid)
            return HttpResponse("Experiment Not Found")

        current_user = str(user)
        created_user = str(author)

        if current_user == created_user:
            staging = path.join(settings.STAGING_PATH, str(user), str(eid),
                                str(folder))
            filelist = []
            ds_desc = {}
            #          import pdb
            #          pdb.set_trace()
            for root, dirs, files in os.walk(staging):
                for named in files:
                    filelist.append(named)

            next = str(filelist)
            ds_desc[desc] = filelist

            #TODO If needed for security - Metadata from the folder can be extracted
            #to check the folder name

            for d, df in ds_desc.items():
                dataset = models.Dataset(description=d, experiment=exp)
                dataset.save()
                for f in df:
                    logger.debug('f = %s' % f)
                    filepath = path.join(staging, f)
                    size = path.getsize(filepath)
                    filename = path.basename(filepath)

                    datafile = Dataset_File(dataset=dataset,
                                            filename=filename,
                                            url=filepath,
                                            size=size,
                                            protocol='staging')
                    datafile.save()

            next = next + ' File path :' + staging

            process_experimentX(exp)

            next = next + ' The Author is : ' + str(
                author) + ',' + ' The User is : ' + str(user)
            return HttpResponse(next)
        else:
            next = 'The author of the experiment can only add the files (From Tardis)'
            return HttpResponse(next)
    else:
        return HttpResponse("UnSuccessful")