Changeset 4679 for exist


Ignore:
Timestamp:
18/12/08 12:31:06 (11 years ago)
Author:
cbyrom
Message:

Extend granulite to allow command line operation - with input options
to specify logging level and 'replace atom' mode - which command line
inputs to ask users if they want to replace duplicated data.

Location:
exist/trunk/python/ndgUtils
Files:
4 edited

Legend:

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

    r4677 r4679  
    505505 
    506506             
    507     def createAtomInExist(self, atom, replaceAtom = 'True'): 
     507    def createAtomInExist(self, atom, replaceAtom = True): 
    508508        ''' 
    509509        Create an atom in the eXist DB - using the atom contents to work out 
    510510        the location + data set ID 
    511511        @param atom: atom object to create in the DB 
    512         @keyword replaceAtom: if 'False' and the atom is already available in eXist 
    513         then raise a ValueError.  NB, use strings not bools. 
     512        @keyword replaceAtom: if False and the atom is already available in eXist 
     513        then raise a ValueError. 
    514514        ''' 
    515515        logging.info("Creating atom in eXist") 
     
    546546        # create backup of atom if it already exists 
    547547        else: 
    548             if replaceAtom == 'False': 
     548            if not replaceAtom: 
    549549                raise DuplicateError('An atom with the specified ID (%s) already exists in eXist' \ 
    550550                                     %atom.datasetID) 
  • exist/trunk/python/ndgUtils/lib/granulite.py

    r4677 r4679  
    7272                  eXistClient = None, csmlOrCdmlFile = None, \ 
    7373                  aggregateCoverage = False, useCSMLID = False,  
    74                   timeAxis = 'time', datasetID = None): 
     74                  timeAxis = 'time', datasetID = None, replaceAtom = False): 
    7575        ''' 
    7676        Constructor for granulite object - NB, the csml/cdml keywords allow use 
     
    9191        @keyword datasetID: if using a CDML file, specify the ID of the dataset to use 
    9292        - otherwise one will be randomly generated 
     93        @keyword replaceAtom: if True, and if a granule atom is found with the ID of 
     94        the atom to be created by the granulite, automatically overwrite the older 
     95        atom  
    9396        ''' 
    9497        logging.info("Creating granulite data model") 
     
    120123            # create a skeleton granule 
    121124            self.__initialiseGranule() 
    122  
     125             
     126        self._replaceAtom = replaceAtom 
    123127        self.useCSMLID = useCSMLID 
    124128        self._cdmlTimeAxis = timeAxis 
     
    380384        ''' 
    381385        logging.debug("Retrieving data entity atom - to attach granule to") 
    382 #        doc = self._eXist.getAtom('dataent_' + dataEntityID) 
    383         doc = self._eXist.getAtom(dataEntityID) 
     386        doc = self._eXist.getAtom('dataent_' + dataEntityID) 
    384387        logging.debug("DE retrieved - now adding link to granule") 
    385388        de = Atom.Atom(xmlString=str(doc)) 
     
    551554        # add the granule to eXist - if this exists already a DuplicationError 
    552555        # will be thrown if backups are not allowed 
     556        doReplace = replaceAtom or self._replaceAtom 
    553557        logging.info("Creating granule atom, '%s', in eXist DB" %self._atom.atomName) 
    554         self._eXist.createAtomInExist(self._atom, replaceAtom = replaceAtom) 
     558        self._eXist.createAtomInExist(self._atom, replaceAtom = doReplace) 
    555559 
    556560        # now add the granule data to the data entity in eXist 
     
    562566 
    563567if __name__=="__main__": 
    564     opts, args = getopt.getopt(sys.argv[1:], '-oxuvd') 
     568    opts, args = getopt.getopt(sys.argv[1:], '-rxvd') 
    565569    if len(args) < 1: 
    566570        print "Error: Please specify a granulite data file to process" 
    567571        sys.exit(2) 
    568      
    569     logging.basicConfig(level = logging.DEBUG, 
     572         
     573    loggingLevel = logging.WARNING 
     574    isReplace = False 
     575    for o, a in opts: 
     576        if o == "-v": 
     577            print " - Verbose mode ON" 
     578            loggingLevel = logging.INFO 
     579        elif o == "-d": 
     580            print " - Debug mode ON" 
     581            loggingLevel = logging.DEBUG 
     582        elif o == "-r": 
     583            print " - Replace mode ON" 
     584            isReplace = True 
     585        elif o == "-x": 
     586            print " - Delete mode ON" 
     587            isDelete = True 
     588     
     589    logging.basicConfig(level = loggingLevel, 
    570590                        format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s') 
    571     g = granulite(args[0]) 
    572     g.processGranulite() 
     591    g = granulite(args[0], replaceAtom = isReplace) 
     592     
     593    try: 
     594        g.processGranulite() 
     595    except edc.DuplicateError, e: 
     596        # allow the user to specify if they want to overwrite the duplicated atom 
     597        print e.message 
     598        input = raw_input("- do you want to overwrite this with the granulite data? (y/n) ") 
     599        if input.strip().upper() == 'Y': 
     600            print "OK - replacing old granule atom..." 
     601            g.processGranulite(replaceAtom = True) 
     602        else: 
     603            print "Exiting...." 
  • exist/trunk/python/ndgUtils/models/Atom.py

    r4663 r4679  
    549549        selfLink.attrib["href"] = self.atomBrowseURL 
    550550        selfLink.attrib["rel"] = "self" 
    551         if self.subtypeID != VTD.DEPLOYMENT_TERM: 
    552             molesLink = ET.SubElement(root, "link") 
    553             molesDoc = re.sub('ATOM','NDG-B1', self.atomBrowseURL) 
    554             molesLink.attrib["href"] = molesDoc 
    555             molesLink.attrib["rel"] = 'related' 
    556551         
    557552        for relatedLink in self.relatedLinks: 
  • exist/trunk/python/ndgUtils/models/vocabtermdata.py

    r4663 r4679  
    265265    #BROWSE_ROOT_URL = "http://snow.badc.rl.ac.uk:5000/view/" 
    266266    BROWSE_ROOT_URL = "http://localhost:5000/view/" 
     267     
     268    BADC_BROWSE_ROOT = 'http://badc.nerc.ac.uk/browse' 
    267269 
    268270    def __init__(self): 
Note: See TracChangeset for help on using the changeset viewer.