Commits

jas...@882ca7fe-3cf8-0310-95c5-f9aabef819dd  committed 45a9bbd

added simple dc profile, preparing for release

  • Participants
  • Parent commits 5e6422b
  • Tags MOAI-1.0.3

Comments (0)

Files changed (11)

 MOAI changes
 ============
 
+MOAI 1.0.3 (2009-06-23)
+
+Bugs Fixed
+~~~~~~~~~~
+- Bug in ListMetadataFormats when using nl_didl prefix
+- Added simple dc example profile
+
 MOAI 1.0.2 (2009-05-20)
 -----------------------
 

File buildout.cfg

 
 [moai]
 configuration_profile = example_configuration
+#configuration_profile = simple_dc_configuration
 extension_modules = moai.extensions
                     moai.examples
+                    moai.examples.simple
 
 [example_configuration]
 path = ${buildout:directory}/src/moai/examples/example_data
+host = localhost
+port = 8080
+
+[simple_dc_configuration]
+path = ${buildout:directory}/src/moai/examples/simple/data
+host = localhost
 port = 8080
 
 [example_plugin]
 
 setup(
     name='MOAI',
-    version='1.0.2',
+    version='1.0.3',
     author='Infrae',
     author_email='jasper@infrae.com',
     description="MOAI, A Open Access Server Platform for Institutional Repositories",

File src/moai/examples/example_content.py

             u'description': [
             self.xpath('ex:abstract/text()', 'abstract', unicode)],
             u'title': [self.label],
-            u'date': self.xpath('ex:issued/text()', 'subject', datetime, multi=True),
-            u'subject': self.xpath('ex:keyword/text()', 'subject', unicode, multi=True),
+            u'date': self.xpath('ex:issued/text()',
+                                'subject', datetime, multi=True),
+            u'subject': self.xpath('ex:keyword/text()',
+                                   'subject', unicode, multi=True),
             u'identifier': ['http://purl.example.org/%s' % self.id],
-            u'language': self.xpath('ex:abstract/@xml:lang', 'author', unicode, multi=True),
+            u'language': self.xpath('ex:abstract/@xml:lang',
+                                    'author', unicode, multi=True),
             u'type': [self.content_type]
         }
 
         for el in self.root.xpath('ex:asset', namespaces=self.nsmap):
             asset = {}
             for child in el.xpath('*[text()]'):
-                asset[child.tag.split('}')[-1]] = child.text
+                asset[child.tag.split('}')[-1]] = unicode(child.text)
             assert u'filename' in asset, 'found asset without filename'
             assert u'mimetype' in asset, 'found asset without mimetype'
-            asset[u'url'] = u'http://example.org/repo/assets/%s/%s' % (self.id.replace(':', '_'),
-                                                                     asset['filename'])
+            asset[u'url'] = u'asset/%s/%s' % (
+                self.id,
+                asset['filename'])
             self._assets.append(asset)
-
+            
             path = os.path.join(os.path.dirname(__file__),
                                 'example_data',
-                                'assets', self.id.replace(':', '_'),
+                                'assets', self.id,
                                 asset['filename'])
             assert os.path.isfile(path), "Can not find asset: %s" % path
 
             asset[u'absolute_uri'] = u'file://%s' % path
-            assets[u'metadata'] = []
+            asset[u'md5'] = u''
+            asset[u'metadata'] = []
             self._assets.append(asset)
                 
             
     def set_person_fields(self):
         fields = {
             u'name' : [self.label],
-            u'surname': self.xpath('ex:surname/text()', 'surname', unicode, multi=True),
-            u'firstname': self.xpath('ex:firstname/text()', 'firstname', unicode, multi=True),
-            u'initials': self.xpath('ex:initials/text()', 'initials', unicode, multi=True),
-            u'dai': self.xpath('ex:dai/text()', 'initials', unicode, multi=True),
+            u'surname': self.xpath('ex:surname/text()',
+                                   'surname', unicode, multi=True),
+            u'firstname': self.xpath('ex:firstname/text()',
+                                     'firstname', unicode, multi=True),
+            u'initials': self.xpath('ex:initials/text()',
+                                    'initials', unicode, multi=True),
+            u'dai': self.xpath('ex:dai/text()',
+                               'initials', unicode, multi=True),
             }
         return fields

File src/moai/examples/example_data/assets/publication:1/test.txt

+This is an asset

File src/moai/examples/example_data/assets/publication_1/test.txt

-This is an asset

File src/moai/examples/simple/__init__.py

Empty file added.

File src/moai/examples/simple/config.py

