From: Willie S. <scp...@gm...> - 2013-12-09 22:46:47
|
Im still having problems with this. Because the Transform is executed at the end of each doctree processing, i can't use them. Based on what im trying to do with this extension, its absolutely essential that it be called only after all the files have been converted to doctrees. There's no hope of this thing working correctly without that. The first event that fires after all the pages are read is envupdated. So i hooked a method into that. I can successfully read my docfiles, find the nodes i want to manipulate, and i can update them. All of that works just fine. But, once all of that is done, I can't figure out how to save the doctree for the writers. Maybe if its possible to open a doctree like this doctree = env.get_doctree('prudhoe') and then somehow reinitialize the transforms on that doctree, i may be able to make that work, but so far the transforms array has been null. i suspect because that array was loaded by something else buried deep in the api. here's my method def trip_envupdated(self, env): print("trip_envupdated") print(env) doctree = env.get_doctree('prudhoe') print(type(doctree)) keepLoop = True # im checking this because I only want this processed once if not doctree.settings.env.config.tripday_processed_nodes: for origNode in doctree.traverse(tripday): print("++++++++++++") print(origNode) if isinstance(origNode, Node): print("its a node") #index = doctree.index(node) #print(index) updateNode = origNode.deepcopy() next_node = updateNode.next_node(ascend=True) pprint.pprint(next_node) #print(type(next_node)) if (next_node is not None and ((not isinstance(next_node, nodes.Invisible) and not isinstance(next_node, nodes.Targetable)) or isinstance(next_node, nodes.target))): "work with it based on what type it is." if type(next_node) is title: print("Its a title node") sub = next_node.next_node(ascend=True) sub_rep = Text("test: " + updateNode['ids'][0]) next_node.replace(sub, sub_rep) #tripArrayEntry['refid'] = refid print("orig") print(origNode) print("new") print(updateNode) origNode.replace_self(updateNode) #doctree.replace(origNode, node) print("===============") #core.publish_from_doctree(doctree) # save the parsed doctree doctree_filename = path.join(self.doctreedir, 'prudhoe.doctree') print(doctree_filename) dirname = path.dirname(doctree_filename) if not path.isdir(dirname): os.makedirs(dirname) with file(doctree_filename, 'wb') as f: pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL) #doctree2 = env.get_doctree('prudhoe') #print("get second copy") #print(doctree2) but, i get this error pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL) PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed Lots of debugging code, i know, but regardless, i find it really tough to believe that this is impossible. Surly im not the first to ever try this, am I What am i doing wrong here? thanks |