Index: trunk/ippToPsps/jython/gpc1db.py
===================================================================
--- trunk/ippToPsps/jython/gpc1db.py	(revision 31344)
+++ trunk/ippToPsps/jython/gpc1db.py	(revision 31345)
@@ -7,6 +7,6 @@
 import logging
 
+from mysql import MySql
 from java.sql import *
-from xml.etree.ElementTree import ElementTree
 
 
@@ -14,29 +14,11 @@
 Class for GPC1 database connectivity
 '''
-class Gpc1Db(object):
-
-    driverName="com.mysql.jdbc.Driver"
+class Gpc1Db(MySql):
 
     '''
     Constructor
-
     '''
     def __init__(self, logger):
-
-        # setup logging
-        self.logger = logger
-        self.logger.debug("Gpc1Db constructor")
-
-        # open config
-        doc = ElementTree(file="config.xml")
-
-        # set up JDBC connection
-        dbName = doc.find("gpc1database/name").text
-        dbHost = doc.find("gpc1database/host").text
-        dbUser = doc.find("gpc1database/user").text
-        dbPass = doc.find("gpc1database/password").text
-        self.url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass
-        self.con = DriverManager.getConnection(self.url)
-        self.stmt = self.con.createStatement()
+        super(Gpc1Db, self).__init__(logger,"gpc1database")
 
     '''
@@ -46,12 +28,9 @@
 
         self.logger.debug("Gpc1Db destructor")
-        self.stmt.close()
-        self.con.close()
-
 
     '''
-    Gets a list of sky_ids in this DVO database
+    Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far)
     '''
-    def getSkyIDsInThisDVODb(self, dvoDb):
+    def getIDsInThisDVODbForThisStage(self, dvoDb, stage):
 
         self.logger.debug("Querying GPC1 for sky_ids in this DVO database: " + dvoDb)
@@ -59,8 +38,6 @@
         sql = "SELECT DISTINCT stage_id \
                FROM addRun \
-               WHERE stage = 'staticsky' \
+               WHERE stage = '" + stage + "' \
                AND dvodb = '" + dvoDb + "'"
-
-        print sql
 
         try:
@@ -69,11 +46,11 @@
             self.logger.exception("Can't query for sky_ids")
 
-        skyIDs = []
+        ids = []
         while (rs.next()):
-            skyIDs.append(rs.getInt(1))
+            ids.append(rs.getInt(1))
 
         rs.close()
 
-        return skyIDs
+        return ids
 
     '''
@@ -106,4 +83,66 @@
 
         return imageIDs
+
+    '''
+    Gets some camera-stage meta data for this cam_id
+    '''
+    def getCameraStageMeta(self, camID):
+
+        self.logger.debug("Querying GPC1 for camera meta data")
+
+        meta = []
+        sql = "SELECT exp_id, exp_name, camRun.dist_group \
+               FROM camRun \
+               JOIN chipRun USING(chip_id) \
+               JOIN rawExp USING(exp_id) WHERE camRun.cam_id = %d" % camID
+
+        try:
+            rs = self.stmt.executeQuery(sql)
+            rs.first()
+        except:
+            self.logger.exception("Can't query for camera meta")
+        finally:
+            meta.append(rs.getInt(1))
+            meta.append(rs.getString(2))
+            meta.append(rs.getString(3))
+
+        return meta
+
+    '''
+    Gets a camera-stage smf for this cam_id
+    '''
+    def getCameraStageSmf(self, camID):
+
+        self.logger.debug("Querying GPC1 for camera smf files")
+
+        sql = "SELECT path_base \
+               FROM camProcessedExp \
+               JOIN camRun USING(cam_id) \
+               WHERE camRun.cam_id = %d" % camID
+
+        try:
+            rs = self.stmt.executeQuery(sql)
+            rs.first()
+        except:
+            self.logger.exception("Can't query for camera smfs")
+
+        # get path to base dir of cmf files
+        path = rs.getString(1)
+        path = path[0:path.rfind("/")]
+       
+        # list all cmf files if a neb path
+        files = []
+        if path.startswith("neb"):
+
+            f=os.popen("neb-ls -p "+path+"/%smf")
+            print "neb-ls -p "+path+"/%smf"
+            for i in f.readlines():
+                files.append(i.rstrip())
+
+        # or not a neb path
+        else:
+            files = glob.glob(path + "/*.cmf")
+
+        return files[0] # TODO just returning first file - check
 
 
Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 31344)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 31345)
@@ -6,41 +6,38 @@
 import logging
 
+from mysql import MySql
 from java.sql import *
-from xml.etree.ElementTree import ElementTree
 
 '''
 Class for ippToPsps database connectivity
 '''
-class IppToPspsDb(object):
-
-    driverName="com.mysql.jdbc.Driver"
+class IppToPspsDb(MySql):
 
     '''
     Constructor
