Skip to content

Commit

Permalink
write MDO record to output dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsgalore committed Aug 14, 2018
1 parent 412fb56 commit 8705d49
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
11 changes: 11 additions & 0 deletions iromlab/cdworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from . import isobuster
from . import dbpoweramp
from . import verifyaudio
from . import mdo


def mediumLoaded(driveName):
Expand Down Expand Up @@ -107,6 +108,7 @@ def processDisc(carrierData):
"""Process one disc / job"""

jobID = carrierData['jobID']
PPN = carrierData['PPN']

logging.info(''.join(['### Job identifier: ', jobID]))
logging.info(''.join(['PPN: ', carrierData['PPN']]))
Expand Down Expand Up @@ -292,6 +294,15 @@ def processDisc(carrierData):
logging.info(''.join(['isolyzerSuccess: ', str(isolyzerSuccess)]))
logging.info(''.join(['imageTruncated: ', str(imageTruncated)]))

# Fetch metadata from KBMDO and store as file
logging.info('*** Writing metadata from KB-MDO to file ***')
wroteMDORecord = mdo.writeMDORecord(PPN, dirOut)

if not wroteMDORecord:
success = False
reject = True
logging.error("Could not write metadata from KB-MDO")

# Generate checksum file
logging.info('*** Computing checksums ***')
successChecksum = checksumDirectory(dirOut)
Expand Down
50 changes: 50 additions & 0 deletions iromlab/mdo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#! /usr/bin/env python
"""
Quick and dirty module for writing entire MDO record for a PPN to file
using SRU query. Code based on kbapi.sru.py
"""

import os
import io
import requests
import urllib

def writeMDORecord(PPN, writeDirectory):
"""Write MDO record for a PPN to file"""

fileOut = os.path.join(writeDirectory, "meta-kbmdo.xml")
sruSearchString = '"PPN=' + PPN + '"'

SRU_BASEURL = 'http://jsru.kb.nl/sru/sru'
SRU_BASEURL += '?version=1.2&maximumRecords=%i'
SRU_BASEURL += '&operation=searchRetrieve'
SRU_BASEURL += '&startRecord=%i'
SRU_BASEURL += '&recordSchema=%s'
SRU_BASEURL += '&x-collection=%s&query=%s'

maximumrecords = 1
startrecord = 1
recordschema = 'dcx'
collection = 'GGC'

query = urllib.parse.quote_plus(sruSearchString)

url = SRU_BASEURL % (maximumrecords, startrecord,
recordschema, collection, query)
r = requests.get(url)

if r.status_code != 200:
# Status code: must be 200, otherwise an error occurred
wroteMDORecord = False
else:
record_data = r.content.decode("utf-8")

try:
with io.open(fileOut, "w", encoding="utf-8") as fOut:
fOut.write(str(record_data))
fOut.close()
wroteMDORecord = True
except IOError:
wroteMDORecord = False

return wroteMDORecord

0 comments on commit 8705d49

Please sign in to comment.