Пример #1
0
    def handle(self, *args, **options):
        if len(args) < 1:
            self.stdout.write("no command specified\n")
            return

        if args[0] == 'all':
            yesno = raw_input("Are you REALLY sure you want to extract ALL "
                              "experiment metadata (will overwrite existing "
                              "data) [y/N]")
            if yesno.lower() == "y":
                process_all_experiments()
        else:
            try:
                expid = int(args[0])
            except ValueError:
                self.stderr.write("invalid experiment id")
                return
            exp = Experiment.objects.get(id=expid)
            process_experimentX(exp)
Пример #2
0
 def handle(self, *args, **options):
     if len(args) < 1:
         self.stdout.write("no command specified\n")
         return
     
     if args[0] == 'all':
         yesno = raw_input("Are you REALLY sure you want to extract ALL "
                           "experiment metadata (will overwrite existing "
                           "data) [y/N]")
         if yesno.lower() == "y":    
             process_all_experiments()
     else:
         try:
             expid = int(args[0])
         except ValueError: 
             self.stderr.write("invalid experiment id")
             return
         exp = Experiment.objects.get(id=expid)    
         process_experimentX(exp)
Пример #3
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.apps.hpctardis.metadata import process_all_experiments
    from tardis.apps.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")