Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pubfields.append(('c', remove_html_markup(form['publication_date'])))
if pubfields:
record_add_field(rec, '260', subfields=pubfields)
record_add_field(rec, '856', ind1='0', subfields=[('f', email)])
if 'open_access' in form:
record_add_field(rec, '542', subfields=[('l', 'open')])
else:
record_add_field(rec, '542', subfields=[('l', 'restricted')])
if form['licence']:
record_add_field(rec, '540', subfields=[('a', remove_html_markup(form['licence']))])
record_add_field(rec, '520', subfields=[('a', remove_html_markup(form['description']))])
if form['contact_email']:
record_add_field(rec,'270',subfields=[('m', remove_html_markup(form['contact_email']))])
if form['keywords']:
for kw in form['keywords'].split(','):
if kw and not kw.isspace():
record_add_field(rec, '653',
ind1='1',
subfields=[('a', remove_html_markup(kw.strip()))])
if 'contributors' in form and form['contributors']:
fields = form.getlist('contributors')
for f in fields:
if f and not f.isspace():
record_add_field(rec, '700', subfields=[('a', remove_html_markup(f.strip()))])
record_add_field(rec, '546', subfields=[('a', remove_html_markup(form['language']))])
if key == 'a':
field[0][idx] = ('a', punctuate_authorname(value))
# 773 is cited by, DOI of the extended paper
# match the INSPIRE record ID of that paper and add it in 786__w
for field in record_get_field_instances(rec, '773'):
subs = field_get_subfields(field)
if 'i' in subs and 'isSupplementTo' in subs['i']:
if 'n' in subs and "doi" in [s.lower() for s in subs['n']]:
paper_recid = perform_request_search(
p="0247_a:%s" % subs['a'][0],
of="id"
)
if paper_recid:
record_add_field(rec,
"786",
subfields=[('w', str(paper_recid[0]))])
if 'n' in subs and "arxiv" in [s.lower() for s in subs['n']]:
paper_recid = perform_request_search(
p="037__a:%s" % subs['a'][0],
of="id"
)
if paper_recid:
record_add_field(rec,
"786",
subfields=[('w', str(paper_recid[0]))])
# Other mandatory fields
# 786 formatting
record_add_field(rec, "786", subfields=[('q', '0')])
def hepdata2marcxml(record):
out = {}
record_add_field(out, '024', '7', subfields=[('a', record['doi']), ('2', 'DOI')])
if record.get('title'):
title = 'Data from {title} from: {paper_title}'
else:
title = 'Additional data from: {paper_title}'
record_add_field(out, '245', subfields=[('a', title.format(title=record.get('title'), paper_title=record['paper_title'])), ('9', 'HEPDATA')])
record_add_field(out, '336', subfields=[('t', 'DATASET')])
record_add_field(out, '520', subfields=[('h', record['abstract']), ('9', 'HEPDATA')])
for keyword in record['keywords']:
name = keyword['name']
value = keyword['value']
if name in ('observables', 'cmenergies'):
value = '%s: %s' % (name, value)
record_add_field(out, '695', subfields=[('a', value), ('9', 'HEPDATA')])
for collaboration in record['collaborations']:
record_add_field(out, '710', subfields=[('g', collaboration)])
record_add_field(out, '786', subfields=[('q', str(record['position'])), ('w', str(record['inspire_id']))])
record_add_field(out, '980', subfields=[('a', 'DATA')])
return record_xml_output(out)
fft_status = "firerole: %s" % "\n".join(fft_status)
for file_path, real_name in files:
record_add_field(rec, 'FFT', subfields=[
('a', file_path),
#('d', 'some description') # TODO
#('t', 'Type'), # TODO
('m', real_name),
('r', fft_status),
])
# License
if r['license'] == 'CC BY-NC-SA':
record_add_field(rec, '540', subfields=[
('a', 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported'),
('u', 'http://creativecommons.org/licenses/by-nc-sa/3.0/'),
])
record_add_field(rec, '650', ind1="1", ind2="7", subfields=[
('a', 'cc-nc'),
('2', 'opendefinition.org'),
])
# DOI
if r['doi']:
record_add_field(rec, '024', '7', subfields=[('a', r['doi']), ('2', 'DOI')])
# Publication date
record_add_field(rec, '260', subfields=[('c', r['publication_date'])])
# Title
record_add_field(rec, '245', subfields=[('a', r['title'])])
# Creators
creators = r['authors']
for (i, name) in enumerate(creators):
if i == 0:
field_no = '100'
email = get_email(self.uid)
name = user_info.get(
"external_fullname", user_info.get("nickname", "")).strip()
if isinstance(email, unicode):
email = email.encode('utf8')
if isinstance(name, unicode):
name = name.encode('utf8')
record_add_field(
rec, '856', ind1='0', subfields=[('f', email), ('y', wash_for_xml(name))])
# =================
# Access right
# =================
# Access rights (open, closed, embargoed, restricted date
access_right = self._metadata['access_right']
record_add_field(rec, '542', subfields=[('l', access_right)])
# Embargo date
if access_right == 'embargoed':
record_add_field(rec, '942', subfields=[
('a', self._metadata['embargo_date'])
])
# =================
# Type of file(s)
# =================
# Upload type - 980__a: type, b: subtype
main_coll, sub_coll = self.get_collection_name()
subfields = [('a', main_coll), ]
if sub_coll:
subfields.append(('b', sub_coll))
record_add_field(rec, '980', subfields=subfields)
insert_mode_p = True
# Insert the record into the bibrec databases to have a recordId
rec_id = create_new_record(pretend=pretend)
write_message(" -Creation of a new record id (%d): DONE" % rec_id, verbose=2)
# we add the record Id control field to the record
error = record_add_field(record, '001', controlfield_value=rec_id)
if error is None:
msg = " Failed: Error during adding the 001 controlfield " \
"to the record"
write_message(msg, verbose=1, stream=sys.stderr)
return (1, int(rec_id), msg)
else:
error = None
error = record_add_field(record, '005', controlfield_value=now.strftime("%Y%m%d%H%M%S.0"))
if error is None:
write_message(" Failed: Error during adding to 005 controlfield to record",verbose=1,stream=sys.stderr)
return (1, int(rec_id))
else:
error=None
elif opt_mode != 'insert' and opt_mode != 'format' and \
opt_stage_to_start_from != 5:
insert_mode_p = False
# Update Mode
# Retrieve the old record to update
rec_old = get_record(rec_id)
record_had_altered_bit = record_get_field_values(rec_old, CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[:3], CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3], CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4], CFG_OAI_PROVENANCE_ALTERED_SUBFIELD)
# Also save a copy to restore previous situation in case of errors
original_record = get_record(rec_id)
if 'contributors' in form and form['contributors']:
fields = form.getlist('contributors')
for f in fields:
if f and not f.isspace():
record_add_field(rec, '700', subfields=[('a', remove_html_markup(f.strip()))])
record_add_field(rec, '546', subfields=[('a', remove_html_markup(form['language']))])
# copying zenodo here, but I don't think 980 is the right MARC field
if 'resource_type' in form and form['resource_type']:
fields = form.getlist('resource_type')
for f in fields:
record_add_field(rec, '980', subfields=[('a', remove_html_markup(form['resource_type']))])
if 'alternate_identifier' in form and form['alternate_identifier']:
record_add_field(rec, '024',
subfields=[('a', remove_html_markup(form['alternate_identifier']))])
if 'version' in form and form['version']:
record_add_field(rec, '250', subfields=[('a', remove_html_markup(form['version']))])
record_add_field(rec, '264',
subfields=[('b', CFG_SITE_NAME),
('c', str(datetime.utcnow()) + " UTC")])
except Exception as e:
current_app.logger.error(e)
raise
newval = ''
if val[0] == 'OPEN':
newval = 'open'
elif val[0] == 'RESTRICTED':
newval = 'restricted'
elif val[0] == 'openAccess':
newval = 'open'
elif val[0] == 'closedAccess':
newval = 'closed'
elif val[0] == 'embargoedAccess':
newval = 'embargoed'
elif val[0] == 'restrictedAccess':
newval = 'restricted'
elif val[0] == 'cc0':
newval = 'open'
record_add_field(rec, '540', subfields=[('a', 'Creative Commons CCZero'), ('u', 'http://www.opendefinition.org/licenses/cc-zero')])
record_add_field(rec, '650', ind1="1", ind2="7", subfields=[
('a', 'cc-zero'),
('2', 'opendefinition.org'),
])
if newval:
record_add_field(rec, '542', subfields=[('l', newval)])
return (rec, newval)
else:
return (rec, val[0])
return (rec, "closed")
record_delete_field(rec, '037', field_position_global=field[4])
for field in record_get_field_instances(rec, '242'):
record_add_field(rec, '246', subfields=field[0])
record_delete_fields(rec, '242')
# 269 Date normalization
for field in record_get_field_instances(rec, '269'):
for idx, (key, value) in enumerate(field[0]):
if key == "c":
field[0][idx] = ("c", convert_date_to_iso(value))
record_delete_fields(rec, "260")
if not 'THESIS' in collections:
for field in record_get_field_instances(rec, '260'):
record_add_field(rec, '269', subfields=field[0])
record_delete_fields(rec, '260')
# 300 page number
for field in record_get_field_instances(rec, '300'):
for idx, (key, value) in enumerate(field[0]):
if key == 'a':
if "mult." not in value and value != " p":
field[0][idx] = ('a', re.sub(r'[^\d-]+', '', value))
else:
record_delete_field(rec, '300',
field_position_global=field[4])
break
# 100 & 700 punctuate author names
author_names = record_get_field_instances(rec, '100')
author_names.extend(record_get_field_instances(rec, '700'))