def handleMatch(self, match): """ Process the input file supplied. """ # Update the settings from regex match settings = self.getSettings(match.group(4)) # Build the complete filename. # NOTE: os.path.join doesn't like the unicode even if you call str() on it first. rel_filename = match.group(2).lstrip('/') filename = MooseDocs.MOOSE_DIR.rstrip('/') + os.path.sep + rel_filename # Read the file and create element filename = self.checkFilename(rel_filename) if not filename: el = self.createErrorElement(rel_filename) elif not settings.has_key('block'): el = self.createErrorElement(rel_filename, message="Use of !input syntax while not providing a block=some_block. If you wish to include the entire file, use !text instead") else: parser = ParseGetPot(filename) node = parser.root_node.getNode(settings['block']) if node == None: content = 'ERROR: Failed to find {} in {}.'.format(match.group(3), rel_filename) else: content = node.createString() if match.group(2): label = match.group(2) else: label = rel_filename el = self.createElement(label, content, filename, rel_filename, settings) return el
def handleMatch(self, match): """ Process the input file supplied. """ # Update the settings from regex match settings = self.getSettings(match.group(3)) # Build the complete filename. rel_filename = match.group(2) filename = MooseDocs.abspath(rel_filename) # Read the file and create element if not os.path.exists(filename): el = self.createErrorElement( "The input file was not located: {}".format(rel_filename)) elif settings['block'] is None: el = self.createErrorElement( "Use of !input syntax while not providing a block=some_block. If you wish to include the entire file, use !text instead" ) else: parser = ParseGetPot(filename) node = parser.root_node.getNode(settings['block']) if node == None: el = self.createErrorElement('Failed to find {} in {}.'.format( settings['block'], rel_filename)) else: content = node.createString() label = match.group(2) if match.group(2) else rel_filename el = self.createElement(label, content, filename, rel_filename, settings) return el
def parseJobsFile(self, template_dir, job_file): jobs = [] # We expect the job list to be named "job_list" filename = template_dir + job_file try: data = ParseGetPot.readInputFile(filename) except: # ParseGetPot class print "Parse Error: " + filename return jobs # We expect our root node to be called "Jobs" if 'Jobs' in data.children: jobs_node = data.children['Jobs'] # Get the active line active_jobs = None if 'active' in jobs_node.params: active_jobs = jobs_node.params['active'].split(' ') for jobname, job_node in jobs_node.children.iteritems(): # Make sure this job is active if active_jobs != None and not jobname in active_jobs: continue # First retrieve the type so we can get the valid params if 'type' not in job_node.params: print "Type missing in " + filename sys.exit(1) params = self.factory.validParams(job_node.params['type']) params['job_name'] = jobname # Now update all the base level keys params_parsed = set() params_ignored = set() for key, value in job_node.params.iteritems(): params_parsed.add(key) if key in params: if params.type(key) == list: params[key] = value.split(' ') else: if re.match('".*"', value): # Strip quotes params[key] = value[1:-1] else: params[key] = value else: params_ignored.add(key) # Make sure that all required parameters are supplied required_params_missing = params.required_keys() - params_parsed if len(required_params_missing): print 'Required Missing Parameter(s): ', required_params_missing sys.exit(1) if len(params_ignored): print 'Ignored Parameter(s): ', params_ignored jobs.append(params) return jobs
def extractContent(self, filename, settings): """ Extract input file content with GetPot parser if 'block' is available. (override) """ if not settings['block']: return super(ListingInputPattern, self).extractContent(filename, settings) parser = ParseGetPot(filename) node = parser.root_node.getNode(settings['block']) if node is not None: return node.createString() return super(ListingInputPattern, self).extractContent(filename, settings)
def extractContent(self, filename, settings): """ Extract input file content with GetPot parser if 'block' is available. (override) """ if settings['main_comment']: with open(filename) as fid: content = fid.read() match = re.search(r'(?P<comment>.*?)\[.*?\]', content, flags=re.MULTILINE | re.DOTALL) return match.group('comment') if not settings['block']: return super(ListingInputPattern, self).extractContent(filename, settings) parser = ParseGetPot(filename) node = parser.root_node.getNode(settings['block']) if node is not None: return node.createString() return super(ListingInputPattern, self).extractContent(filename, settings)
def _createMergedInputFile(name, files, **kwargs): style = kwargs.pop('style', 'inl') title = kwargs.pop('title', None) # Create the moose.i file for containing the entire moose workshop fid = open(name, 'w') # Add the root block fid.write('[presentation]\n') fid.write(' style = ' + style + '\n') if (title != None): fid.write(' title = ' + title + '\n') # Add the blocks from the various input files for f in files: root = ParseGetPot(f).root_node.children['presentation'] for child in root.children_list: node = root.children[child] fid.write(node.createString(1) + '\n') # Close the block and file fid.write('[]\n') fid.close()