Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
creator = Creator()
if role:
creator["roles"] = [role]
if rec_class == constants.REC_CLASS_EVENT:
event = Event()
event["title"] = formatted_name
creator["agent"] = event
elif rec_class == constants.REC_CLASS_ORGUNIT:
orgunit = Orgunit()
orgunit["name"] = formatted_name
creator["agent"] = orgunit
elif rec_class == constants.REC_CLASS_PERSON or rec_class == constants.REC_CLASS_FAMILY:
# class is "Person" or "Family"
name_given = ""
name_middle = ""
name_family = ""
name_prefix = ""
name_terms_of_address = ""
date_birth = ""
date_death = ""
parenthesis_index = formatted_name.rfind("(")
if parenthesis_index != -1:
#may be like: name (date_birth-date_death)
dates_part = formatted_name[parenthesis_index + 1:-1].strip()
date_birth = dates_part[:4]
date_death = dates_part[5:]
def convert_xmletree(xmletree_root, input_format, source, rec_id_prefix, only_first_record):
if xmletree_root is not None:
if input_format is None:
input_format = io_service.guess_format_from_xmletree(xmletree_root)
if input_format is not None:
logging.info("# input_format: {0}".format(input_format))
if input_format == constants.FORMAT_DDI:
# ddi
return ddi_crosswalk.ddi_xmletree_to_metajson_list(xmletree_root, source, rec_id_prefix, only_first_record)
elif input_format == constants.FORMAT_DIDL:
# didl
return didl_crosswalk.didl_xmletree_to_metajson_list(xmletree_root, source, rec_id_prefix, only_first_record)
elif input_format == constants.FORMAT_ENDNOTEXML:
# endnotexml
return endnotexml_crosswalk.endnotexml_xmletree_to_metajson_list(xmletree_root, source, rec_id_prefix, only_first_record)
elif input_format == constants.FORMAT_METS:
# mets
return mets_crosswalk.mets_xmletree_to_metajson_list(xmletree_root, source, rec_id_prefix, only_first_record)
elif input_format == constants.FORMAT_MODS:
# mods
return mods_crosswalk.mods_xmletree_to_metajson_list(xmletree_root, source, rec_id_prefix, only_first_record)
elif input_format == constants.FORMAT_OPENURL:
if input_format is not None:
logging.info("input_format: {0}".format(input_format))
if input_format == constants.FORMAT_METAJSON:
# metajson
if input_data["rec_class"] == constants.REC_CLASS_COLLECTION:
return input_data["records"]
else:
return [input_data]
elif input_format == constants.FORMAT_BIBJSON:
# bibjson
return bibjson_crosswalk.bibjson_to_metajson_list(input_data, source, rec_id_prefix, only_first_record)
elif input_format == constants.FORMAT_SUMMONJSON:
# summon
return summonjson_crosswalk.summonjson_to_metajson_list(input_data, source, rec_id_prefix, only_first_record)
else:
logging.error("Error: {} input_format not managed".format(input_format))
def __init__(self, *args, **kwargs):
Common.__init__(self, *args, **kwargs)
if "rec_metajson" not in self:
self["rec_metajson"] = constants.METAJSON_VERSION
if "rec_class" not in self:
self["rec_class"] = constants.REC_CLASS_WARPPER
def guess_type_from_format(input_format):
if input_format and input_format in constants.format_to_file_type:
return constants.format_to_file_type[input_format]
TYPE_BOOKLET = "booklet"
TYPE_CONFERENCE = "conference"
TYPE_ICOMM = "ICOMM"
TYPE_INBOOK = "inbook"
TYPE_INCOLLECTION = "incollection"
TYPE_INPROCEEDINGS = "inproceedings"
TYPE_MANUAL = "manual"
TYPE_MASTERSTHESIS = "mastersthesis"
TYPE_MISC = "misc"
TYPE_PHDTHESIS = "phdthesis"
TYPE_PROCEEDINGS = "proceedings"
TYPE_TECHREPORT = "techreport"
TYPE_UNPUBLISHED = "unpublished"
bibtex_document_type_to_metajson_document_type = {
TYPE_ARTICLE: constants.DOC_TYPE_JOURNALARTICLE,
TYPE_BOOK: constants.DOC_TYPE_BOOK,
TYPE_BOOKLET: constants.DOC_TYPE_BOOKLET,
TYPE_CONFERENCE: constants.DOC_TYPE_CONFERENCEPAPER,
TYPE_ICOMM: constants.DOC_TYPE_CONFERENCECONTRIBUTION,
TYPE_INBOOK: constants.DOC_TYPE_BOOKPART,
TYPE_INCOLLECTION: constants.DOC_TYPE_BOOKPART,
TYPE_INPROCEEDINGS: constants.DOC_TYPE_CONFERENCEPAPER,
TYPE_MANUAL: constants.DOC_TYPE_MANUEL,
TYPE_MASTERSTHESIS: constants.DOC_TYPE_MASTERTHESIS,
TYPE_MISC: constants.DOC_TYPE_UNPUBLISHEDDOCUMENT,
TYPE_PHDTHESIS: constants.DOC_TYPE_DOCTORALTHESIS,
TYPE_PROCEEDINGS: constants.DOC_TYPE_CONFERENCEPROCEEDINGS,
TYPE_TECHREPORT: constants.DOC_TYPE_TECHREPORT,
TYPE_UNPUBLISHED: constants.DOC_TYPE_UNPUBLISHEDDOCUMENT
}
def write_csv(item, output_file_path):
#logging.debug("write_csv type(item): {}".format(type(item)))
with open(output_file_path, "w") as output_file:
csvwriter = csv.DictWriter(output_file, delimiter=',', fieldnames=constants.csv_metajson_fieldnames)
csvwriter.writeheader()
for csv_document in item:
csvwriter.writerow(csv_document)
def __init__(self, *args, **kwargs):
Common.__init__(self, *args, **kwargs)
if "rec_class" not in self:
self["rec_class"] = constants.REC_CLASS_BRAND
if isinstance(document, dict):
document = load_dict(document)
# rec_id
if "rec_id" not in document or document["rec_id"] is None:
document["rec_id"] = str(uuid.uuid1())
# language
# todo use language_service
# title_non_sort
manage_title_non_sort(document)
# rec_status
if "rec_status" not in document or document["rec_status"] is None:
document["rec_status"] = constants.REC_STATUS_PRIVATE
# rec_created_date
if "rec_created_date" not in document or document["rec_created_date"] is None:
document["rec_created_date"] = datetime.now().isoformat()
# rec_modified_date
if "rec_modified_date" not in document or document["rec_modified_date"] is None:
document["rec_modified_date"] = datetime.now().isoformat()
# rec_deleted_date
if document["rec_status"] == constants.REC_STATUS_DELETED and "rec_deleted_date" not in metajson:
document["rec_deleted_date"] = datetime.now().isoformat()
# For "rec_class": "Document" only
if "rec_class" in document and document["rec_class"] == constants.REC_CLASS_DOCUMENT:
# citations
def write_item(item, output_file_path, output_format):
#logging.debug("write_item type(item): {}, output_file_path:{}, output_format:{}".format(type(item), output_file_path, output_format))
output_type = guess_type_from_format(output_format)
if output_type is None:
logging.error("Error: output_type is None")
else:
if output_type == constants.FILE_TYPE_JSON:
write_json(item[1], output_file_path)
elif output_type == constants.FILE_TYPE_TXT:
write_txt(item[1], output_file_path)
elif output_type == constants.FILE_TYPE_XMLETREE:
write_xml(item[1], output_file_path)
elif output_type == constants.FILE_TYPE_BIBTEX:
write_bibtex(item[1], output_file_path)
elif output_type == constants.FILE_TYPE_CSV:
write_csv(item[1], output_file_path)
else:
logging.error("Error: output_type is not managed: {}".format(output_type))