def update_records(self):
        
        def purge_scenes(db_cursor, dataset_root):
            logger.info('Purging all nonexistent datasets in directory "%s"', dataset_root)
            sql = """-- Retrieve all dataset paths
select dataset_id, dataset_path
from dataset
where position(%(dataset_root)s in dataset_path) = 1
order by dataset_path;
"""    
            params = {'dataset_root': dataset_root}
    
            log_multiline(logger.debug, db_cursor.mogrify(sql, params), 'SQL', '\t')
    
            db_cursor.execute(sql, params)
            
            db_cursor2 = self.db_connection.cursor()
            for row in db_cursor:
                if not os.path.isdir(os.path.join(row[1], 'scene01')):
                    logger.info('Removing dataset record for nonexistent directory "%s"', row[1])
                    sql = """-- Removing %(bad_dataset)s
delete from tile where dataset_id = %(dataset_id)s;
delete from dataset where dataset_id = %(dataset_id)s;

"""    
                    params = {'dataset_id': row[0],
                              'bad_dataset': row[1]}
    
                    log_multiline(logger.debug, db_cursor2.mogrify(sql, params), 'SQL', '\t')
    
                    try:
                        db_cursor2.execute(sql, params)
                        self.db_connection.commit()
                    except Exception, e:
                        logger.warning('Delete operation failed for "%s": %s', sql, e.message)
                        self.db_connection.rollback()

            logger.info('Scene purging completed for %s', dataset_root) 
            
        dataset_list_file = os.path.join(self.temp_dir, 'dataset.list')
        if self.remove_existing_dblist:
            try:
                os.remove(dataset_list_file)
            except:
                pass
        db_cursor = self.db_connection.cursor()
    
        if self.purge:
            # Remove rows for nonexistent files
            purge_scenes(db_cursor, self.source_dir) 

        # Wait for locked file to become unlocked
        unlock_retries = 0
        while os.path.exists(dataset_list_file) and self.check_object_locked(dataset_list_file):
            unlock_retries += 1
            assert unlock_retries > DBUpdater.MAX_RETRIES, 'Timed out waiting for list file %s to be unlocked' % dataset_list_file
            logger.debug('Waiting for locked list file %s to become unlocked',  dataset_list_file)
            time.sleep(DBUpdater.LOCK_WAIT)
            
        if os.path.exists(dataset_list_file):
            logger.info('Loading existing list file %s',  dataset_list_file)
            shelf = shelve.open(dataset_list_file)
            dataset_list = shelf['dataset_list']
            shelf.close()
        else:        
            self.lock_object(dataset_list_file)
            shelf = shelve.open(dataset_list_file)
            logger.info('Creating new list file %s',  dataset_list_file)
            
            # Create master list of datasets
            logger.info('Searching for datasets in %s', self.source_dir)
            if self.follow_symbolic_links:
                command = "find -L %s -name 'scene01' | sort" % self.source_dir
            else:
                command = "find %s -name 'scene01' | sort" % self.source_dir
            logger.debug('executing "%s"', command)
            result = execute(command)
            assert not result['returncode'], '"%s" failed: %s' % (command, result['stderr'])
    
            dataset_list = [os.path.abspath(re.sub('/scene01$', '', scenedir)) for scenedir in result['stdout'].split('\n') if scenedir]
    
            # Save dataset dict for other instances to use
            logger.debug('Saving new dataset list file %s',  dataset_list_file)
#            assert not os.path.getsize(dataset_list_file), 'File %s has already been written to'
            shelf['dataset_list'] = dataset_list
            shelf.close()
            self.unlock_object(dataset_list_file)
            
#            log_multiline(logger.debug, dataset_list, 'dataset_list')

        print 'Not here'
        for dataset_dir in dataset_list:
            if not os.path.isdir(os.path.join(dataset_dir, 'scene01')):
                logger.warning('Skipping nonexistent dataset %s', dataset_dir)
                continue
            
            try:
                if re.search('PQ', dataset_dir):
                    update_pqa_dataset_record.update_dataset_record(dataset_dir, db_cursor, self.refresh, self.debug)
                elif re.search('FC', dataset_dir):
                    update_fc_dataset_record.update_dataset_record(dataset_dir, db_cursor, self.refresh, self.debug)
                else:
                    update_dataset_record.update_dataset_record(dataset_dir, db_cursor, self.refresh, self.debug)
                self.db_connection.commit()
            except Exception, e:
                logger.warning('Database operation failed for %s: %s', dataset_dir, e.message)
                self.db_connection.rollback()
        
#        self.db_connection.close()        
        logger.info('Database updating completed for %s', self.source_dir)
dataset/ETHPy150Open GeoscienceAustralia/agdc/deprecated/dbupdater.py/DBUpdater.update_records/original