#!/usr/bin/env jython

import stilts
import datetime
import re
import sys
import os
import logging
import glob

from dvo import Dvo


'''
A class for ingesting DVO detections into MySQL
'''
class DvoObjects(Dvo):

    '''
    Constructor
    '''
    def __init__(self, logger, config, scratchDbName=None):

        super(DvoObjects, self).__init__(logger, config, scratchDbName)

        # declare DVO file types of interest
        self.ingestFileTypes = ['cpt', 'cps']
        self.loadPhotcodes()

    '''
    Ingests object files for this region
    '''
    def ingestRegion(self, region):

       self.logger.infoPair("Ingesting objects for", region)

       for fileType in self.ingestFileTypes:

           path = self.config.dvoLocation + "/" + region + "." + fileType
           tableName = self.scratchDb.getDbFriendlyTableName(region + "." + fileType)

           self.importFits(path, "*", tableName)

           self.scratchDb.setImportedThisDvoTable(path, region)

       return True


