def __iter__(self): root = Element('database') root.attrib['name'] = '' schemas = {} objects = {} for (schema, obj, desc, columns) in self.retriever: try: schema_elem = schemas[schema] except KeyError: schema_elem = SubElement(root, 'schema') schema_elem.attrib['name'] = schema schemas[schema] = schema_elem try: obj_elem = objects[(schema, obj)] except KeyError: obj_elem = SubElement(schema_elem, 'relation') obj_elem.attrib['name'] = obj objects[(schema, obj)] = obj_elem SubElement(obj_elem, 'description').text = desc for (column, desc) in sorted(columns.iteritems()): col_elem = SubElement(obj_elem, 'column') col_elem.attrib['name'] = column col_elem.text = desc indent(root) yield '<?xml version="1.0" encoding="UTF-8" ?>\n' # Ensure the output is in UTF-8 encoding s = tostring(root) if isinstance(s, unicode): s = s.encode('UTF-8') yield s
def generate_settings(self): tag = self.tag doc = tag.office_document_settings( tag.office_settings(), office_version='1.1' ) doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def generate_manifest(self): tag = self.tag doc = tag.manifest_manifest( tag.manifest_file_entry(manifest_media_type=self.generate_mimetype(), manifest_full_path='/'), ( tag.manifest_file_entry(manifest_media_type=mimetype, manifest_full_path=info.filename) for (info, mimetype) in self.manifest ) ) doc = '<?xml version="1.0" encoding="%s"?>%s' % (self.encoding, tostring(doc)) return doc.encode(self.encoding)
def generate_manifest(self): tag = self.tag doc = tag.manifest_manifest( tag.manifest_file_entry( manifest_media_type=self.generate_mimetype(), manifest_full_path='/'), (tag.manifest_file_entry(manifest_media_type=mimetype, manifest_full_path=info.filename) for (info, mimetype) in self.manifest)) doc = '<?xml version="1.0" encoding="%s"?>%s' % (self.encoding, tostring(doc)) return doc.encode(self.encoding)
def execute(self, database): super(OutputPlugin, self).execute(database) # Translate any templates in the filename option now that we've got the # database if not 'filename_template' in self.options: self.options['filename_template'] = Template( self.options['filename']) self.options['filename'] = self.options[ 'filename_template'].safe_substitute({ 'db': database.name, 'dblower': database.name.lower(), 'dbupper': database.name.upper(), }) # Construct a dictionary mapping database objects to XML elements # representing those objects logging.debug('Constructing elements') self.elements = {} for db_object in database: self.make_element(db_object) # Stitch together the XML tree by adding each element to its parent logging.debug('Constructing element hierarchy') for db_object, element in self.elements.iteritems(): if db_object.parent: parent = self.elements[db_object.parent] parent.append(element) # Find the root document element, convert the document to a string with # an appropriate XML PI logging.debug('Converting output') root = self.elements[database] if self.options['indent']: indent(root) s = unicode(tostring(root)) s = '<?xml version="1.0" encoding="%s"?>\n%s' % ( self.options['encoding'], s) # Check there aren't any silly characters (control characters / binary) # lurking in the unicode version. Most codecs will blindly pass these # through but they're invalid in XML s = re.sub(r'[\x00-\x08\x0B\x0C\x0E-\x1F]+', lambda m: '?' * len(m.group()), s) s = s.encode(self.options['encoding']) # Finally, write the document to disk logging.info('Writing output to "%s"' % self.options['filename']) f = open(self.options['filename'], 'w') try: f.write(s) finally: f.close()
def generate_meta(self): tag = self.tag doc = tag.office_document_meta( tag.office_meta( tag.meta_generator('db2makedoc'), # XXX enhance this a bit ;) tag.dc_title(self.options['title']), tag.dc_description(''), # XXX fill this in? tag.dc_subject(self.database.name), tag.dc_creator(self.options['author_name']), tag.dc_date(self.created.isoformat()), tag.meta_initial_creator(self.options['author_name']), tag.meta_creation_date(self.created.isoformat())), office_version='1.1') doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def generate_meta(self): tag = self.tag doc = tag.office_document_meta( tag.office_meta( tag.meta_generator('db2makedoc'), # XXX enhance this a bit ;) tag.dc_title(self.options['title']), tag.dc_description(''), # XXX fill this in? tag.dc_subject(self.database.name), tag.dc_creator(self.options['author_name']), tag.dc_date(self.created.isoformat()), tag.meta_initial_creator(self.options['author_name']), tag.meta_creation_date(self.created.isoformat()) ), office_version='1.1' ) doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def generate_content(self): tag = self.tag doc = tag.office_document_content( tag.office_body( tag.office_text( tag.text_h(self.options['title'], text_style_name='doc_title'), tag.text_p(text_style_name='text_body'), self.generate_database(self.database), (self.generate_schema(schema) for schema in self.database.schema_list), (self.generate_relation(relation) for schema in self.database.schema_list for relation in schema.relation_list), (self.generate_trigger(trigger) for schema in self.database.schema_list for trigger in schema.trigger_list), (self.generate_routine(routine) for schema in self.database.schema_list for routine in schema.routine_list), ) ), office_version='1.1' ) doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def execute(self, database): super(OutputPlugin, self).execute(database) # Translate any templates in the filename option now that we've got the # database if not 'filename_template' in self.options: self.options['filename_template'] = Template(self.options['filename']) self.options['filename'] = self.options['filename_template'].safe_substitute({ 'db': database.name, 'dblower': database.name.lower(), 'dbupper': database.name.upper(), }) # Construct a dictionary mapping database objects to XML elements # representing those objects logging.debug('Constructing elements') self.elements = {} for db_object in database: self.make_element(db_object) # Stitch together the XML tree by adding each element to its parent logging.debug('Constructing element hierarchy') for db_object, element in self.elements.iteritems(): if db_object.parent: parent = self.elements[db_object.parent] parent.append(element) # Find the root document element, convert the document to a string with # an appropriate XML PI logging.debug('Converting output') root = self.elements[database] if self.options['indent']: indent(root) s = unicode(tostring(root)) s = '<?xml version="1.0" encoding="%s"?>\n%s' % (self.options['encoding'], s) # Check there aren't any silly characters (control characters / binary) # lurking in the unicode version. Most codecs will blindly pass these # through but they're invalid in XML s = re.sub(r'[\x00-\x08\x0B\x0C\x0E-\x1F]+', lambda m: '?'*len(m.group()), s) s = s.encode(self.options['encoding']) # Finally, write the document to disk logging.info('Writing output to "%s"' % self.options['filename']) f = open(self.options['filename'], 'w') try: f.write(s) finally: f.close()
def generate_content(self): tag = self.tag doc = tag.office_document_content(tag.office_body( tag.office_text( tag.text_h(self.options['title'], text_style_name='doc_title'), tag.text_p(text_style_name='text_body'), self.generate_database(self.database), (self.generate_schema(schema) for schema in self.database.schema_list), (self.generate_relation(relation) for schema in self.database.schema_list for relation in schema.relation_list), (self.generate_trigger(trigger) for schema in self.database.schema_list for trigger in schema.trigger_list), (self.generate_routine(routine) for schema in self.database.schema_list for routine in schema.routine_list), )), office_version='1.1') doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def generate_styles(self): tag = self.tag doc = tag.office_document_styles( tag.style_font_face_decls( tag.style_font_face( style_font_family_generic=family, svg_font_family='"%s"' % name, style_font_pitch=pitch, style_name=name ) for (family, pitch, name) in ( ('roman', 'variable', 'Times New Roman'), ('swiss', 'variable', 'Arial'), ('system', 'variable', 'Arial'), ) ), tag.office_master_styles( tag.style_master_page(style_name='Standard', style_page_layout_name='pm1') ), tag.office_automatic_styles( tag.style_style( tag.style_text_properties(fo_font_weight='bold'), style_name='bold', style_family='text' ), tag.style_style( tag.style_text_properties(fo_font_style='italic'), style_name='italic', style_family='text' ), tag.style_style( tag.style_text_properties( style_text_underline_color='font-color', style_text_underline_style='solid', style_text_underline_width='auto' ), style_name='underline', style_family='text' ), ), tag.office_styles( tag.style_default_style( tag.style_paragraph_properties( style_link_break='strict', style_punctuation_wrap='hanging', style_tab_stop_distance='0.25in', style_text_autospace='ideograph-alpha', style_writing_mode='page', fo_hyphenation_ladder_count='no-limit' ), tag.style_text_properties( fo_language='en', fo_country='US', style_font_name='Times New Roman', fo_font_size='12pt', style_letter_kerning='true', fo_hyphenate='false', fo_hyphenation_push_char_count=2, fo_hyphenation_remain_char_count=2, style_use_window_font_color='true', style_script_type='ignore' ), style_family='paragraph' ), tag.style_default_style( tag.style_table_properties(style_border_model='collapsing'), style_family='table' ), tag.style_default_style( tag.style_table_row_properties(fo_keep_together='auto'), style_family='table-row' ), tag.style_default_style( tag.style_table_column_properties(style_use_optimal_column_width='true'), style_family='table-column' ), tag.style_style( style_name='standard', style_display_name='Standard', style_class='text', style_family='paragraph' ), tag.style_style( tag.style_paragraph_properties(fo_margin_bottom='0.1in', fo_margin_top='0in'), style_name='text_body', style_display_name='Body Text', style_parent_style_name='standard', style_class='text', style_family='paragraph' ), tag.style_style( tag.style_paragraph_properties(fo_margin_bottom='0.1in', fo_margin_top='0.2in', fo_keep_with_next='always'), tag.style_text_properties(style_font_name='Arial', fo_font_size='14pt'), style_name='heading', style_parent_style_name='standard', style_next_style_name='text_body', style_class='text', style_family='paragraph' ), tag.style_style( tag.style_text_properties(fo_font_size='24pt', fo_font_weight='bold'), style_name='doc_title', style_display_name='Document Title', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph' ), tag.style_style( tag.style_text_properties(fo_font_size='18pt', fo_font_weight='bold'), style_name='heading_1', style_display_name='Heading 1', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph', style_default_outline_level=1 ), tag.style_style( tag.style_text_properties(fo_font_size='14pt', fo_font_weight='bold'), style_name='heading_2', style_display_name='Heading 2', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph', style_default_outline_level=2 ), tag.style_style( tag.style_text_properties(fo_font_size='12pt', fo_font_weight='bold'), style_name='heading_3', style_display_name='Heading 3', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph', style_default_outline_level=3 ), tag.style_style( style_name='list', style_display_name='List', style_parent_style_name='text_body', style_class='list', style_family='paragraph' ), tag.style_style( tag.style_paragraph_properties(text_line_number=0, text_number_lines='false'), style_name='table_contents', style_display_name='Table Contents', style_parent_style_name='standard', style_class='extra', style_family='paragraph' ), tag.style_style( tag.style_section_properties( tag.style_columns(fo_column_count=1, fo_column_gap='0in'), tag.style_background_image(), style_editable='false', text_dont_balance_text_columns='false', fo_background_color='transparent' ), style_name='section', style_display_name='Section' ) ), office_version='1.1' ) doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def generate_styles(self): tag = self.tag doc = tag.office_document_styles( tag.style_font_face_decls( tag.style_font_face(style_font_family_generic=family, svg_font_family='"%s"' % name, style_font_pitch=pitch, style_name=name) for (family, pitch, name) in ( ('roman', 'variable', 'Times New Roman'), ('swiss', 'variable', 'Arial'), ('system', 'variable', 'Arial'), )), tag.office_master_styles( tag.style_master_page(style_name='Standard', style_page_layout_name='pm1')), tag.office_automatic_styles( tag.style_style( tag.style_text_properties(fo_font_weight='bold'), style_name='bold', style_family='text'), tag.style_style( tag.style_text_properties(fo_font_style='italic'), style_name='italic', style_family='text'), tag.style_style(tag.style_text_properties( style_text_underline_color='font-color', style_text_underline_style='solid', style_text_underline_width='auto'), style_name='underline', style_family='text'), ), tag.office_styles( tag.style_default_style(tag.style_paragraph_properties( style_link_break='strict', style_punctuation_wrap='hanging', style_tab_stop_distance='0.25in', style_text_autospace='ideograph-alpha', style_writing_mode='page', fo_hyphenation_ladder_count='no-limit'), tag.style_text_properties( fo_language='en', fo_country='US', style_font_name='Times New Roman', fo_font_size='12pt', style_letter_kerning='true', fo_hyphenate='false', fo_hyphenation_push_char_count=2, fo_hyphenation_remain_char_count=2, style_use_window_font_color='true', style_script_type='ignore'), style_family='paragraph'), tag.style_default_style(tag.style_table_properties( style_border_model='collapsing'), style_family='table'), tag.style_default_style( tag.style_table_row_properties(fo_keep_together='auto'), style_family='table-row'), tag.style_default_style(tag.style_table_column_properties( style_use_optimal_column_width='true'), style_family='table-column'), tag.style_style(style_name='standard', style_display_name='Standard', style_class='text', style_family='paragraph'), tag.style_style(tag.style_paragraph_properties( fo_margin_bottom='0.1in', fo_margin_top='0in'), style_name='text_body', style_display_name='Body Text', style_parent_style_name='standard', style_class='text', style_family='paragraph'), tag.style_style( tag.style_paragraph_properties(fo_margin_bottom='0.1in', fo_margin_top='0.2in', fo_keep_with_next='always'), tag.style_text_properties(style_font_name='Arial', fo_font_size='14pt'), style_name='heading', style_parent_style_name='standard', style_next_style_name='text_body', style_class='text', style_family='paragraph'), tag.style_style(tag.style_text_properties( fo_font_size='24pt', fo_font_weight='bold'), style_name='doc_title', style_display_name='Document Title', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph'), tag.style_style(tag.style_text_properties( fo_font_size='18pt', fo_font_weight='bold'), style_name='heading_1', style_display_name='Heading 1', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph', style_default_outline_level=1), tag.style_style(tag.style_text_properties( fo_font_size='14pt', fo_font_weight='bold'), style_name='heading_2', style_display_name='Heading 2', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph', style_default_outline_level=2), tag.style_style(tag.style_text_properties( fo_font_size='12pt', fo_font_weight='bold'), style_name='heading_3', style_display_name='Heading 3', style_parent_style_name='heading', style_next_style_name='text_body', style_class='text', style_family='paragraph', style_default_outline_level=3), tag.style_style(style_name='list', style_display_name='List', style_parent_style_name='text_body', style_class='list', style_family='paragraph'), tag.style_style(tag.style_paragraph_properties( text_line_number=0, text_number_lines='false'), style_name='table_contents', style_display_name='Table Contents', style_parent_style_name='standard', style_class='extra', style_family='paragraph'), tag.style_style(tag.style_section_properties( tag.style_columns(fo_column_count=1, fo_column_gap='0in'), tag.style_background_image(), style_editable='false', text_dont_balance_text_columns='false', fo_background_color='transparent'), style_name='section', style_display_name='Section')), office_version='1.1') doc = unicode(tostring(doc)) return doc.encode(self.encoding)
def generate_settings(self): tag = self.tag doc = tag.office_document_settings(tag.office_settings(), office_version='1.1') doc = unicode(tostring(doc)) return doc.encode(self.encoding)