示例#1
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})
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
示例#3
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
示例#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
        })
示例#5
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
示例#6
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