From 3524dea6cdb23c4b7e60f4311cd0af5c2fbe972f Mon Sep 17 00:00:00 2001 From: Aleksander Vines Date: Mon, 8 Aug 2016 15:47:00 +0200 Subject: [PATCH] Revert "Added simple DIF support - for dif 9.8.4" This reverts commit 8d177f5660da7701e457911abd2d34842ac10c5e. --- moai/dif_v9.8.4.xsd | 490 ------------------------------------------- moai/metadata/dif.py | 55 ----- moai/xml.py | 58 ----- settings.ini | 47 ++--- setup.py | 6 +- 5 files changed, 22 insertions(+), 634 deletions(-) delete mode 100644 moai/dif_v9.8.4.xsd delete mode 100644 moai/metadata/dif.py delete mode 100644 moai/xml.py diff --git a/moai/dif_v9.8.4.xsd b/moai/dif_v9.8.4.xsd deleted file mode 100644 index d1730b8..0000000 --- a/moai/dif_v9.8.4.xsd +++ /dev/null @@ -1,490 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/moai/metadata/dif.py b/moai/metadata/dif.py deleted file mode 100644 index 22a5ae5..0000000 --- a/moai/metadata/dif.py +++ /dev/null @@ -1,55 +0,0 @@ -import re -import uuid -import sys - -from lxml.builder import ElementMaker - -XSI_NS = 'http://www.w3.org/2001/XMLSchema-instance' - -class DIF(object): - """This is the GCMD DIF format - - It is registered as prefix 'dif'.' - """ - - def __init__(self, prefix, config, db): - self.prefix = prefix - self.config = config - self.db = db - - self.ns = { - None : 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/' - } - - # TODO: Mofidy this hard coded schema - # to follow whatever the input schema say - # BUT: make sure it is some DIF version - self.schemas = { - None: 'http://gcmd.nasa.gov/Aboutus/xml/dif/dif_v9.8.4.xsd' - } - - def get_namespace(self): - return self.ns[self.prefix] - - def get_schema_location(self): - return self.schemas[self.prefix] - - def __call__(self, element, metadata): - data = metadata.record - DIF = ElementMaker(namespace=self.ns[None], nsmap=self.ns) - dif = DIF.dif() - create_xml(data['metadata']['dif'], dif, DIF) - dif.attrib['{%s}schemaLocation' % XSI_NS] = '%s %s' % ( - self.ns[None], - self.schemas[None]) - element.append(dif) - - -def create_xml(inElement, root, em): - for tag, val in inElement: - if isinstance(val, list): - element = [] - create_xml(val, element, em) - root.append(em(tag, *element)) - else: - root.append(em(tag, val)) \ No newline at end of file diff --git a/moai/xml.py b/moai/xml.py deleted file mode 100644 index 08d4803..0000000 --- a/moai/xml.py +++ /dev/null @@ -1,58 +0,0 @@ -from lxml import etree -import os - -from moai.utils import XPath - -class XMLContent(object): - def __init__(self, provider): - self.provider = provider - self.id = None - self.modified = None - self.deleted = False - self.sets = {u'normap': {u'name':u'normap', - u'description':u'NORMAP data'}} - self.metadata = None - - def update(self, path): - ## We validate that the input file follows dif 9.8.4 - # TODO: validate that it follows whatever schema its said to follow - doc = etree.parse(path, parser=get_parser()) - xpath = XPath(doc, nsmap={'x':'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'}) - self.root = doc.getroot() - - id = xpath.string('//x:Entry_ID') - self.id = id - self.modified = xpath.date('//x:Last_DIF_Revision_Date') - self.metadata = {} - self.metadata['dif'] = extract_node(self.root) - - -def extract_node(node): - element = [] - if (len(node.getchildren()) == 0): - if node.text: - val = (node.tag.split("}")[1], node.text) - element.append(val) - else: - for node2 in node: - tag = node2.tag.split("}")[1] - val = None - if (len(node2.getchildren()) == 0): - if node2.text: - val = node2.text - else: - val = extract_node(node2) - if (val): - val = (tag, val) - element.append(val) - return element - - -def get_parser(): - xsdPath = os.path.dirname(os.path.abspath(__file__)) + '/dif_v9.8.4.xsd' - with open(xsdPath, "r") as myfile: - schemaString = myfile.read() - schema_root = etree.XML(schemaString) - schema = etree.XMLSchema(schema_root) - parser = etree.XMLParser(schema=schema) - return parser \ No newline at end of file diff --git a/settings.ini b/settings.ini index 590637a..b6c260f 100644 --- a/settings.ini +++ b/settings.ini @@ -1,27 +1,20 @@ -[composite:main] -use = egg:Paste#urlmap -/oai = moai_nersc - -[app:moai_example] -use = egg:moai -name = MOAI Example Feed -url = http://localhost:8080/oai -admin_email = webmaster@localhost -formats = oai_dc mods dif -disallow_sets = private -database = sqlite:////opt/data/moai-example.db -provider = file:///vagrant/shared/pyoai/metadata/*.xml -content = moai_example -forcedflush = 10000 - -[app:moai_nersc] -use = egg:moai -name = MOAI Example Feed -url = http://moai.test.ad.nersc.no/oai -admin_email = webmaster@localhost -formats = dif -disallow_sets = private -database = sqlite:////opt/data/moai-nersc.db -provider = file:///vagrant/shared/pyoai/metadata/*.xml -content = moai_dif -forcedflush = 10000 \ No newline at end of file +[composite:main] +use = egg:Paste#urlmap +/oai = moai_example + +[app:moai_example] +use = egg:moai +name = MOAI Example Feed +url = http://localhost:8080/oai +admin_email = webmaster@localhost +formats = oai_dc mods +disallow_sets = private +database = sqlite:///moai-example.db +provider = file://moai/example-*.xml +content = moai_example +forcedflush = 10000 + +[server:main] +use = egg:PasteScript#wsgiutils +host = 127.0.0.1 +port = 8080 diff --git a/setup.py b/setup.py index c2e1774..37c432c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='MOAI', - version='2.0.1-nersc', + version='2.0.0', author='Infrae', author_email='info@infrae.com', url='http://infrae.com/products/moai', @@ -30,8 +30,7 @@ 'main=moai.wsgi:app_factory' ], 'moai.content':[ - 'moai_example=moai.example:ExampleContent', - 'moai_dif=moai.xml:XMLContent' + 'moai_example=moai.example:ExampleContent' ], 'moai.database':[ 'sqlite=moai.database:SQLDatabase', @@ -48,7 +47,6 @@ 'oai_dc=moai.metadata.oaidc:OAIDC', 'mods=moai.metadata.mods:MODS', 'nl_mods=moai.metadata.mods:NL_MODS', - 'dif=moai.metadata.dif:DIF', 'didl=moai.metadata.didl:DIDL', 'nl_didl=moai.metadata.dare_didl:DareDIDL' ],