Index: /trunk/ippToPsps/jython/gpc1db.py
===================================================================
--- /trunk/ippToPsps/jython/gpc1db.py	(revision 31399)
+++ /trunk/ippToPsps/jython/gpc1db.py	(revision 31400)
@@ -34,6 +34,4 @@
     def getIDsInThisDVODbForThisStage(self, dvoDb, stage):
 
-        self.logger.debug("Querying GPC1 for sky_ids in this DVO database: " + dvoDb)
-
         sql = "SELECT DISTINCT stage_id \
                FROM addRun \
@@ -44,5 +42,5 @@
             rs = self.stmt.executeQuery(sql)
         except:
-            self.logger.exception("Can't query for sky_ids")
+            self.logger.exception("Can't query for ids in DVO")
 
         ids = []
@@ -52,4 +50,6 @@
         rs.close()
 
+        self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
+
         return ids
 
@@ -59,5 +59,5 @@
     def getImageIDsForThisStackID(self, stackID):
 
-        self.logger.debug("Querying GPC1 for image IDs for stack ID: " + stackID)
+        self.logger.debug("Querying GPC1 for image IDs for stack ID: " + str(stackID))
 
         sql = "SELECT DISTINCT CONCAT(exp_id, SUBSTR(class_id, 3, 4)) FROM ( \
@@ -70,5 +70,5 @@
                JOIN camRun USING(cam_id)  \
                JOIN chipRun USING(chip_id) \
-               WHERE stackRun.stack_id = " + stackID + ") AS a"
+               WHERE stackRun.stack_id = " + str(stackID) + ") AS a"
 
         try:
@@ -84,4 +84,33 @@
         return imageIDs
 
+    '''
+    Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved
+    '''
+    def getStackStageMeta(self, skyID, filter):
+
+        self.logger.debug("Querying GPC1 for stack meta data")
+
+        meta = []
+        sql = "SELECT \
+               stackRun.stack_id,\
+               stackRun.skycell_id \
+               FROM \
+               staticskyInput, staticskyRun, stackRun, staticskyResult \
+               WHERE staticskyRun.sky_id = staticskyInput.sky_id \
+               AND staticskyInput.stack_id = stackRun.stack_id \
+               AND staticskyInput.sky_id = staticskyResult.sky_id \
+               and staticskyInput.sky_id = %d \
+               and filter = '%s'" % (skyID, filter)
+
+
+        try:
+            rs = self.stmt.executeQuery(sql)
+            rs.first()
+            meta.append(rs.getInt(1))
+            meta.append(rs.getString(2))
+        except:
+            self.logger.exception("Can't query for stack meta")
+
+        return meta
     '''
     Gets some camera-stage meta data for this cam_id
@@ -100,10 +129,9 @@
             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))
+        except:
+            self.logger.exception("Can't query for camera meta")
 
         return meta
@@ -114,5 +142,5 @@
     def getCameraStageSmf(self, camID):
 
-        self.logger.debug("Querying GPC1 for camera smf files")
+        self.logger.debug("Querying GPC1 for camera smf files with cam_id = " + str(camID))
 
         sql = "SELECT path_base \
@@ -136,5 +164,4 @@
 
             f=os.popen("neb-ls -p "+path+"/%smf")
-            print "neb-ls -p "+path+"/%smf"
             for i in f.readlines():
                 files.append(i.rstrip())
@@ -157,4 +184,5 @@
                FROM staticskyResult \
                WHERE sky_id = %d" % skyID
+
         try:
             rs = self.stmt.executeQuery(sql)
@@ -165,5 +193,5 @@
         # get path to base dir of cmf files
         path = rs.getString(1)
-        path = path[0:path.rfind("/")]
+        #path = path[0:path.rfind("/")]
        
         # list all cmf files if a neb path
@@ -171,11 +199,13 @@
         if path.startswith("neb"):
 
-            f=os.popen("neb-ls -p "+path+"/%cmf")
+            f=os.popen("neb-ls -p "+path+"%cmf")
+            print "neb-ls -p "+path+"%cmf"
             for i in f.readlines():
                 files.append(i.rstrip())
+                print i.rstrip()
 
         # or not a neb path
         else:
-            files = glob.glob(path + "/*.cmf")
+            files = glob.glob(path + "*.cmf")
 
         return files
