def include_file(self,name,encoding=None): "Include an interscruot file" if 'input' in self.process.trace: print('input from',name) file_signature = (self.depth+1,'interscript',name) if file_signature in self.pass_frame.skiplist: print('SKIPPING INCLUDE FILE',file_signature) i = 0 t = self.master.src_tree n = len(t) while i<n: if file_signature == tuple(t[i][0:3]): break i = i + 1 if i == n: print('COULD NOT FIND SKIP FILE',file_signature,'in',t) else: self.pass_frame.include_files.append(file_signature) i = i + 1 lev = file_signature[0] while i<n: if t[i][0] >= lev: break print('INSERTING',t[i][2],'into include file list (cheating)') self.pass_frame.include_files.append(tuple(t[i][0:3])) i = i + 1 else: self.pass_frame.include_files.append(file_signature) if encoding is None: encoding = self.source.encoding_name self.include_source(named_file_source( self.pass_frame,name, self.source.directory, encoding=encoding))
def sink_verbatim(self, filename): "Write code in an external file directly to the tanglers driver" self.current_weaver.label_chunk(filename) source = named_file_source(self.pass_frame, filename, self.source.directory) data = source.readlines() self.current_tangler.sink.writelines(data)
def include_file(self, name, encoding=None): "Include an interscruot file" if 'input' in self.process.trace: print('input from', name) file_signature = (self.depth + 1, 'interscript', name) if file_signature in self.pass_frame.skiplist: print('SKIPPING INCLUDE FILE', file_signature) i = 0 t = self.master.src_tree n = len(t) while i < n: if file_signature == tuple(t[i][0:3]): break i = i + 1 if i == n: print('COULD NOT FIND SKIP FILE', file_signature, 'in', t) else: self.pass_frame.include_files.append(file_signature) i = i + 1 lev = file_signature[0] while i < n: if t[i][0] >= lev: break print('INSERTING', t[i][2], 'into include file list (cheating)') self.pass_frame.include_files.append(tuple(t[i][0:3])) i = i + 1 else: self.pass_frame.include_files.append(file_signature) if encoding is None: encoding = self.source.encoding_name self.include_source( named_file_source(self.pass_frame, name, self.source.directory, encoding=encoding))
def sink_verbatim(self,filename): "Write code in an external file directly to the tanglers driver" self.current_weaver.label_chunk(filename) source = named_file_source( self.pass_frame, filename, self.source.directory) data = source.readlines() self.current_tangler.sink.writelines(data)
def include_code(self, name, current_tangler): "Insert code in an external file into a nominated tangler stream" ifdata = (self.depth + 1, 'code: ' + current_tangler.language, name) self.pass_frame.include_files.append(ifdata) r = [] source = named_file_source(self.pass_frame, name, self.source.directory) inpt = input_frame(self.pass_frame, source, r, self.current_weaver, self.userdict.copy(), self.depth + 1) r.append([inpt.any_line_re, inpt.do_web]) inpt.select(current_tangler) inpt.file_pass()
def insert_code(self,name): "Insert code in an external file into the tangler stream" ifdata = (self.depth+1,'code: '+self.current_tangler.language,name) self.pass_frame.include_files.append(ifdata) r = [] source = named_file_source(self.pass_frame,name, self.source.directory) inpt = input_frame( self.pass_frame, source, r, self.current_weaver, self.userdict.copy(), self.depth+1) r.append([inpt.any_line_re, inpt.do_web]) inpt.select(self.current_tangler) inpt.file_pass()
def __init__(self,master, passno, skiplist): self.skiplist = skiplist # the display self.master = master self.process = master.process if 'frames' in self.process.trace: self.process.acquire_object(self, 'PASS FRAME') self.passno = passno self.inhibit_sref = master.inhibit_sref self.ids = {} self.flist = [] self.fdict = {} self.iflist = [] self.toc = [] self.include_files = [] self.classes = {} self.functions = {} self.testno = 0 self.sequence = 0 self.tests = {} self.section_index = {} self.ftp_list = [] file = self.master.filename encoding = self.master.encoding encoding = encoding.lower().replace('-','_') if 'frames' in self.process.trace: print('Processing',file,'Pass',passno+1,'Encoding',encoding) basename = file if file.find('.') != -1: basename = '.'.join(file.split('.')[:-1]) weaver = None userdict = { } try: input_file =named_file_source(self,file, self.master.source_prefix, encoding = encoding) except source_open_error as filename: print('Cannot Open File',filename,'for input (ignored)') raise except KeyboardInterrupt: raise except: print("Program error opening",file) traceback.print_exc() raise self.include_files.append((1,'interscript',file)) inpt = input_frame( self, input_file, [], weaver, userdict, 1) del input_file del weaver del userdict inpt.set_warning_character(python='@') if 'input' in self.process.trace: print('input from',inpt.source.get_source_name()) inpt.file_pass() # at this point, inpt, weaver, userdict, input_file # should all be released (even if 'pass_frame' is held onto, # these symbols are defined in the __init__ function frame) del inpt try: raise eoi except: pass