def substeps(self, primname, context): self.memtrack(primname, "START") # print "RO184: primstype_order = %s" % self.primstype_order savedLocalparms = context.localparms context.status = "RUNNING" prevprimname = self.curPrimName self.curPrimName = primname # check to see current primitive set type is correct correctPrimType = self.recipeLib.discover_correct_prim_type(context) # will be NONE if there are no current inputs, maintain current # curPrimType if correctPrimType and correctPrimType != self.curPrimType: # print "RO98:", repr(correctPrimType), repr(self.curPrimType) newprimset = self.recipeLib.retrieve_primitive_set(astrotype=correctPrimType) self.add_prim_set(newprimset, add_to_front=True) self.curPrimType = correctPrimType self.recipeLib.check_and_bind(self, primname, context=context) primset = self.get_prim_set(primname) if hasattr(primset, primname): prim = eval("primset.%s" % primname) else: msg = "There is no recipe or primitive named \"%s\" in %s" % \ (primname, str(repr(self))) self.curPrimName = prevprimname raise ReductionExcept(msg) # set type of prim for logging btype = primset.btype logstring = "%s: %s" % (btype,primname) if context['index'] == None: # top-level recipe, set indent=0, add some extra demarcation logutils.update_indent(0, context['logmode']) context.update({'index':0}) log.status( COLORSTR("="*80, "blue", "on_white")) if primname.startswith('proxy'): log.debug(logstring) else: log.status(logstring) log.status(COLORSTR("="*80, "blue", "on_white")) else: if btype=="RECIPE": # if it is a proxy recipe, log only at debug level, if primname.startswith('proxy'): log.debug(logstring) else: # increase the index indx = context['index'] + 1 context.update({'index':indx}) logutils.update_indent(indx, context['logmode']) log.status(COLORSTR(logstring, "blue")) log.status(COLORSTR("=" * len(logstring), "blue")) else: indx = context['index'] + 1 context.update({'index':indx}) logutils.update_indent(indx, context['logmode']) log.status(COLORSTR(logstring, "green", "on_white")) log.status(COLORSTR("-" * len(logstring), "green")) # primset init should perhaps be called ready # because it needs to be called each step because though # this primset may have been initted, it takes the context # which may have changed primset.init(context) context.parameter_collate(self.curPrimType, primset, primname) from RecipeManager import SettingFixedParam nonStandardStream = None if context["stream"] != None: # print "RO132: got stream arg", context["stream"] nonStandardStream = context.switch_stream(context["stream"]) context.begin(primname) try: #2.6 feature #if inspect.isgeneratorfunction(prim): # print "it's a primitive" #else: # print "it's not a primitive" begin_step_report = { "status":"normal", "module": primset.__module__, "step_name":primname, "primset": { "prim_name":prim.__name__, "settype":primset.astrotype }, "_reporter":__name__, "depth":context["index"] if "index" in context else [-1], } context.report_qametric(begin_step_report, "begin_step") for rc in prim(context): # @@note: call the command clause callback here # @@note2: no, this yields and the command loop act that way # @@.....: and it is in run, which caps the yields which must # @@.....: call the command clause. # problem, creates a lot of noisy entries due to # recipies and subrecipes --> self.memtrack(primname, "YIELD") # needs to be made smarter # @@PLANS: it used to be yeild rc was required # @@ : but now returning None is ok # @@ : the code below implements this. Returning rc allows # @@ : things like `yield rc.finish()` if rc == None: rc = context if False: raise ReductionExcept( "Primitive '%s' returned None for rc on yield\n" % primname) rcmd = rc.pop_return_command() if rcmd == "return_from_recipe": rc.terminate_primitive() break if rcmd == "terminate_primitive": break if rc.is_finished(): break yield rc gc.collect() # @@MEM end_step_report = { "status":"normal", "module": primset.__module__, "step_name":primname, "primset": { "prim_name":prim.__name__, "settype":primset.astrotype }, "depth":context["index"] if "index" in context else [-1], "_reporter":__name__, } context.report_qametric(end_step_report, "end_step") except SettingFixedParam, e: print str(e)
}, "depth":context["index"] if "index" in context else [-1], "_reporter":__name__, } context.report_qametric(end_step_report, "end_step") except SettingFixedParam, e: print str(e) except TypeError,e: print 'Recieved TypeError: "%s" during iteration' % e msg = "The running primitive, '%s'." % primname raise # IterationError(msg) except: print COLORSTR("recipe: '%(name)s' failed due to an exception." %{'name':primname}, "yellow", "on_red", ["bold"]) logutils.update_indent(0, context['logmode']) failreport = { "status":"error", "module":primset.__module__, "step_name":primname, "failure_type": "python exception", "primset": { "prim_name":prim.__name__, "settype":primset.astrotype }, "depth":context["index"] if "index" in context else [-1], "exception": tb.format_exc() } context.report_qametric(failreport, "failure_report") raise context.curPrimName = None self.curPrimName = prevprimname