def join_children(self, path, lang1, c1_list, lang2, c2_list): c_list = [] for i,c1 in enumerate( self.require_identical_list_len(path, lang1, c1_list, lang2, c2_list) ): c2 = c2_list[i] c_path = path + [str(i + 1)] c = {} self.require_identical_dict_keys(c_path, lang1, c1, lang2, c2, ACCEPTED_CHILDREN_DEFAULT_KEYS) key = join_keys(lang1, c1.get('key', ''), lang2, c2.get('key', '')) for k,v in c1.items(): if k == 'key': c[k] = key elif k in ('name', 'title', 'static_content'): c[k] = join_values(lang1, v, lang2, c2.get(k, v)) elif k == 'config': e1 = yaml_writer.read(yaml_writer.file_path(self.app.env, v)) e2 = yaml_writer.read(yaml_writer.file_path(self.app.env, c2.get(k, v))) yaml_writer.write( yaml_writer.file_path(self.app.env, key), self.join_exercises(key, lang1, e1, lang2, e2) ) c[k] = key + '.yaml' elif k == 'children': c[k] = self.join_children(c_path, lang1, v, lang2, c2.get(k, [])) elif deep_equals(v, c2.get(k, v)): c[k] = v else: self.raise_unequal(c_path, lang2, k) c_list.append(c) return c_list
def write(app, exception): ''' Writes the table of contents level configuration. ''' if app.builder.name != 'html': # course configuration YAML is only built with the Sphinx HTML builder # because some parts of the YAML generation have only been implemented # in the visit methods of the HTML builder (aplus_nodes functions # visit_html and depart_html) return if exception: return root = app.env.get_doctree(app.config.master_doc) # Check for language tree. tocs = root.traverse(addnodes.toctree) keys = set() if tocs and tocs[0].get('rawcaption') == u'Select language': app.info('Detected language tree.') indexes = [] for docname, _, doc in traverse_tocs(app, root): i = docname.rfind('_') if i < 0: raise SphinxError( 'Language postfix is required (e.g. docname_en): ' + docname) lang = docname[(i + 1):] app.info( 'Traverse document elements to write configuration index ({}).' .format(lang)) index = make_index(app, doc) yaml_writer.write(yaml_writer.file_path(app.env, 'index_' + lang), index) indexes.append((lang, index)) app.info('Joining language tree to one index.') index = toc_languages.join(app, indexes) append_manual_content(app, index) yaml_writer.write(yaml_writer.file_path(app.env, 'index'), index) keys |= set(m['key'] for m in index['modules']) else: app.info('Traverse document elements to write configuration index.') index = make_index(app, root) append_manual_content(app, index) yaml_writer.write(yaml_writer.file_path(app.env, 'index'), index) keys |= set(m['key'] for m in index['modules']) # Rewrite links for remote inclusion. app.info('Retouch all files to rewrite links.') keys |= {'toc', 'user', 'account'} html_tools.rewrite_outdir(app.outdir, keys, app.config.static_host)
def write_yaml(self, env, name, data_dict, data_type=None): ''' Adds configuration data and requests write into a file. ''' self.set_yaml(data_dict, data_type) self.yaml_write = yaml_writer.file_path(env, name)