Changeset 4034


Ignore:
Timestamp:
30/06/08 12:11:41 (11 years ago)
Author:
cbyrom
Message:

Fix PrettyPrint? to cast elem data as string, before attempting to
call strip() on it (to avoid problems when handling, e.g. ints).
Add ndgmetadata1.3.xsd to csml package and extend molesReadWrite to
use this version, to avoid the need to having to copy this file
locally on each use.

Location:
TI02-CSML/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/csml2Moles/molesReadWrite.py

    r4028 r4034  
    1111        # if you've egged it this is the way it comes 
    1212        from ndgUtils.elementtree import cElementTree as ET 
    13 import sys 
    14  
     13import sys, os, pkg_resources 
    1514 
    1615#this is the NEW xml schema class 
     
    246245         
    247246    def toXML(self): 
    248         self.schema = xmlSchema('ndgmetadata1.3.xsd') 
     247        # ensure that the schema is avaiable locally - if not extract from egg 
     248        self.molesSchema = 'ndgmetadata1.3.xsd' 
     249        self.extractLocalSchema() 
     250        self.schema = xmlSchema(self.molesSchema) 
    249251        molesFrag=ET.Element('dgMetadata') 
    250252        molesFrag.attrib['xmlns']='http://ndg.nerc.ac.uk/moles' 
    251253        molesElement.toXML(self,molesFrag,schema=self.schema) 
    252254        return molesFrag 
    253  
     255     
     256    def extractLocalSchema(self): 
     257        schema = 'XMLSchemas/moles/' + self.molesSchema 
     258        if not os.path.isfile(self.molesSchema): 
     259            content = pkg_resources.resource_string('csml',schema) 
     260            try: 
     261                f = open(self.molesSchema,'w') 
     262                f.write(content) 
     263                f.close() 
     264            except: 
     265                raise SystemError, "ERROR: Problem encountered when creating file, %s" %schema 
    254266 
    255267class MolesDoc(object): 
  • TI02-CSML/trunk/csml/parser_extra.py

    r4003 r4034  
    5959                        return '' 
    6060                else: 
    61                         return elem.strip() 
     61                        # just in case the elem is another simple type - e.g. int - wrapper it as a string 
     62                        return str(elem).strip() 
    6263        strAttrib='' 
    6364        for att in elem.attrib: 
  • TI02-CSML/trunk/setup.py

    r3683 r4034  
    1717 
    1818    packages = find_packages(), 
     19    package_data = {'csml':['XMLSchemas/moles/ndgmetadata1.3.xsd']}, 
    1920    install_requires = ['cdat_lite'], 
    2021 
Note: See TracChangeset for help on using the changeset viewer.