Changeset 4562


Ignore:
Timestamp:
08/12/08 16:10:12 (11 years ago)
Author:
cbyrom
Message:

Move granulite to ndgUtils to allow re-use with the atom editor.
Extend + generalise this class to allow use for both granulite files and
when just adding CDML/CSML data to an atom + allow specification of
single input file; the class now works out whether this is a CSML or CDML
file.
Add helper methods to utilities for this purpose.

Location:
exist/trunk/python/ndgUtils/lib
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/lib/utilities.py

    r4535 r4562  
    11import os, sys, logging, re, cgi, urlparse, httplib, time, urllib2, socket 
    22from ndgUtils.ETxmlView import subAI 
     3from ndgUtils import ndgObject 
    34import csml.csmlscan as CsmlScan 
    45from xml.sax.saxutils import escape 
     
    226227    CSMLFileName = datasetID + "_csml.xml" 
    227228    logging.debug("Inputs specified: datasetID = %s, timeAxis = %s" %(datasetID, timeAxis)) 
    228     CsmlScan.main(['csmlscan', '-i', datasetID ,'-t', timeAxis, '-o', CSMLFileName, CDMLFilePath]) 
     229    inputVals = ['csmlscan', '-o', CSMLFileName, CDMLFilePath] 
     230    if datasetID: 
     231        inputVals.extend(['-i', datasetID]) 
     232    if timeAxis: 
     233        inputVals.extend(['-t', timeAxis]) 
     234     
     235    CsmlScan.main(inputVals) 
    229236    logging.info("Created CSML file: %s" %CSMLFileName) 
    230237    return CSMLFileName 
     238 
     239 
     240def isCSMLFile(fileContent): 
     241    ''' 
     242    Given the contents of a file, determine whether it is CSML or not 
     243    @param fileContent: content of the file to check - as a string 
     244    @return True if CSML, False otherwise 
     245    ''' 
     246    logging.info("Checking file content to see if it is a CSML file") 
     247    if fileContent.find(ndgObject.CSML_NS) > -1 or \ 
     248        fileContent.find('CSMLFeatureCollection') > -1 or \ 
     249        fileContent.find('CSMLStorageDescriptor') > -1: 
     250        logging.info("- file is of CSML format") 
     251        return True 
     252 
     253    logging.info("- file is not of CSML format") 
     254    return False 
     255 
     256 
     257def isCDMLFile(fileContent): 
     258    ''' 
     259    Given the contents of a file, determine whether it is CDML or not 
     260    @param fileContent: content of the file to check - as a string 
     261    @return True if CDML, False otherwise 
     262    ''' 
     263    logging.info("Checking file content to see if it is a CDML file") 
     264    # NB, this is a bit of a fudge - there may be a better way to check for 
     265    # CDML-ness 
     266    if filecontent.find(ndgObject.CDML_DTD) > -1 or \ 
     267        (fileContent.find('dataset') > -1 and \ 
     268        fileContent.find('attr') > -1 and \ 
     269        fileContent.find('axis')): 
     270        logging.info("- file is of CDML format") 
     271        return True 
     272 
     273    logging.info("- file is not of CDML format") 
     274    return False 
    231275 
    232276 
Note: See TracChangeset for help on using the changeset viewer.