def genRef(specFile, baseDir): file = loadFile(specFile) if file is None: return # Save the path to this file for later use in rewriting relative includes specDir = os.path.dirname(os.path.abspath(specFile)) pageMap = findRefs(file, specFile) logDiag(specFile + ': found', len(pageMap.keys()), 'potential pages') sys.stderr.flush() # Fix up references in pageMap fixupRefs(pageMap, specFile, file) # Create each page, if possible for name in sorted(pageMap): pi = pageMap[name] printPageInfo(pi, file) if pi.Warning: logDiag('genRef:', pi.name + ':', pi.Warning) if pi.extractPage: emitPage(baseDir, specDir, pi, file) elif pi.type == 'enums': autoGenEnumsPage(baseDir, pi, file) elif pi.type == 'flags': autoGenFlagsPage(baseDir, pi.name) else: # Don't extract this page logWarn('genRef: Cannot extract or autogenerate:', pi.name)
def genRef(specFile, baseDir): file = loadFile(specFile) if file is None: return # Save the path to this file for later use in rewriting relative includes specDir = os.path.dirname(os.path.abspath(specFile)) pageMap = findRefs(file, specFile) logDiag(specFile + ': found', len(pageMap.keys()), 'potential pages') sys.stderr.flush() # Fix up references in pageMap fixupRefs(pageMap, specFile, file) # Create each page, if possible for name in sorted(pageMap): pi = pageMap[name] printPageInfo(pi, file) if pi.Warning: logDiag('genRef:', pi.name + ':', pi.Warning) if pi.extractPage: emitPage(baseDir, specDir, pi, file) elif pi.type == 'enums': autoGenEnumsPage(baseDir, pi, file) elif pi.type == 'flags': autoGenFlagsPage(baseDir, pi.name) else: # Don't extract this page logWarn('genRef: Cannot extract or autogenerate:', pi.name)
def genRef(specFile, baseDir): """Extract reference pages from a spec asciidoc source file. - specFile - filename to extract from - baseDir - output directory to generate page in""" # We don't care the newline format used here. file, _ = loadFile(specFile) if file is None: return # Save the path to this file for later use in rewriting relative includes specDir = os.path.dirname(os.path.abspath(specFile)) pageMap = findRefs(file, specFile) logDiag(specFile + ': found', len(pageMap.keys()), 'potential pages') sys.stderr.flush() # Fix up references in pageMap fixupRefs(pageMap, specFile, file) # Create each page, if possible pages = {} for name in sorted(pageMap): pi = pageMap[name] printPageInfo(pi, file) if pi.Warning: logDiag('genRef:', pi.name + ':', pi.Warning) if pi.extractPage: emitPage(baseDir, specDir, pi, file) elif pi.type == 'enums': autoGenEnumsPage(baseDir, pi, file) elif pi.type == 'flags': autoGenFlagsPage(baseDir, pi.name) else: # Don't extract this page logWarn('genRef: Cannot extract or autogenerate:', pi.name) pages[pi.name] = pi for alias in pi.alias.split(): pages[alias] = pi return pages
def reflowFile(filename, args): logDiag('reflow: filename', filename) lines = loadFile(filename) if lines is None: return # Output file handle and reflow object for this file. There are no race # conditions on overwriting the input, but it's not recommended unless # you have backing store such as git. if args.overwrite: outFilename = filename else: outFilename = args.outDir + '/' + os.path.basename( filename) + args.suffix try: fp = open(outFilename, 'w', encoding='utf8') except: logWarn('Cannot open output file', filename, ':', sys.exc_info()[0]) return state = ReflowState(filename, file=fp, reflow=not args.noflow, nextvu=args.nextvu) for line in lines: state.incrLineNumber() # Is this a title line (leading '= ' followed by text)? thisTitle = False # The logic here is broken. If we're in a non-reflowable block and # this line *doesn't* end the block, it should always be # accumulated. # Test for a blockCommonReflow delimiter comment first, to avoid # treating it solely as a end-Paragraph marker comment. if line == blockCommonReflow: # Starting or ending a pseudo-block for "common" VU statements. # Common VU statements use an Asciidoc variable as the apiName, # instead of inferring it from the most recent API include. state.apiName = '{refpage}' state.endParaBlockReflow(line, vuBlock=True) elif blockReflow.match(line): # Starting or ending a block whose contents may be reflowed. # Blocks cannot be nested. # Is this is an explicit Valid Usage block? vuBlock = (state.lineNumber > 1 and lines[state.lineNumber - 2] == '.Valid Usage\n') state.endParaBlockReflow(line, vuBlock) elif endPara.match(line): # Ending a paragraph. Emit the current paragraph, if any, and # prepare to begin a new paragraph. state.endPara(line) # If this is an include:: line starting the definition of a # structure or command, track that for use in VUID generation. matches = includePat.search(line) if matches is not None: generated_type = matches.group('generated_type') include_type = matches.group('category') if generated_type == 'api' and include_type in ('protos', 'structs'): apiName = matches.group('entity_name') if state.apiName != '': # This happens when there are multiple API include # lines in a single block. The style guideline is to # always place the API which others are promoted to # first. In virtually all cases, the promoted API # will differ solely in the vendor suffix (or # absence of it), which is benign. if not apiMatch(state.apiName, apiName): logWarn('Promoted API name mismatch at line', state.lineNumber, ':', 'apiName:', apiName, 'does not match state.apiName:', state.apiName) else: state.apiName = apiName elif endParaContinue.match(line): # For now, always just end the paragraph. # Could check see if len(para) > 0 to accumulate. state.endParaContinue(line) # If it's a title line, track that if line[0:2] == '= ': thisTitle = True elif blockPassthrough.match(line): # Starting or ending a block whose contents must not be reflowed. # These are tables, etc. Blocks cannot be nested. state.endParaBlockPassthrough(line) elif state.lastTitle: # The previous line was a document title line. This line # is the author / credits line and must not be reflowed. state.endPara(line) else: # Just accumulate a line to the current paragraph. Watch out for # hanging indents / bullet-points and track that indent level. state.addLine(line) state.lastTitle = thisTitle # Cleanup at end of file state.endPara(None) # Sanity check on block nesting if len(state.blockStack) > 1: logWarn('file', filename, 'mismatched asciidoc block delimiters at EOF:', state.blockStack[-1]) fp.close() # Update the 'nextvu' value if args.nextvu != state.nextvu: logWarn('Updated nextvu to', state.nextvu, 'after file', filename) args.nextvu = state.nextvu
def reflowFile(filename, args): logDiag('reflow: filename', filename) lines = loadFile(filename) if lines is None: return # Output file handle and reflow object for this file. There are no race # conditions on overwriting the input, but it's not recommended unless # you have backing store such as git. if args.overwrite: outFilename = filename else: outFilename = args.outDir + '/' + os.path.basename( filename) + args.suffix try: fp = open(outFilename, 'w', encoding='utf8') except: logWarn('Cannot open output file', filename, ':', sys.exc_info()[0]) return state = ReflowState(filename, file=fp, reflow=not args.noflow, nextvu=args.nextvu) for line in lines: state.incrLineNumber() # Is this a title line (leading '= ' followed by text)? thisTitle = False # The logic here is broken. If we're in a non-reflowable block and # this line *doesn't* end the block, it should always be # accumulated. if endPara.match(line): # Ending a paragraph. Emit the current paragraph, if any, and # prepare to begin a new paragraph. state.endPara(line) # If this is an include:: line starting the definition of a # structure or command, track that for use in VUID generation. matches = includePat.search(line) if matches is not None: include_type = matches.group('type') if include_type in ('protos', 'structs'): state.apiName = matches.group('name') elif endParaContinue.match(line): # For now, always just end the paragraph. # Could check see if len(para) > 0 to accumulate. state.endParaContinue(line) # If it's a title line, track that if line[0:2] == '= ': thisTitle = True elif blockReflow.match(line): # Starting or ending a block whose contents may be reflowed. # Blocks cannot be nested. # First see if this is an explicit Valid Usage block vuBlock = (state.lineNumber > 1 and lines[state.lineNumber - 2] == '.Valid Usage\n') state.endParaBlockReflow(line, vuBlock) elif blockPassthrough.match(line): # Starting or ending a block whose contents must not be reflowed. # These are tables, etc. Blocks cannot be nested. state.endParaBlockPassthrough(line) elif state.lastTitle: # The previous line was a document title line. This line # is the author / credits line and must not be reflowed. state.endPara(line) else: # Just accumulate a line to the current paragraph. Watch out for # hanging indents / bullet-points and track that indent level. state.addLine(line) state.lastTitle = thisTitle # Cleanup at end of file state.endPara(None) # Sanity check on block nesting if len(state.blockStack) > 1: logWarn('file', filename, 'mismatched asciidoc block delimiters at EOF:', state.blockStack[-1]) fp.close() # Update the 'nextvu' value if args.nextvu != state.nextvu: logWarn('Updated nextvu to', state.nextvu, 'after file', filename) args.nextvu = state.nextvu
def reflowFile(filename, args): logDiag('reflow: filename', filename) lines = loadFile(filename) if lines is None: return # Output file handle and reflow object for this file. There are no race # conditions on overwriting the input, but it's not recommended unless # you have backing store such as git. if args.overwrite: outFilename = filename else: outFilename = args.outDir + '/' + os.path.basename(filename) + args.suffix try: fp = open(outFilename, 'w', encoding='utf8') except: logWarn('Cannot open output file', filename, ':', sys.exc_info()[0]) return state = ReflowState(filename, file = fp, reflow = not args.noflow, nextvu = args.nextvu) for line in lines: state.incrLineNumber() # Is this a title line (leading '= ' followed by text)? thisTitle = False # The logic here is broken. If we're in a non-reflowable block and # this line *doesn't* end the block, it should always be # accumulated. if endPara.match(line): # Ending a paragraph. Emit the current paragraph, if any, and # prepare to begin a new paragraph. state.endPara(line) # If this is an include:: line starting the definition of a # structure or command, track that for use in VUID generation. matches = includePat.search(line) if matches is not None: include_type = matches.group('type') if include_type in ('protos', 'structs'): state.apiName = matches.group('name') elif endParaContinue.match(line): # For now, always just end the paragraph. # Could check see if len(para) > 0 to accumulate. state.endParaContinue(line) # If it's a title line, track that if line[0:2] == '= ': thisTitle = True elif blockReflow.match(line): # Starting or ending a block whose contents may be reflowed. # Blocks cannot be nested. # First see if this is an explicit Valid Usage block vuBlock = (state.lineNumber > 1 and lines[state.lineNumber-2] == '.Valid Usage\n') state.endParaBlockReflow(line, vuBlock) elif blockPassthrough.match(line): # Starting or ending a block whose contents must not be reflowed. # These are tables, etc. Blocks cannot be nested. state.endParaBlockPassthrough(line) elif state.lastTitle: # The previous line was a document title line. This line # is the author / credits line and must not be reflowed. state.endPara(line) else: # Just accumulate a line to the current paragraph. Watch out for # hanging indents / bullet-points and track that indent level. state.addLine(line) state.lastTitle = thisTitle # Cleanup at end of file state.endPara(None) # Sanity check on block nesting if len(state.blockStack) > 1: logWarn('file', filename, 'mismatched asciidoc block delimiters at EOF:', state.blockStack[-1]) fp.close() # Update the 'nextvu' value if args.nextvu != state.nextvu: logWarn('Updated nextvu to', state.nextvu, 'after file', filename) args.nextvu = state.nextvu