-
     '''
     def __init__(self, logger):
-
-        # setup logging
-        self.logger = logger
-        self.logger.debug("IppToPspsDb Constructor")
-        # open config
-        doc = ElementTree(file="config.xml")
-
-        # set up JDBC connection
-        dbName = doc.find("ipptopspsdatabase/name").text
-        dbHost = doc.find("ipptopspsdatabase/host").text
-        dbUser = doc.find("ipptopspsdatabase/user").text
-        dbPass = doc.find("ipptopspsdatabase/password").text
-        self.url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass
-        self.con = DriverManager.getConnection(self.url)
-        self.stmt = self.con.createStatement()
+        super(IppToPspsDb, self).__init__(logger,"ipptopspsdatabase")
 
     '''
     Creates a new batch
     '''
-    def createNewBatch(self, expID, surveyType, batchType, dvoDb, datastoreProduct):
+    def createNewBatch(self, batchType, survey, dvoDb, datastoreProduct):
 
-        sql = "SELECT batch_id FROM batches ORDER BY batch_id DESC LIMIT 1"
+        sql = "INSERT INTO batch ( \
+               batch_type, \
+               survey, \
+               dvo_db, \
+               datastore_product \
+               ) VALUES ( \
+               '" + batchType + "', \
+               '" + survey + "', \
+               '" + dvoDb + "', \
+               '" + datastoreProduct + "' \
+               )"
+
+        self.stmt.execute(sql)
+
+        sql = "SELECT MAX(batch_id) FROM batch"
 
         batchID = -1;
@@ -53,27 +50,63 @@
             self.logger.exception("Unable to get batch ID")
 
-        if batchID > 0:
-            batchID = batchID + 1
-
-            sql = "INSERT INTO batches \
-                   (batch_id, \
-                    exp_id, \
-                    survey_id, \
-                    batch_type, \
-                    dvo_db, \
-                    datastore_product) \
-                   VALUES \
-                   ("+str(batchID)+", \
-                    " + str(expID) + ", \
-                    '"+surveyType+"', \
-                    '"+batchType+"', \
-                    '"+dvoDb+"', \
-                    '"+datastoreProduct+"')"
-
-            self.stmt.execute(sql)
-
-        self.logger.info("Creating new batch in ippToPsps database with batchID = %d" % batchID)
+        self.logger.info("Created new batch in ippToPsps database with batchID = %d" % batchID)
 
         return batchID;
+
+    '''
+    Updates min/max object ID on this table and batch 
+    '''
+    def updateMinMaxObjID(self, batchID, minObjID, maxObjID):
+
+        sql = "UPDATE batch SET \
+               min_obj_id = " + str(minObjID) + ", \
+               max_obj_id = " + str(maxObjID) + " \
+               WHERE batch_id = " + str(batchID)
+
+        self.stmt.execute(sql)
+
+    '''
+    Updates batch processed field 
+    '''
+    def updateProcessed(self, batchID, processed):
+
+        sql = "UPDATE batch \
+               SET processed = " + str(processed) + " \
+               WHERE batch_id = " + str(batchID)
+
+        self.stmt.execute(sql)
+
+    '''
+    Updates batch loaded_to_datastore field 
+    '''
+    def updateLoadedToDatastore(self, batchID, loadedToDatastore):
+
+        sql = "UPDATE batch \
+               SET loaded_to_datastore = " + str(loadedToDatastore) + " \
+               WHERE batch_id = " + str(batchID)
+
+        self.stmt.execute(sql)
+
+    '''
+    Inserts some stack metadata for this batch ID
+    '''
+    def insertStackMeta(self, batchID, skyID, stackID, filter, stackType):
+
+        sql = "INSERT INTO stack ( \
+               batch_id \
+               ,sky_id \
+               ,stack_id \
+               ,filter \
+               ,stack_type \
+               ) VALUES ( \
+               " + str(batchID) + " \
+               ," + str(skyID) + " \
+               ," + str(stackID) + " \
+               ,'" + filter + "' \
+               ,'" + stackType + "' \
+               )"
+
+        self.stmt.execute(sql)
+
 
     '''
