| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## |
|---|
| 4 | ## This file is part of CDS Indico. |
|---|
| 5 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 6 | ## |
|---|
| 7 | ## CDS Indico is free software; you can redistribute it and/or |
|---|
| 8 | ## modify it under the terms of the GNU General Public License as |
|---|
| 9 | ## published by the Free Software Foundation; either version 2 of the |
|---|
| 10 | ## License, or (at your option) any later version. |
|---|
| 11 | ## |
|---|
| 12 | ## CDS Indico is distributed in the hope that it will be useful, but |
|---|
| 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 | ## General Public License for more details. |
|---|
| 16 | ## |
|---|
| 17 | ## You should have received a copy of the GNU General Public License |
|---|
| 18 | ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., |
|---|
| 19 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 20 | |
|---|
| 21 | """ |
|---|
| 22 | Metadata generation |
|---|
| 23 | |
|---|
| 24 | This module is UNFINISHED |
|---|
| 25 | |
|---|
| 26 | """ |
|---|
| 27 | |
|---|
| 28 | # system libs |
|---|
| 29 | from pymarc import Record, Field, marcxml |
|---|
| 30 | |
|---|
| 31 | # plugin imports |
|---|
| 32 | from indico.ext.livesync.metadata import MetadataWrapper, MetadataGenerator |
|---|
| 33 | |
|---|
| 34 | # legacy import |
|---|
| 35 | from MaKaC import conference |
|---|
| 36 | from MaKaC.fossils.conference import IConferenceFossil |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | ### These classes should be used instead of the current MARCXML generator |
|---|
| 40 | |
|---|
| 41 | class IMARCFossil(IConferenceFossil): |
|---|
| 42 | # TODO: finish this |
|---|
| 43 | pass |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | class _future_MARCGenerator(MetadataGenerator): |
|---|
| 47 | |
|---|
| 48 | _fossilMappings = { |
|---|
| 49 | conference.Conference: [ |
|---|
| 50 | ('245', ('',''), {'a': 'title'}), |
|---|
| 51 | ('111', ('',''), {'a': 'title', |
|---|
| 52 | 'c': 'location', |
|---|
| 53 | '9': 'xmlStartDate', |
|---|
| 54 | 'Z': 'xmlEndDate'}) |
|---|
| 55 | # ... |
|---|
| 56 | # TODO: finish this |
|---|
| 57 | ] |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | def _generateFields(self, object): |
|---|
| 61 | fossil = object.fossilize(IMARCFossil) |
|---|
| 62 | for field in self._fossilMappings[object.__class__]: |
|---|
| 63 | pass |
|---|
| 64 | # generate |
|---|
| 65 | |
|---|
| 66 | def generate(self, object): |
|---|
| 67 | |
|---|
| 68 | metadata = self._generateFields(object) |
|---|
| 69 | |
|---|
| 70 | # Empty MARC record |
|---|
| 71 | record = Record() |
|---|
| 72 | |
|---|
| 73 | for tag, indicators, subfields in metadata: |
|---|
| 74 | record.add_field(tag = tag, indicators = indicators, subfields = subfields) |
|---|
| 75 | |
|---|
| 76 | return self._serialize(record) |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | class _future_MARC21Generator(_future_MARCGenerator): |
|---|
| 80 | |
|---|
| 81 | def _serialize(self, record): |
|---|
| 82 | return record.as_marc() |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | class _future_MARCXMLGenerator(_future_MARCGenerator): |
|---|
| 86 | |
|---|
| 87 | def _serialize(self, record): |
|---|
| 88 | return marcxml.record_to_xml(record) |
|---|
| 89 | |
|---|
| 90 | ### |
|---|