#!/usr/bin/env python
+# -*- coding: utf-8 -*-
"""
Prepare sets of electronic resource MARC records for loading into Evergreen
"code": "OSBO", \
"ebrary_code": "boreal", \
"proxy": "http://ra.ocls.ca/ra/login.aspx?url=", \
- "link_text": "Disponible en ligne" \
+ "link_text": "Disponible en ligne", \
+ "access_note": "Accès réservé aux utilisateurs avec un ID valide Collège Boréal ;" \
}
self.laurentian = { \
-A / --algoma: Add an 856 for Algoma University
+ -B / --boreal: Add an 856 for College Boreal
+
-L / --laurentian: Add an 856 for Laurentian University
-W / --windsor : Add an 856 for University of Windsor
def consolidate_options(opts):
"""Make long arguments the standard form in command line options"""
+ _shortlong = {
+ '-i': '--input',
+ '-o': '--output',
+ '-a': '--authorization',
+ '-c': '--consortium',
+ '-e': '--ebrary',
+ '-p': '--publisher',
+ '-P': '--platform',
+ '-n': '--note',
+ '-A': '--algoma',
+ '-B': '--boreal',
+ '-L': '--laurentian',
+ '-W': '--windsor',
+ '-s': '--sample',
+ '-h': '--help'
+ }
+
_options = dict(opts)
for key, val in opts:
- if key == '-i':
- _options['--input'] = val
- elif key == '-o':
- _options['--output'] = val
- elif key == '-a':
- _options['--authorization'] = val
- elif key == '-c':
- _options['--consortium'] = val
- elif key == '-e':
- _options['--ebrary'] = val
- elif key == '-p':
- _options['--publisher'] = val
- elif key == '-P':
- _options['--platform'] = val
- elif key == '-n':
- _options['--note'] = val
- elif key == '-A':
- _options['--algoma'] = val
- elif key == '-L':
- _options['--laurentian'] = val
- elif key == '-W':
- _options['--windsor'] = val
- elif key == '-s':
- _options['--sample'] = val
- elif key == '-h':
- _options['--help'] = val
+ if key in _shortlong:
+ _options[_shortlong[key]] = val
return _options
"""Check the validity of options that were passed in"""
_help = False
+ _req = {
+ '--input': "* Missing -i / --input argument!",
+ '--output': "* Missing -o / --output argument!",
+ '--consortium': "* Missing -c / --consortium argument!",
+ '--authorization': "* Missing -a / --authorization argument!",
+ '--publisher': "* Missing -p / --publisher argument!"
+ }
if '--help' in options:
do_help()
- if '--input' not in options:
- print "* Missing -i / --input argument!"
- _help = True
-
- if '--output' not in options:
- print "* Missing -o / --output argument!"
- _help = True
-
- if '--consortium' not in options:
- print "* Missing -c / --consortium argument!"
- _help = True
-
- if '--authorization' not in options:
- print "* Missing -a / --authorization argument!"
- _help = True
-
- if '--publisher' not in options:
- print "* Missing -p / --publisher argument!"
- _help = True
+ for reqkey, reqwarn in _req.iteritems():
+ if reqkey not in options:
+ print reqwarn
+ _help = True
_libraries = check_libraries(options)
if len(_libraries.keys()) == 0:
"""Build a dict of the libraries that were requested for this batch"""
_libraries = dict()
- if '--algoma' in options:
- _libraries['algoma'] = True
-
- if '--laurentian' in options:
- _libraries['laurentian'] = True
-
- if '--windsor' in options:
- _libraries['windsor'] = True
+ for lib in ['algoma', 'boreal', 'laurentian', 'windsor']:
+ if '--' + lib in options:
+ _libraries[lib] = True
return _libraries
def parse_opts():
"""Get command-line arguments from the script"""
try:
- _short_opts = 'i:o:a:c:p:ALWen:P:s:h'
+ _short_opts = 'i:o:a:c:p:ABLWen:P:s:h'
_long_opts = ['input=', 'output=', 'authorization=', 'consortium=',
- 'publisher=', 'algoma', 'laurentian', 'windsor', 'ebrary',
+ 'publisher=', 'algoma', 'boreal', 'laurentian', 'windsor', 'ebrary',
'note=', 'platform=', 'sample=', 'help'
]
opts = getopt.getopt(sys.argv[1:], _short_opts, _long_opts)
global RECORD_COUNT
sample = ''
- reader = pymarc.MARCReader(
- open(options['input'], mode='rb'), to_unicode=True
- )
- writer = pymarc.MARCWriter(open(options['output'], mode='wb'))
+
+ try:
+ reader = pymarc.MARCReader(
+ open(options['input'], mode='rb'), to_unicode=True
+ )
+ except Exception, ex:
+ print("Could not open input file [%s]" % options['input'])
+
+ try:
+ writer = pymarc.MARCWriter(open(options['output'], mode='wb'))
+ except Exception, ex:
+ print("Could not open output file [%s]" % options['output'])
+
if ('sample' in options):
sample = pymarc.MARCWriter(open(options['sample'], mode='wb'))
if ebrary:
ebrary_url = re.search(r'^(.+?/lib/).+?(/.+?)$', url)
url = ebrary_url.group(1) + data['ebrary_code'] + ebrary_url.group(2)
+
+ # Only Boreal still wants proxied ebrary links
+ if ebrary and data['ebrary_code'] != 'boreal':
subs.extend(['u', url])
else:
subs.extend(['u', data['proxy'] + field['u']])