Ejemplo n.º 1
0
def prepareFiles(request, context):

    jobinfo = {}
    specimens = []
    for lineno, afile in enumerate(request.FILES.getlist('importfile')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno + 1, 'name',
                                            afile.name, 'size', afile.size)

            handle_uploaded_file(afile)

        except:
            sys.stderr.write("error! file=%s %s" %
                             (afile.name, traceback.format_exc()))
            specimens.append({
                'name':
                afile.name,
                'size':
                afile.size,
                'error':
                'problem uploading file or extracting image metadata, not processed'
            })

    return jobinfo, specimens
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    numProblems = 0
    for lineno, afile in enumerate(request.FILES.getlist('tricoderfiles')):
        # print afile
        # we gotta do this for now!
        if 'barcode.' not in afile.name: afile.name = 'barcode.' + afile.name
        fileinfo = {'id': lineno, 'name': afile.name, 'status': '', 'date': time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())}
        # always use the current date as the date for the filename checking
        today = time.strftime("%Y-%m-%d", time.localtime())
        filenamepattern = r'^barcode.TRIDATA_' + re.escape(today) + r'_[\w_\.]+\.DAT$'
        if not re.match(filenamepattern, afile.name):
            fileinfo['status'] = 'filename is not valid'
            numProblems += 1
        else:
            try:
                print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name, 'size', afile.size)
                if not validateonly:
                    handle_uploaded_file(afile)
                fileinfo['status'] = 'OK'
            except:
                if validateonly:
                    fileinfo['status'] = 'validation failed'
                else:
                    fileinfo['status'] = 'file handling problem, not uploaded'
                numProblems += 1

        tricoder_files.append(fileinfo)

    if numProblems > 0:
        errormsg = 'Errors found, abandoning upload. Please fix and try again.'
    else:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        tricoder_fileinfo['tricoder_filenumber'] = tricoder_filenumber
        tricoder_fileinfo['estimatedtime'] = '%8.1f' % (len(tricoder_files) * 10 / 60.0)

        if 'createtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'createtricoder'
            if not validateonly:
                loginfo('start', get_tricoder_file('input',tricoder_filenumber), request)
                try:
                    retcode = subprocess.call(
                        [POSTBLOBPATH, get_tricoder_file('input',tricoder_filenumber)])
                    if retcode < 0:
                        loginfo('process', tricoder_filenumber + " Child was terminated by signal %s" % -retcode,
                                request)
                    else:
                        loginfo('process', tricoder_filenumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', get_tricoder_file('input',tricoder_filenumber), request)

        elif 'uploadtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'uploadtricoder'
        else:
            tricoder_fileinfo['status'] = 'No status possible'

    return tricoder_fileinfo, tricoder_files, numProblems
Ejemplo n.º 3
0
def import_shapefile_to_simple_locations(request, level=2):

    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'], level)
            return HttpResponse("OK")
        else:
            return HttpResponse("NOTOK")
            
    else:
        form = UploadFileForm()
    return render_to_response('maintenance/upload.html', {'form': form},
                              context_instance = RequestContext(request),)
Ejemplo n.º 4
0
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    for lineno, afile in enumerate(request.FILES.getlist("tricoderfiles")):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ("id", lineno, "name", afile.name, "size", afile.size)
            fileinfo = {"id": lineno, "name": afile.name, "size": afile.size, "date": ""}
            if not validateonly:
                handle_uploaded_file(afile)
            tricoder_files.append(fileinfo)
        except:
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            tricoder_files.append(
                {"name": afile.name, "size": afile.size, "error": "problem extracting image metadata, not processed"}
            )

    if len(tricoder_files) > 0:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        tricoder_fileinfo["tricoder_filenumber"] = tricoder_filenumber
        tricoder_fileinfo["estimatedtime"] = "%8.1f" % (len(tricoder_files) * 10 / 60.0)

        if "createtricoder" in request.POST:
            tricoder_fileinfo["status"] = "createtricoder"
            if not validateonly:
                loginfo("start", get_tricoder_file(tricoder_filenumber), request)
                try:
                    retcode = subprocess.call([POSTBLOBPATH, get_tricoder_file(tricoder_filenumber)])
                    if retcode < 0:
                        loginfo(
                            "process", tricoder_filenumber + " Child was terminated by signal %s" % -retcode, request
                        )
                    else:
                        loginfo("process", tricoder_filenumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo("error", "Execution failed: %s" % e, request)
                loginfo("finish", get_tricoder_file(tricoder_filenumber), request)

        elif "uploadtricoder" in request.POST:
            tricoder_fileinfo["status"] = "uploadtricoder"
        else:
            tricoder_fileinfo["status"] = "No status possible"

    return tricoder_fileinfo, tricoder_files
Ejemplo n.º 5
0
def import_shapefile_to_simple_locations(request, level=2):

    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)

        if form.is_valid():
            handle_uploaded_file(request.FILES['file'], level)
            return HttpResponse("OK")
        else:
            return HttpResponse("NOTOK")

    else:
        form = UploadFileForm()
    return render_to_response(
        'maintenance/upload.html',
        {'form': form},
        context_instance=RequestContext(request),
    )
Ejemplo n.º 6
0
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    for lineno, afile in enumerate(request.FILES.getlist('tricoderfiles')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name, 'size', afile.size)
            fileinfo = {'id': lineno, 'name': afile.name, 'size': afile.size, 'date': ''}
            if not validateonly:
                handle_uploaded_file(afile)
            tricoder_files.append(fileinfo)
        except:
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            tricoder_files.append({'name': afile.name, 'size': afile.size,
                           'error': 'problem extracting image metadata, not processed'})

    if len(tricoder_files) > 0:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        tricoder_fileinfo['tricoder_filenumber'] = tricoder_filenumber
        tricoder_fileinfo['estimatedtime'] = '%8.1f' % (len(tricoder_files) * 10 / 60.0)

        if 'createtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'createtricoder'
            if not validateonly:
                loginfo('start', get_tricoder_file(tricoder_filenumber), request)
                try:
                    retcode = subprocess.call(
                        [POSTBLOBPATH, get_tricoder_file(tricoder_filenumber)])
                    if retcode < 0:
                        loginfo('process', tricoder_filenumber + " Child was terminated by signal %s" % -retcode, request)
                    else:
                        loginfo('process', tricoder_filenumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', get_tricoder_file(tricoder_filenumber), request)

        elif 'uploadtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'uploadtricoder'
        else:
            tricoder_fileinfo['status'] = 'No status possible'

    return tricoder_fileinfo, tricoder_files
Ejemplo n.º 7
0
def upload(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():

            handle_uploaded_file(request)

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('upload'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the summary page sorted by created time
    documents = Document.objects.all().order_by('-created_time')
    # Render list page with the documents and the form

    return render(request, 'upload.html', {
        'documents': documents,
        'form': form
    })
Ejemplo n.º 8
0
def user_image_upload(request):
	# Check authentication
	if "username" not in request.session:
		return redirect("/login/")
	
	if request.method == 'GET':
		form = UploadForm()
		return render(request, 'upload.html', { 'title': 'Upload', 'form': form })
	
	elif request.method == 'POST':
		form = UploadForm(request.POST, request.FILES)

		if not form.is_valid():
			return render(request, 'upload.html', { 'title': 'Upload', 'form': form, 'response_message': 'fail' })
		
		# Handle file
		fpath = handle_uploaded_file(request.FILES['file_image'])
		fname = get_filename(request.FILES['file_image'].name)
		
		# Send file to API
		params = {
				"id": fname,
				"name": form.cleaned_data['appname'],
				"status": form.cleaned_data['status'],
				"manifest_id": form.cleaned_data['manifest_id'],
				"storage_id": form.cleaned_data['storage_id'],
				"plugin_id": form.cleaned_data['plugin_id'],
				"disk_format": form.cleaned_data['disk_format'],
				"container_format": form.cleaned_data['container_format'],
				}
		files = {"image": open(fpath, 'rb')}
		
		try:
			putNewAppToAPI(fname, files, params)
			request.session['upload_status'] = 'success'
		except requests.exceptions.HTTPError:
			return render(request, 'upload.html', { 'title': 'Upload', 'form': form, 'response_message': 'fail' })
			
		# Delete file
		os.remove(fpath)
		
		return redirect('/store/')
Ejemplo n.º 9
0
def add_pic_to_person(request): 
    # validate if this user owns this profile, then only she can add picture to this profile.
    if 'person_id' not in request.GET:
        raise Http404
    objs = MissingPerson.objects.filter(reporting_user_id=request.user.id, id=request.GET['person_id'])
    if objs is None:
        raise Http404

    ''' 
    Steps:
    1. Detect Face in picture.
    2. Save the picture locally
    3. Add the picture in FaceMatcher module to person.
    '''
    try:
        matcher = utils.handle_uploaded_file(request)
        utils.add_source_picture(request.GET['person_id'],matcher)
    except Exception as e:
        raise Http404(e)
    return HttpResponse("done")
Ejemplo n.º 10
0
def upload(request):
    if request.method == 'POST' and 'Upload' in request.POST:
        form1 = UploadForm1(request.POST, request.FILES)
        form2 = UploadForm2(request.POST, request.FILES)
        form3 = UploadForm3(request.POST, request.FILES)
        form4 = UploadForm4(request.POST, request.FILES)
        form5 = UploadForm5(request.POST, request.FILES)

        p_uuid = uuid4().hex
        date = datetime.date.today().isoformat()
        dest = "/".join(["uploads", str(p_uuid)])

        if form1.is_valid():
            if form2.is_valid():

                project = ".".join(["project", "csv"])
                file1 = request.FILES['docfile1']
                handle_uploaded_file(file1, dest, project)
                parse_project(dest, date, file1, p_uuid)
                print("Parsed project!")

                sample = ".".join(["sample", "csv"])
                file2 = request.FILES['docfile2']
                handle_uploaded_file(file2, dest, sample)
                parse_sample(file2, p_uuid)
                print("Parsed sample!")

                taxonomy = ".".join(["mothur", "taxonomy"])
                file3 = request.FILES['docfile3']
                handle_uploaded_file(file3, dest, taxonomy)
                parse_taxonomy(file3)
                print("Parsed taxonomy!")

                shared = ".".join(["mothur", "shared"])
                file4 = request.FILES['docfile4']
                handle_uploaded_file(file4, dest, shared)
                parse_profile(dest, p_uuid)
                print("Parsed profile!")

                #taxaprofile(p_uuid)
                #print("Taxa profiles created")

            elif form3.is_valid():
                name = ".".join(["project", "csv"])
                file = request.FILES['docfile1']
                handle_uploaded_file(file, dest, name)

                name = ".".join(["sample", "csv"])
                file = request.FILES['docfile2']
                handle_uploaded_file(file, dest, name)

                name = ".".join(["biom_1.5", "txt"])
                file = request.FILES['docfile5']
                handle_uploaded_file(file, dest, name)

            elif form4.is_valid():
                name = ".".join(["project", "csv"])
                file = request.FILES['docfile1']
                handle_uploaded_file(file, dest, name)

                name = ".".join(["sample", "csv"])
                file = request.FILES['docfile2']
                handle_uploaded_file(file, dest, name)

                name = ".".join(["biom_1.4", "txt"])
                file = request.FILES['docfile6']
                handle_uploaded_file(file, dest, name)

            elif form5.is_valid():
                name = ".".join(["project", "csv"])
                file = request.FILES['docfile1']
                handle_uploaded_file(file, dest, name)

                name = ".".join(["sample", "csv"])
                file = request.FILES['docfile2']
                handle_uploaded_file(file, dest, name)

                name = ".".join(["biom_1.4", "txt"])
                file = request.FILES['docfile7']
                handle_uploaded_file(file, dest, name)

            else:
                print("Please upload taxonomic profile data")

        else:
            print("Please upload meta files")

    elif request.method == 'POST' and 'clickMe' in request.POST:
        remove_list(request)

    projects = Project.objects.all().order_by('project_name')
    return render_to_response('upload.html', {
        'projects': projects,
        'form1': UploadForm1,
        'form2': UploadForm2,
        'form3': UploadForm3,
        'form4': UploadForm4,
        'form5': UploadForm5
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 11
0
 def save(self):
     self.folder, root_path = get_root_path(self.folder_name)
     name = self.cleaned_data["file"].name
     self.filename, self.path = get_file_path(name, root_path)
     handle_uploaded_file(self.cleaned_data["file"], self.path)
Ejemplo n.º 12
0
def uploadfiles(request):

    jobinfo = {}
    constants = {}
    images = []
    dropdowns = getDropdowns()
    elapsedtime = time.time()

    form = forms.Form(request)
    if request.POST:

        contributor = request.POST['contributor']
        overrideContributor = request.POST['overridecreator']

        creatorDisplayname = request.POST['creator']
        overrideCreator = request.POST['overridecreator']

        rightsholderDisplayname = request.POST['rightsholder']
        overrideRightsholder = request.POST['overriderightsholder']

        constants = {'creator': creatorDisplayname, 'contributor': contributor, 'rightsholder': rightsholderDisplayname}

        for lineno,afile in enumerate(request.FILES.getlist('imagefiles')):
            #print afile
            try:
                print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name, 'size', afile.size)
                im = get_exif(afile)
                objectnumber = getNumber(afile.name)
                #objectCSID = getCSID(objectnumber)
                creator, creatorRefname = assignValue(creatorDisplayname,overrideCreator,im,'Artist',dropdowns['creators'])
                contributor, dummy = assignValue(contributor,overrideContributor,im,'ImageDescription',{})
                rightsholder, rightsholderRefname = assignValue(rightsholderDisplayname,overrideRightsholder,im,'RightsHolder',dropdowns['rightsholders'])
                datetimedigitized, dummy = assignValue('','ifblank',im,'DateTimeDigitized',{})
                imageinfo = {'id': lineno, 'name': afile.name, 'size': afile.size,
                             'objectnumber': objectnumber,
                             #'objectCSID': objectCSID,
                             'date': datetimedigitized,
                             'creator': creatorRefname,
                             'contributor': contributor,
                             'rightsholder': rightsholderRefname,
                             'creatorDisplayname': creator,
                             'rightsholderDisplayname': rightsholder,
                             'contributorDisplayname': contributor
                }
                handle_uploaded_file(afile, imageinfo)
                images.append(imageinfo)
            except:
                #raise
                images.append({'name': afile.name, 'size': afile.size, 'error': 'problem extracting image metadata, not processed'})

        if len(images) > 0:
            jobnumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
            jobinfo['jobnumber'] = jobnumber
            writeCsv(getJobfile(jobnumber)+'.step1.csv', images,
                     ['name', 'size', 'objectnumber', 'date', 'creator', 'contributor', 'rightsholder'])
            jobinfo['estimatedtime'] = '%8.1f' % (len(images) * 10 / 60.0)

            if 'createmedia' in request.POST:
                jobinfo['status'] = 'createmedia'
                loginfo('start', getJobfile(jobnumber), request)
                try:
                    retcode = subprocess.call(["/usr/local/share/django/pahma_project/uploadmedia/postblob.sh", getJobfile(jobnumber)])
                    if retcode < 0:
                        loginfo('process', jobnumber+" Child was terminated by signal %s" %  -retcode, request)
                    else:
                        loginfo('process', jobnumber+": Child returned %s" %  retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', getJobfile(jobnumber), request)

            elif 'uploadmedia' in request.POST:
                jobinfo['status'] = 'uploadmedia'
            else:
                jobinfo['status'] = 'No status possible'

    status = 'up'
    timestamp = time.strftime("%b %d %Y %H:%M:%S", time.localtime())
    elapsedtime = time.time() - elapsedtime

    return render(request, 'uploadmedia.html',
                  {'title': TITLE, 'images': images, 'count': len(images), 'constants': constants, 'jobinfo': jobinfo,
                   'dropdowns': dropdowns, 'overrides': overrides, 'status': status, 'timestamp': timestamp, 'elapsedtime': '%8.2f' % elapsedtime})
Ejemplo n.º 13
0
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    numProblems = 0
    for lineno, afile in enumerate(request.FILES.getlist('tricoderfiles')):
        # print afile
        # we gotta do this for now!
        if 'barcode.' not in afile.name: afile.name = 'barcode.' + afile.name
        fileinfo = {
            'id': lineno,
            'name': afile.name,
            'status': '',
            'date': time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        }
        # always use the current date as the date for the filename checking
        today = time.strftime("%Y-%m-%d", time.localtime())
        filenamepattern = r'^barcode.TRIDATA_' + re.escape(
            today) + r'_[\w_\.]+\.DAT$'
        if not re.match(filenamepattern, afile.name):
            fileinfo['status'] = 'filename is not valid'
            numProblems += 1
        else:
            try:
                print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name',
                                                afile.name, 'size', afile.size)
                if not validateonly:
                    handle_uploaded_file(afile)
                fileinfo['status'] = 'OK'
            except:
                if validateonly:
                    fileinfo['status'] = 'validation failed'
                else:
                    fileinfo['status'] = "error! %s" % traceback.format_exc()
                    sys.stderr.write("error! %s" % traceback.format_exc())
                numProblems += 1

        tricoder_files.append(fileinfo)

    if numProblems > 0:
        errormsg = 'Errors found, abandoning upload. Please fix and try again.'
    else:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S",
                                            time.localtime())
        tricoder_fileinfo['tricoder_filenumber'] = tricoder_filenumber
        tricoder_fileinfo['estimatedtime'] = '%8.1f' % (len(tricoder_files) *
                                                        10 / 60.0)

        if 'createtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'createtricoder'
            if not validateonly:
                loginfo('start', get_tricoder_file('input',
                                                   tricoder_filenumber),
                        request)
                try:
                    retcode = subprocess.call([
                        POSTBLOBPATH,
                        get_tricoder_file('input', tricoder_filenumber)
                    ])
                    if retcode < 0:
                        loginfo(
                            'process', tricoder_filenumber +
                            " Child was terminated by signal %s" % -retcode,
                            request)
                    else:
                        loginfo(
                            'process', tricoder_filenumber +
                            ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish',
                        get_tricoder_file('input', tricoder_filenumber),
                        request)

        elif 'uploadtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'uploadtricoder'
        else:
            tricoder_fileinfo['status'] = 'No status possible'

    return tricoder_fileinfo, tricoder_files, numProblems
Ejemplo n.º 14
0
def prepareFiles(request, validateonly, BMUoptions, constants):
    jobnumber = constants['jobnumber']
    jobinfo = {}
    images = []
    for lineno, afile in enumerate(request.FILES.getlist('imagefiles')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno + 1, 'name', afile.name, 'size', afile.size)
            image = get_exif(afile)
            filename, objectnumber, imagenumber = getNumber(afile.name, INSTITUTION)
            datetimedigitized, dummy = assignValue('', 'ifblank', image, 'DateTimeDigitized', {})
            imageinfo = {'id': lineno, 'name': afile.name, 'size': afile.size,
                         'objectnumber': objectnumber,
                         'imagenumber': imagenumber,
                         # 'objectCSID': objectCSID,
                         'date': datetimedigitized}
            for override in BMUoptions['overrides']:
                dname,refname = assignValue(constants[override[2]][0], constants[override[2]][1], image, override[3], override[4])
                imageinfo[override[2]] = refname
                # add the Displayname just in case...
                imageinfo['%sDisplayname' % override[2]] = dname

            if not validateonly:
                handle_uploaded_file(afile)

            for option in ['handling', 'approvedforweb']:
                if option in request.POST:
                    imageinfo[option] = request.POST[option]
                else:
                    imageinfo[option] = ''

            if 'handling' in request.POST:
                handling = request.POST['handling']
                for parms in BMUoptions['bmuconstants'][handling]:
                    imageinfo[parms] = BMUoptions['bmuconstants'][handling][parms]

                # special case:
                # borndigital media have their mh id numbers unconditionally replaced with a sequence number
                if imageinfo['handling'] == 'borndigital':
                    # for these, we create a media handling number...
                    # options considered were:
                    # DP-2015-10-08-12-16-43-0001 length: 27
                    # DP-201510081216430001 length: 21
                    # DP-2CBE859E990BFB1 length: 18
                    # DP-2015-10-08-12-16-43-0001 length: 27 the winner! (most legible)
                    mhnumber = jobnumber + ("-%0.4d" % (lineno + 1))
                    #mhnumber = hex(int(mhnumber.replace('-','')))[2:]
                    imageinfo['objectnumber'] = 'DP-' + mhnumber
            images.append(imageinfo)

        except:
            # raise
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            images.append({'name': afile.name, 'size': afile.size,
                           'error': 'problem extracting image metadata, not processed'})

    if len(images) > 0:
        jobinfo['jobnumber'] = jobnumber

        if not validateonly:
            writeCsv(getJobfile(jobnumber) + '.step1.csv', images, FIELDS2WRITE)
        jobinfo['estimatedtime'] = '%8.1f' % (len(images) * 10 / 60.0)

        if 'createmedia' in request.POST:
            jobinfo['status'] = 'createmedia'
            if not validateonly:
                loginfo('start', getJobfile(jobnumber), request)
                try:
                    retcode = subprocess.call([path.join(POSTBLOBPATH, 'postblob.sh'), INSTITUTION, getJobfile(jobnumber), BATCHPARAMETERS])
                    if retcode < 0:
                        loginfo('process', jobnumber + " Child was terminated by signal %s" % -retcode, request)
                    else:
                        loginfo('process', jobnumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', getJobfile(jobnumber), request)

        elif 'uploadmedia' in request.POST:
            jobinfo['status'] = 'uploadmedia'
        else:
            jobinfo['status'] = 'No status possible'

    return jobinfo, images
Ejemplo n.º 15
0
def prepareFiles(request, validateonly, BMUoptions, constants):
    jobnumber = constants['jobnumber']
    jobinfo = {}
    images = []
    for lineno, afile in enumerate(request.FILES.getlist('imagefiles')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno + 1, 'name', afile.name, 'size', afile.size)
            image = get_exif(afile)
            filename, objectnumber, imagenumber = getNumber(afile.name, INSTITUTION)
            datetimedigitized, dummy = assignValue('', 'ifblank', image, 'DateTimeDigitized', {})
            imageinfo = {'id': lineno, 'name': afile.name, 'size': afile.size,
                         'objectnumber': objectnumber,
                         'imagenumber': imagenumber,
                         # 'objectCSID': objectCSID,
                         'date': datetimedigitized}
            for override in BMUoptions['overrides']:
                dname,refname = assignValue(constants[override[2]][0], constants[override[2]][1], image, override[3], override[4])
                imageinfo[override[2]] = refname
                # add the Displayname just in case...
                imageinfo['%sDisplayname' % override[2]] = dname

            if not validateonly:
                handle_uploaded_file(afile)

            for option in ['handling', 'approvedforweb']:
                if option in request.POST:
                    imageinfo[option] = request.POST[option]
                else:
                    imageinfo[option] = ''

            if 'handling' in request.POST:
                handling = request.POST['handling']
                for parms in BMUoptions['bmuconstants'][handling]:
                    imageinfo[parms] = BMUoptions['bmuconstants'][handling][parms]

                # special case:
                # borndigital media have their mh id numbers unconditionally replaced with a sequence number
                if imageinfo['handling'] == 'borndigital':
                    # for these, we create a media handling number...
                    # options considered were:
                    # DP-2015-10-08-12-16-43-0001 length: 27
                    # DP-201510081216430001 length: 21
                    # DP-2CBE859E990BFB1 length: 18
                    # DP-2cbe859e990bfb1 length: 18 the winner!
                    mhnumber = jobnumber + ("-%0.4d" % (lineno + 1))
                    #mhnumber = hex(int(mhnumber.replace('-','')))[2:]
                    imageinfo['objectnumber'] = 'DP-' + mhnumber
            images.append(imageinfo)

        except:
            # raise
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            images.append({'name': afile.name, 'size': afile.size,
                           'error': 'problem extracting image metadata, not processed'})

    if len(images) > 0:
        jobinfo['jobnumber'] = jobnumber

        if not validateonly:
            writeCsv(getJobfile(jobnumber) + '.step1.csv', images, FIELDS2WRITE)
        jobinfo['estimatedtime'] = '%8.1f' % (len(images) * 10 / 60.0)

        if 'createmedia' in request.POST:
            jobinfo['status'] = 'createmedia'
            if not validateonly:
                loginfo('start', getJobfile(jobnumber), request)
                try:
                    retcode = subprocess.call([path.join(POSTBLOBPATH, 'postblob.sh'), INSTITUTION, getJobfile(jobnumber), BATCHPARAMETERS])
                    if retcode < 0:
                        loginfo('process', jobnumber + " Child was terminated by signal %s" % -retcode, request)
                    else:
                        loginfo('process', jobnumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', getJobfile(jobnumber), request)

        elif 'uploadmedia' in request.POST:
            jobinfo['status'] = 'uploadmedia'
        else:
            jobinfo['status'] = 'No status possible'

    return jobinfo, images
Ejemplo n.º 16
0
def upload(request):
    if request.method == "POST" and "Upload" in request.POST:
        form1 = UploadForm1(request.POST, request.FILES)
        form2 = UploadForm2(request.POST, request.FILES)
        form3 = UploadForm3(request.POST, request.FILES)
        form4 = UploadForm4(request.POST, request.FILES)
        form5 = UploadForm5(request.POST, request.FILES)

        p_uuid = uuid4().hex
        date = datetime.date.today().isoformat()
        dest = "/".join(["uploads", str(p_uuid)])

        if form1.is_valid():
            if form2.is_valid():

                project = ".".join(["project", "csv"])
                file1 = request.FILES["docfile1"]
                handle_uploaded_file(file1, dest, project)
                parse_project(dest, date, file1, p_uuid)
                print("Parsed project!")

                sample = ".".join(["sample", "csv"])
                file2 = request.FILES["docfile2"]
                handle_uploaded_file(file2, dest, sample)
                parse_sample(file2, p_uuid)
                print("Parsed sample!")

                taxonomy = ".".join(["mothur", "taxonomy"])
                file3 = request.FILES["docfile3"]
                handle_uploaded_file(file3, dest, taxonomy)
                parse_taxonomy(file3)
                print("Parsed taxonomy!")

                shared = ".".join(["mothur", "shared"])
                file4 = request.FILES["docfile4"]
                handle_uploaded_file(file4, dest, shared)
                parse_profile(dest, p_uuid)
                print("Parsed profile!")

                # taxaprofile(p_uuid)
                # print("Taxa profiles created")

            elif form3.is_valid():
                name = ".".join(["project", "csv"])
                file = request.FILES["docfile1"]
                handle_uploaded_file(file, dest, name)

                name = ".".join(["sample", "csv"])
                file = request.FILES["docfile2"]
                handle_uploaded_file(file, dest, name)

                name = ".".join(["biom_1.5", "txt"])
                file = request.FILES["docfile5"]
                handle_uploaded_file(file, dest, name)

            elif form4.is_valid():
                name = ".".join(["project", "csv"])
                file = request.FILES["docfile1"]
                handle_uploaded_file(file, dest, name)

                name = ".".join(["sample", "csv"])
                file = request.FILES["docfile2"]
                handle_uploaded_file(file, dest, name)

                name = ".".join(["biom_1.4", "txt"])
                file = request.FILES["docfile6"]
                handle_uploaded_file(file, dest, name)

            elif form5.is_valid():
                name = ".".join(["project", "csv"])
                file = request.FILES["docfile1"]
                handle_uploaded_file(file, dest, name)

                name = ".".join(["sample", "csv"])
                file = request.FILES["docfile2"]
                handle_uploaded_file(file, dest, name)

                name = ".".join(["biom_1.4", "txt"])
                file = request.FILES["docfile7"]
                handle_uploaded_file(file, dest, name)

            else:
                print("Please upload taxonomic profile data")

        else:
            print("Please upload meta files")

    elif request.method == "POST" and "clickMe" in request.POST:
        remove_list(request)

    projects = Project.objects.all().order_by("project_name")
    return render_to_response(
        "upload.html",
        {
            "projects": projects,
            "form1": UploadForm1,
            "form2": UploadForm2,
            "form3": UploadForm3,
            "form4": UploadForm4,
            "form5": UploadForm5,
        },
        context_instance=RequestContext(request),
    )
Ejemplo n.º 17
0
def uploadfiles(request):

    jobinfo = {}
    constants = {}
    images = []
    dropdowns = getDropdowns()
    elapsedtime = time.time()

    form = forms.Form(request)
    if request.POST:

        contributor = request.POST['contributor']
        overrideContributor = request.POST['overridecreator']

        creatorDisplayname = request.POST['creator']
        overrideCreator = request.POST['overridecreator']

        rightsholderDisplayname = request.POST['rightsholder']
        overrideRightsholder = request.POST['overriderightsholder']

        constants = {
            'creator': creatorDisplayname,
            'contributor': contributor,
            'rightsholder': rightsholderDisplayname
        }

        for lineno, afile in enumerate(request.FILES.getlist('imagefiles')):
            #print afile
            try:
                print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name',
                                                afile.name, 'size', afile.size)
                im = get_exif(afile)
                objectnumber = getNumber(afile.name)
                #objectCSID = getCSID(objectnumber)
                creator, creatorRefname = assignValue(creatorDisplayname,
                                                      overrideCreator, im,
                                                      'Artist',
                                                      dropdowns['creators'])
                contributor, dummy = assignValue(contributor,
                                                 overrideContributor, im,
                                                 'ImageDescription', {})
                rightsholder, rightsholderRefname = assignValue(
                    rightsholderDisplayname, overrideRightsholder, im,
                    'RightsHolder', dropdowns['rightsholders'])
                datetimedigitized, dummy = assignValue('', 'ifblank', im,
                                                       'DateTimeDigitized', {})
                imageinfo = {
                    'id': lineno,
                    'name': afile.name,
                    'size': afile.size,
                    'objectnumber': objectnumber,
                    #'objectCSID': objectCSID,
                    'date': datetimedigitized,
                    'creator': creatorRefname,
                    'contributor': contributor,
                    'rightsholder': rightsholderRefname,
                    'creatorDisplayname': creator,
                    'rightsholderDisplayname': rightsholder,
                    'contributorDisplayname': contributor
                }
                handle_uploaded_file(afile, imageinfo)
                images.append(imageinfo)
            except:
                #raise
                images.append({
                    'name':
                    afile.name,
                    'size':
                    afile.size,
                    'error':
                    'problem extracting image metadata, not processed'
                })

        if len(images) > 0:
            jobnumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
            jobinfo['jobnumber'] = jobnumber
            writeCsv(
                getJobfile(jobnumber) + '.step1.csv', images, [
                    'name', 'size', 'objectnumber', 'date', 'creator',
                    'contributor', 'rightsholder'
                ])
            jobinfo['estimatedtime'] = '%8.1f' % (len(images) * 10 / 60.0)

            if 'createmedia' in request.POST:
                jobinfo['status'] = 'createmedia'
                loginfo('start', getJobfile(jobnumber), request)
                try:
                    retcode = subprocess.call([
                        "/usr/local/share/django/pahma_project/uploadmedia/postblob.sh",
                        getJobfile(jobnumber)
                    ])
                    if retcode < 0:
                        loginfo(
                            'process', jobnumber +
                            " Child was terminated by signal %s" % -retcode,
                            request)
                    else:
                        loginfo('process',
                                jobnumber + ": Child returned %s" % retcode,
                                request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', getJobfile(jobnumber), request)

            elif 'uploadmedia' in request.POST:
                jobinfo['status'] = 'uploadmedia'
            else:
                jobinfo['status'] = 'No status possible'

    status = 'up'
    timestamp = time.strftime("%b %d %Y %H:%M:%S", time.localtime())
    elapsedtime = time.time() - elapsedtime

    return render(
        request, 'uploadmedia.html', {
            'title': TITLE,
            'images': images,
            'count': len(images),
            'constants': constants,
            'jobinfo': jobinfo,
            'dropdowns': dropdowns,
            'overrides': overrides,
            'status': status,
            'timestamp': timestamp,
            'elapsedtime': '%8.2f' % elapsedtime
        })
Ejemplo n.º 18
0
def prepareFiles(request, validateonly, dropdowns):
    jobinfo = {}
    images = []
    for lineno, afile in enumerate(request.FILES.getlist('imagefiles')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name,
                                            'size', afile.size)
            image = get_exif(afile)
            filename, objectnumber, imagenumber = getNumber(afile.name)
            # objectCSID = getCSID(objectnumber)
            im.creator, im.creatorRefname = assignValue(
                im.creatorDisplayname, im.overrideCreator, image, 'Artist',
                dropdowns['creators'])
            im.contributor, dummy = assignValue(im.contributor,
                                                im.overrideContributor, image,
                                                'ImageDescription', {})
            im.rightsholder, im.rightsholderRefname = assignValue(
                im.rightsholderDisplayname, im.overrideRightsholder, image,
                'RightsHolder', dropdowns['rightsholders'])
            datetimedigitized, dummy = assignValue('', 'ifblank', image,
                                                   'DateTimeDigitized', {})
            imageinfo = {
                'id': lineno,
                'name': afile.name,
                'size': afile.size,
                'objectnumber': objectnumber,
                'imagenumber': imagenumber,
                # 'objectCSID': objectCSID,
                'date': datetimedigitized,
                'creator': im.creatorRefname,
                'contributor': im.contributor,
                'rightsholder': im.rightsholderRefname,
                'creatorDisplayname': im.creator,
                'rightsholderDisplayname': im.rightsholder,
                'contributorDisplayname': im.contributor
            }
            if not validateonly:
                handle_uploaded_file(afile)
            images.append(imageinfo)
        except:
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            images.append({
                'name':
                afile.name,
                'size':
                afile.size,
                'error':
                'problem extracting image metadata, not processed'
            })

    if len(images) > 0:
        jobnumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        jobinfo['jobnumber'] = jobnumber

        if not validateonly:
            writeCsv(
                getJobfile(jobnumber) + '.step1.csv', images, [
                    'name', 'size', 'objectnumber', 'date', 'creator',
                    'contributor', 'rightsholder', 'imagenumber'
                ])
        jobinfo['estimatedtime'] = '%8.1f' % (len(images) * 10 / 60.0)

        if 'createmedia' in request.POST:
            jobinfo['status'] = 'createmedia'
            if not validateonly:
                loginfo('start', getJobfile(jobnumber), request)
                try:
                    retcode = subprocess.call([
                        path.join(POSTBLOBPATH, 'postblob.sh'),
                        getJobfile(jobnumber)
                    ])
                    if retcode < 0:
                        loginfo(
                            'process', jobnumber +
                            " Child was terminated by signal %s" % -retcode,
                            request)
                    else:
                        loginfo('process',
                                jobnumber + ": Child returned %s" % retcode,
                                request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', getJobfile(jobnumber), request)

        elif 'uploadmedia' in request.POST:
            jobinfo['status'] = 'uploadmedia'
        else:
            jobinfo['status'] = 'No status possible'

    return jobinfo, images
Ejemplo n.º 19
0
def prepareFiles(request, validateonly, dropdowns):
    jobinfo = {}
    images = []
    for lineno, afile in enumerate(request.FILES.getlist('imagefiles')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name, 'size', afile.size)
            image = get_exif(afile)
            filename, objectnumber, imagenumber = getNumber(afile.name)
            # objectCSID = getCSID(objectnumber)
            im.creator, im.creatorRefname = assignValue(im.creatorDisplayname, im.overrideCreator, image, 'Artist',
                                                        dropdowns['creators'])
            im.contributor, dummy = assignValue(im.contributor, im.overrideContributor, image, 'ImageDescription', {})
            im.rightsholder, im.rightsholderRefname = assignValue(im.rightsholderDisplayname, im.overrideRightsholder,
                                                                  image, 'RightsHolder', dropdowns['rightsholders'])
            datetimedigitized, dummy = assignValue('', 'ifblank', image, 'DateTimeDigitized', {})
            imageinfo = {'id': lineno, 'name': afile.name, 'size': afile.size,
                         'objectnumber': objectnumber,
                         'imagenumber': imagenumber,
                         # 'objectCSID': objectCSID,
                         'date': datetimedigitized,
                         'creator': im.creatorRefname,
                         'contributor': im.contributor,
                         'rightsholder': im.rightsholderRefname,
                         'creatorDisplayname': im.creator,
                         'rightsholderDisplayname': im.rightsholder,
                         'contributorDisplayname': im.contributor
            }
            if not validateonly:
                handle_uploaded_file(afile)
            images.append(imageinfo)
        except:
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            images.append({'name': afile.name, 'size': afile.size,
                           'error': 'problem extracting image metadata, not processed'})

    if len(images) > 0:
        jobnumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        jobinfo['jobnumber'] = jobnumber

        if not validateonly:
            writeCsv(getJobfile(jobnumber) + '.step1.csv', images,
                     ['name', 'size', 'objectnumber', 'date', 'creator', 'contributor', 'rightsholder', 'imagenumber'])
        jobinfo['estimatedtime'] = '%8.1f' % (len(images) * 10 / 60.0)

        if 'createmedia' in request.POST:
            jobinfo['status'] = 'createmedia'
            if not validateonly:
                loginfo('start', getJobfile(jobnumber), request)
                try:
                    retcode = subprocess.call([path.join(POSTBLOBPATH, 'postblob.sh'), getJobfile(jobnumber)])
                    if retcode < 0:
                        loginfo('process', jobnumber + " Child was terminated by signal %s" % -retcode, request)
                    else:
                        loginfo('process', jobnumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', getJobfile(jobnumber), request)

        elif 'uploadmedia' in request.POST:
            jobinfo['status'] = 'uploadmedia'
        else:
            jobinfo['status'] = 'No status possible'

    return jobinfo, images
Ejemplo n.º 20
0
def check_if_missing(request):
    matcher = utils.handle_uploaded_file(request)
    matcher.match()
    pass