Index: trunk/ippToPsps/jython/dvoToMySQL.py
===================================================================
--- trunk/ippToPsps/jython/dvoToMySQL.py	(revision 31353)
+++ trunk/ippToPsps/jython/dvoToMySQL.py	(revision 31353)
@@ -0,0 +1,98 @@
+#!/usr/bin/env jython
+
+import stilts
+import datetime
+import re
+import sys
+import os
+import logging
+from subprocess import call, PIPE, Popen
+
+from gpc1db import Gpc1Db
+from scratchdb import ScratchDb
+
+from java.lang import *
+from java.sql import *
+from xml.etree.ElementTree import ElementTree, Element, tostring
+
+
+'''
+Class for pulling IDs from a DVO database and shoving in a MySQL database 
+'''
+class DvoToMySql(object):
+
+    '''
+    Constructor
+
+    '''
+    def __init__(self, logger, pathToDvo):
+
+        # set up logging
+        self.logger = logger
+        self.pathToDvo = pathToDvo
+        self.logger.debug("DvoToMySql class constructor")
+
+        self.logger.debug("Important DVO database at " + self.pathToDvo)
+
+        # open config
+        doc = ElementTree(file="config.xml")
+
+        # create database objects
+        self.scratchDb = ScratchDb(logger)
+        self.gpc1Db = Gpc1Db(self.logger)
+
+        # create DVO table
+        self.scratchDb.createDvoTables()
+
+        # now import tables
+        self.importFits(self.pathToDvo, "Images.dat", 
+                "IMAGE_ID SOURCE_ID CCDNUM EXTERN_ID FLAGS PHOTCODE")
+        
+
+    '''
+    Destructor
+    '''
+    def __del__(self):
+
+        self.logger.debug("DvoToMySql destructor")
+
+    '''
+    Imports a FITS file. A regex filter lets you choose which tables to pull from the file
+    '''
+    def importFits(self, path, file, columns):
+
+      fullPath = path + "/" + file
+      self.logger.info("Attempting to import tables from: " + fullPath)
+
+      tables = stilts.treads(fullPath)
+
+      count = 0
+      for table in tables:
+
+          self.logger.info("   Reading IPP table " + table.name + " from FITS file")
+          table = stilts.tpipe(table, cmd='explodeall')
+     
+          self.scratchDb.dropTable(table.name)
+
+          table.cmd_keepcols('PHOTCODE')
+          # IPP FITS files are littered with infinities, so remove these
+          self.logger.info("   Removing Infinity values from all columns")
+          table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
+          table = stilts.tpipe(table, cmd='replaceval Infinity null *')
+
+          #try:
+          table.cmd_keepcols('IMAGE_ID SOURCE_ID CCDNUM EXTERN_ID FLAGS PHOTCODE').write(self.scratchDb.url + '#' + file)
+          #except:
+          #    self.logger.exception("   Problem writing table '" + table.name + "' to the database")
+          count = count + 1
+
+      self.logger.info("Done. Imported %d tables" % count)
+
+
+logging.config.fileConfig("logging.conf")
+logger = logging.getLogger("dvotomysql")
+logger.info("Starting")
+
+dvoToMySql = DvoToMySql(logger, "/data/ipp005.0/gpc1/catdirs/MD04.merges/MD04.merge")
+
+
