def writeTemplate(self):
     #TODO method stub
     path2Template=os.path.join(PipelineUtil.templateDir(),self.name.upper()+".sjt")
     #TODO, file conditions, should either not exist, or be a normal file
     templateFile=open(path2Template,'w')
     templateFile.write(self.toTemplateString())
     templateFile.close()
 def readTemplate(name):
     #get path
     path2Template=os.path.join(PipelineUtil.templateDir(),name.upper()+".sjt")
     #check file exists
     if not os.path.isfile(path2Template):
         raise PipelineError("Template file does not exist!: " + path2Template)
     #read file:
     templateFile=open(path2Template,'rU')
     templateLines=templateFile.readlines()
     templateFile.close()
     #process file:
     newStep=PipelineTemplate()
     newStep.name=name.upper()
     joblines=[]
     hashMatcher=re.compile(r"^#\S+$")
     varLineMatcher=re.compile(r"^#&VAR:.+$")
     varMatcher=re.compile(r"^#&VAR:(\$.+)=(.+)$")
     suffixMatcher=re.compile(r"^#&SUFFIX:(.+)$")
     typeMatcher=re.compile(r"^#&TYPE:(.+)$")
     jobtype=None
     for line in templateLines:
         line=line.strip()
         if hashMatcher.match(line):
             if varLineMatcher.match(line):
                 varMatch=varMatcher.match(line)
                 if varMatch:
                     var=varMatch.group(1)
                     val=varMatch.group(2)
                     if var in newStep.var_keys:
                         raise PipelineError("[PipelineTemplate.readTemplate] Defined variable %s twice in one template" % var)
                     newStep.var_keys.append(var)
                     newStep.vars[var]=val
                 else:
                     raise PipelineError("[PipelineTemplate.readTemplate] improperly formed VAR line in template: \n"+line)
                 continue
             suffixMatch=suffixMatcher.match(line)
             if suffixMatch:
                 if newStep.suffix is not None:
                     raise PipelineError("[PipelineTemplate.readTemplate] Job Suffix defined twice in template")
                 newStep.suffix=suffixMatch.group(1)
                 continue
             typeMatch=typeMatcher.match(line)
             if typeMatch:
                 if jobtype is not None:
                     raise PipelineError("[PipelineTemplate.readTemplate] Job Type defined twice in template")
                 jobtype=typeMatch.group(1)
                 jobtype=jobtype.upper()
                 if jobtype == "SOLO":
                     newStep.isCrossJob=False
                 elif jobtype == "CROSS":
                     newStep.isCrossJob=True
                 else:
                     raise PipelineError("[PipelineTemplate.readTemplate] improperly formed TYPE line in template: "+ line)
                 continue
             #anything that reaches this point is treated as a comment line
         else:
             joblines.append(line)
     newStep.parseSubJobs(joblines)
     return newStep;
 def loadTemplate(self,templateName):
     template=None
     #TODO: fill in stub
     if len(templateName) == 0:
         return False
     #check if step template is already loaded
     if templateName.upper() in self.jobtemplates:
         #if loaded, no more work to do
         return True;
     #if not found, check if template exists
     path2Template=os.path.join(PipelineUtil.templateDir(),templateName.upper()+".sjt")
     #print(path2Template)
     if os.path.isfile(path2Template):
         #if template exists
         template=PipelineTemplate.readTemplate(templateName.upper())
         self.jobtemplates[templateName.upper()]=template
         return True
     else:
         #if template doesn't exist, signal error
         return False
 def toString(self,grouplbl,cumsuffix,prefix,prefix2=None):
     if self.parent.isCrossJob and prefix2 is None:
         raise PipelineError("[PipelineClusterJob.toString] toString called on crossjob without prefix2 variable\n")
     return PipelineUtil.replaceVars(self.toTemplateString(),self,grouplbl,cumsuffix,prefix,prefix2)