+import os
+import shutil
+
+from moai import ConfigurationProfile, name
+from moai.update import DatabaseUpdater
+from moai.provider.file import FileBasedContentProvider
+from moai.server import Server, FeedConfig
+from moai.http.cherry import start_server
+from moai.database.sqlite import SQLiteDatabase
+from moai.examples.simple.content import SimpleDCContentObject
+            
+class SimpleDCConfiguration(ConfigurationProfile):
+    name('simple_dc_configuration')
+    
+    def get_content_provider(self):
+        provider = FileBasedContentProvider(self.config['path'], '*.xml')
+        provider.set_logger(self.log)
+        return provider
+
+
+    def get_database_updater(self):
+
+        dbpath = '/tmp/moai.new.db'
+        if os.path.isfile(dbpath):
+            self.log.warning('removing old moai.new.db')
+            os.remove(dbpath)
+        
+        return DatabaseUpdater(self.get_content_provider(),
+                               SimpleDCContentObject,
+                               SQLiteDatabase(dbpath, 'w'),
+                               self.log)
+
+    def get_database(self):
+        if os.path.isfile('/tmp/moai.new.db'):
+            shutil.move('/tmp/moai.new.db',
+                        '/tmp/moai.db')
+            
+        return SQLiteDatabase('/tmp/moai.db', 'r')
+    
+    def get_server(self):
+        server_url = 'http://%s:%s/repo' % (self.config['host'],
+                                            self.config['port'])
+        asset_path = os.path.join(os.path.dirname(__file__), 'data')
+                                  
+        server = Server(server_url,
+                        self.get_database())
+        server.add_config(
+            FeedConfig('example',
+                       'An example OAI Server',
+                       '%s/example' % server_url,
+                       self.log,
+                       base_asset_path=asset_path,
+                       metadata_prefixes=['oai_dc', 'mods',
+                                          'didl', 'nl_didl']))
+        return server
+                   
+    def start_development_server(self):
+        start_server('127.0.0.1', self.config['port'], 10, 'repo', self.get_server())
+
+        

File src/moai/examples/simple/content.py

+import os
+import time
+from datetime import datetime
+
+from lxml import etree
+
+from moai.content import XMLContentObject
+
+class SimpleDCContentObject(XMLContentObject):
+
+    def update(self, path, provider):
+        self.provider = provider
+        self.nsmap = {'dc':'http://purl.org/dc/elements/1.1/'}
+        doc = etree.parse(path)
+        self.root = doc.getroot()
+
+        self.id = self.xpath('dc:identifier[not(@scheme)]/text()',
+                             'identifier', unicode, required=True)
+        self.content_type = u'publication'
+        self.label = self.xpath('dc:title/text()',
+                                'label', unicode, required=True)
+        self.is_set = False
+        
+        self.when_modified = datetime(*time.gmtime(os.path.getmtime(path))[:6])
+        self.deleted = False
+        self.sets = []
+        self.sets.extend(self.xpath('dc:subject/text()',
+                                    'subject', unicode, multi=True))
+
+        self._assets = [{u'filename': u'%s.pdf' % self.id,
+                         u'url': u'asset/%s/%s.pdf' % (self.id, self.id),
+                         u'absolute_uri': u'',
+                         u'mimetype': u'application/pdf',
+                         u'md5': u'',
+                         u'metadata': {}}]
+
+
+        
+        self._fields = self.set_publication_fields()
+        
+    def set_publication_fields(self):
+        fields = {
+            u'description': self.xpath('dc:description/text()',
+                                       'description', unicode, multi=True),
+            u'title': [self.label],
+            u'date': self.xpath('dc:date/text()',
+                                'date', datetime, multi=True),
+            u'subject': self.xpath('dc:subject/text()',
+                                   'subject', unicode, multi=True),
+            u'identifier': [self.id],
+            u'language': self.xpath('dc:lanauge/text()',
+                                    'language', unicode, multi=True),
+            u'type': self.xpath('dc:type/text()',
+                                'type', unicode, multi=True),
+            u'url': self.xpath('dc:identifier[@scheme="dcterms:URI"]/text()',
+                               'identifier', unicode, multi=True),
+            u'author': self.xpath('dc:creator/text()',
+                                  'creator', unicode, multi=True),
+        }
+        
+        if fields['date']:
+            # fields should always be unicode
+            fields['date'] = [unicode(fields['date'][0].isoformat())]
+
+        return fields
+    
+    def get_assets(self):
+        return self._assets

File src/moai/examples/simple/data/Py3kEuro08/Py3kEuro08.pdf

Binary file added.

File src/moai/examples/simple/data/Py3kEuro08/oai_dc.xml

+<oai_dc:dc 
+ xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
+  <dc:title>Python 3000 and You</dc:title>
+  <dc:subject>python</dc:subject>
+  <dc:subject>py3k</dc:subject>
+  <dc:description>
+    The keynote held by Guido van Rossum at EuroPython 2008
+  </dc:description>
+  <dc:creator>Guido van Rossum</dc:creator>
+  <dc:type>Keynote</dc:type>
+  <dc:identifier>Py3kEuro08</dc:identifier>
+  <dc:identifier scheme="dcterms:URI">
+    http://www.europython2008.eu/Keynotes
+  </dc:identifier>
+  <dc:language>en</dc:language>
+  <dc:date>2008-07-10T12:36:00</dc:date>
+</oai_dc:dc>
+