Esempio n. 1
0
def showresults(request):
    elapsedtime = 0.0
    context = setConstants(request, im)
    try:
        status = request.GET['status']
    except:
        status = 'showfile'
    filename = request.GET['filename']
    context['filename'] = filename
    context['jobstatus'] = request.GET['status']
    f = open(getJobfile(filename), "rb")
    filecontent = f.read()
    if status == 'showmedia':
        context['derivativegrid'] = 'Medium'
        context['sizegrid'] = '240px'
        context['imageserver'] = prmz.IMAGESERVER
        context['items'] = rendermedia(filecontent)
    elif status == 'showinportal':
        pass
    else:
        context['filecontent'] = reformat(filecontent)
    elapsedtime = time.time() - elapsedtime
    context = setContext(context, elapsedtime)

    return render(request, 'uploadmedia.html', context)
Esempio n. 2
0
def deletejob(request, filename):
    try:
        remove(getJobfile(filename))
        logger.info('%s :: %s' % ('uploadmedia job deleted', filename))

    except:
        logger.info('%s :: %s' % ('uploadmedia tried and failed to delete job', filename))
    return showqueue(request)
Esempio n. 3
0
def checkimagefilenames(request):
    elapsedtime = time.time()
    context = setConstants(request, im)
    try:
        filename = request.GET['filename']
        (jobnumber, step, csv ) = filename.split('.')
        context['jobnumber'] = jobnumber
        context['filename'] = filename
        file_handle = open(getJobfile(filename), "rb")
        lines = file_handle.read().splitlines()
        recordtypes = [f.split("|") for f in lines]
        filenames = [ r[0] for r in recordtypes[1:]]
        objectnumbers = []
        seen = {}
        for o in filenames:
            objitems = getNumber(o, INSTITUTION)
            if objitems[1] in seen:
                objectnumbers.append(objitems + (seen[objitems[1]],))
            else:
                asquery = '%s?as=%s_common:%s%%3D%%27%s%%27&wf_deleted=false&pgSz=%s' % ('collectionobjects', 'collectionobjects', 'objectNumber', objitems[1], 10)
                (objecturl, objectx, dummy, itemtime) = getfromCSpace(asquery, request)
                if objectx is None:
                    totalItems = 0
                else:
                    objectx = fromstring(objectx)
                    totalItems = objectx.find('.//totalItems')
                    totalItems = int(totalItems.text)
                #objectcsids = [e.text for e in objectx.findall('.//csid')]
                objectnumbers.append(objitems + (totalItems,))
                seen[objitems[1]] = totalItems
        file_handle.close()
    except:
        raise
        objectnumbers = []
    elapsedtime = time.time() - elapsedtime
    context = setContext(context, elapsedtime)
    context['objectnumbers'] = objectnumbers

    return render(request, 'uploadmedia.html', context)
Esempio n. 4
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})
Esempio n. 5
0
def showresults(request, filename):
    f = open(getJobfile(filename), "rb")
    response = HttpResponse(FileWrapper(f), content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response
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
Esempio n. 7
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
Esempio n. 8
0
def showresults(request, filename):
    f = open(getJobfile(filename), "rb")
    response = HttpResponse(FileWrapper(f), content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response
Esempio n. 9
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
        })
Esempio n. 10
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
Esempio n. 11
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