Index: /branches/eam_branches/ipp-20121219/ippToPsps/jython/gpc1db.py
===================================================================
--- /branches/eam_branches/ipp-20121219/ippToPsps/jython/gpc1db.py	(revision 35009)
+++ /branches/eam_branches/ipp-20121219/ippToPsps/jython/gpc1db.py	(revision 35010)
@@ -229,4 +229,5 @@
         if path.startswith("neb"):
 
+            # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
             f=os.popen("neb-ls -p "+path+"%smf")
             for i in f.readlines():
@@ -297,45 +298,75 @@
 
 
+        # print "staring stack stage cmf"
+
         # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id
         try:
             rs = self.executeQuery(sql)
             rs.first()
+        except:
+            self.logger.errorPair("Can't query for stack cmfs", "stack_id = %d" % stackID)
+            return None
+
+        try:
             pathBase = rs.getString(1)
+        except:
+            self.logger.errorPair("No stack cmf files found for stack_id = %d" % stackID)
+            return None
+
+        # find the files (are they in nebulous or in the filesystem?)
+        files = []
+        if pathBase.startswith("neb"):
+            # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
+            f=os.popen("neb-ls -p " + pathBase + "%cmf")
+            for i in f.readlines():
+                files.append(i.rstrip())
+
+        # or not a neb path
+        else:
+            files = glob.glob(pathBase + ".cmf")
+
+        # print "stack cmf files:", files
+        if len(files) < 1: return None
+
+        # if we get here, then the cmf is readable, now check the stack_id
+        fits = Fits(self.logger, self.config, files[0])
+        return fits
+
+        # XXX validate the file?
+        # if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
 
             # now find and loop through all cmf files at this path_base
-            files=os.popen("neb-ls " + pathBase + "%cmf")
-            for i in files.readlines():
-
-                nebPath = i.rstrip()
-
-                # now attempt to run 'neb-ls -p' to actually read this cmf file
-                try:
-                    self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")
-                    paths=os.popen("neb-ls -p " + nebPath)
-                    path = paths.readline().rstrip()
-                    if len(path) < 1:
-                       self.logger.debug("zero length path - skipping")
-                       raise
-
-                    # if we get here, then the cmf is readable, now check the stack_id
-                    fits = Fits(self.logger, self.config, path)
-                    if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
-                        # we have the right file!
-                        self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
-                        return fits
-                    else:
-                        # this is not the correct file
-                        self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
-
-                # an exception here means that nebulous could not read this file, so we just skip it
-                except:
-                    self.logger.debug("NEB FAILED SKIPPING")
-                    pass
-
-        except:
-            self.logger.errorPair("Can't query for stack cmfs", "stack_id = %d" % stackID)
-
-        self.logger.errorPair("Couldn't find stack cmf for", "stack_id = %d" % stackID)
-        return None
+
+            ## XXX the code below was needed when we ingested from staticsky (N files per run)
+            ## XXX ingesting from skycal solves this problem (1 file per run)
+            ## files=os.popen("neb-ls " + pathBase + "%cmf")
+            ## for i in files.readlines():
+            ##     nebPath = i.rstrip()
+            ## 
+            ##     # now attempt to run 'neb-ls -p' to actually read this cmf file
+            ##     try:
+            ##         self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")
+            ##         paths=os.popen("neb-ls -p " + nebPath)
+            ##         path = paths.readline().rstrip()
+            ##         if len(path) < 1:
+            ##            self.logger.debug("zero length path - skipping")
+            ##            raise
+            ## 
+            ##         print "starint stack stage cmf 3"
+            ## 
+            ##         # if we get here, then the cmf is readable, now check the stack_id
+            ##         fits = Fits(self.logger, self.config, path)
+            ##         if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):
+            ##             # we have the right file!
+            ##             self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
+            ##             return fits
+            ##         else:
+            ##             # this is not the correct file
+            ##             self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))
+            ## 
+            ##     # an exception here means that nebulous could not read this file, so we just skip it
+            ##     except:
+            ##         self.logger.debug("NEB FAILED SKIPPING")
+            ##         pass
 
     '''
