Exemple #1
0
def pushCompleteData(target_dir, dbSession, logger):
    logger.info('Start creating service and parent metadata file ...')
    serviceMetadataFile = createServiceDescription(TEMPLATE_FILES['service'], target_dir, dbSession, logger)
    parentMetadataFile = os.path.join( target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(TEMPLATE_FILES['parent'], parentMetadataFile)
    logger.info('Insert service and parent metdata file ...')
    gn_transaction_insert(serviceMetadataFile, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger)
    gn_transaction_insert(parentMetadataFile, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger)
    
    logger.info('Start pushing single metadata records to the geonetwork instance ...')
    messtischblaetter = Messtischblatt.all(dbSession)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        if messtischblatt.isttransformiert:
            logger.debug('Push metadata record for messtischblatt %s to cataloge service ...'%messtischblatt.id)
            insertMetadata(id=messtischblatt.id,db=dbSession,logger=logger)
def createServiceDescription(template_path, target_dir, db, logger):
    logger.debug('Start creating service description')

    # create tempory copy
    mdServiceFile = os.path.join(target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(template_path, mdServiceFile)

    # Helper method which define the prefix of the namespaces
    for key in Namespaces:
        ET.register_namespace(key, Namespaces[key].strip('}').strip('{'))

    # parse xml template file
    xmlTree = ET.parse(mdServiceFile)
    xmlElementRoot = xmlTree.getroot()

    # search xml element srv:SV_ServiceIdentification
    searchHierarchy = [
        Namespaces['gmd'] + 'identificationInfo',
        Namespaces['srv'] + 'SV_ServiceIdentification'
    ]
    xmlElementServiceId = xmlElementRoot.find('/'.join(searchHierarchy))

    # get all messtischblaetter
    i = 0
    messtischblaetter = Messtischblatt.all(db)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        metadata_core = MdCore.by_id(messtischblatt.id, db)
        appendCoupledResource(rootElement=xmlElementServiceId,
                              resourceId=str(messtischblatt.id),
                              resourceTitle=metadata_core.titel)

        # break condition for testing


#         if i == 10:
#             break
#         i += 1

    logger.debug('Save modified file in %s.' % mdServiceFile)

    #print 'Service document'
    #print '================'
    #print ET.tostring(xmlElementRoot, encoding='utf-8', method='xml')

    xmlTree.write(mdServiceFile, encoding="utf-8", xml_declaration=True)
    return mdServiceFile
def createServiceDescription(template_path, target_dir, db, logger):
    logger.debug('Start creating service description')
    
    # create tempory copy
    mdServiceFile = os.path.join( target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(template_path, mdServiceFile)

    # Helper method which define the prefix of the namespaces
    for key in Namespaces:
        ET.register_namespace(key, Namespaces[key].strip('}').strip('{'))
        
    # parse xml template file
    xmlTree = ET.parse(mdServiceFile)
    xmlElementRoot = xmlTree.getroot()
    
    # search xml element srv:SV_ServiceIdentification
    searchHierarchy = [Namespaces['gmd']+'identificationInfo', Namespaces['srv']+'SV_ServiceIdentification']
    xmlElementServiceId = xmlElementRoot.find('/'.join(searchHierarchy))
        
    # get all messtischblaetter
    i = 0
    messtischblaetter = Messtischblatt.all(db)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        metadata_core = MdCore.by_id(messtischblatt.id, db)
        appendCoupledResource(rootElement = xmlElementServiceId, resourceId = str(messtischblatt.id), resourceTitle = metadata_core.titel)
        
        # break condition for testing
#         if i == 10:
#             break
#         i += 1

    logger.debug('Save modified file in %s.'%mdServiceFile)        
    
    #print 'Service document'
    #print '================'
    #print ET.tostring(xmlElementRoot, encoding='utf-8', method='xml')
    
    xmlTree.write(mdServiceFile, encoding="utf-8", xml_declaration=True)
    return mdServiceFile
Exemple #4
0
def pushCompleteData(target_dir, dbSession, logger):
    logger.info('Start creating service and parent metadata file ...')
    serviceMetadataFile = createServiceDescription(TEMPLATE_FILES['service'],
                                                   target_dir, dbSession,
                                                   logger)
    parentMetadataFile = os.path.join(target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(TEMPLATE_FILES['parent'], parentMetadataFile)
    logger.info('Insert service and parent metdata file ...')
    gn_transaction_insert(serviceMetadataFile, GN_SETTINGS['gn_username'],
                          GN_SETTINGS['gn_password'], logger)
    gn_transaction_insert(parentMetadataFile, GN_SETTINGS['gn_username'],
                          GN_SETTINGS['gn_password'], logger)

    logger.info(
        'Start pushing single metadata records to the geonetwork instance ...')
    messtischblaetter = Messtischblatt.all(dbSession)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        if messtischblatt.isttransformiert:
            logger.debug(
                'Push metadata record for messtischblatt %s to cataloge service ...'
                % messtischblatt.id)
            insertMetadata(id=messtischblatt.id, db=dbSession, logger=logger)
Exemple #5
0
        mdEditor.updateIdCode(metadata['identifier'])
        mdEditor.updateOnlineResource(metadata['onlineresource'])
        
        print '============================'
        print mdEditor.tostring()
        print '============================'
        
        mdEditor.saveFile(file)
        return True
    except:
        logger.error('Problems while updating the metadata for the xml file %s'%file)
        raise




if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    dbSession = initializeDb(DBCONFIG)
    logger = logging.getLogger('sqlalchemy.engine')
    
    # get all messtischblätter
    messtischblaetter = Messtischblatt.all(dbSession)
    for messtischblatt in messtischblaetter:
        if messtischblatt.isttransformiert:
            #response = gn_transaction_delete(messtischblatt.dateiname, gn_settings['gn_username'], gn_settings['gn_password'], logger)
            response = insertMetadata(id=messtischblatt.id,db=dbSession,logger=logger)
            print "Response - delete record"
            print "========================"
            print response