ged2doc.writer¶
Module which defines base class for all writer classes.
Functions
|
This is no-op function, only used to mark translatable strings, to extract all strings run |
Classes
|
Base class for document writers. |
-
class
ged2doc.writer.
Writer
(flocator, tr, encoding=None, encoding_errors='strict', sort_order=<NameOrder.SURNAME_GIVEN: 'last+first'>, name_fmt=0, make_images=True, make_stat=True, make_toc=True, events_without_dates=True)[source]¶ Bases:
object
Base class for document writers.
This class knows how to extract all relevant information from GEDCOM data and convert it into output document. It defines basic structure of the produced document (sequence of section and sub-sections) and it depends on the subclasses to implement specific rendering of output information into document-specific format. Subclasses will need to implement small set of methods (see _render methods below).
- Parameters
- flocator
ged2doc.input.FileLocator
File locator instance.
- tr
ged2doc.i18n.I18N
Object supporting translation.
- encoding
str
, optional GEDCOM file encoding, if
None
then encoding is determined from file itself.- encoding_errors
str
, optional Controls error handling behavior during string decoding, one of “strict” (default), “ignore”, or “replace”.
- sort_order
ged4py.model.NameOrder
, optional Determines ordering of person in output file, one of the constants defined in
ged4py.model.NameOrder
enum.- name_fmt
int
, optional Bit mask with flags from
ged2doc.name
module.- make_images
bool
, optional If
True
(default) then generate images for persons.- make_stat
bool
, optional If
True
(default) then generate statistics section.- make_toc
bool
, optional If
True
(default) then generate Table of Contents.- events_without_dates
bool
, optional If
True
(default) then show events that have no associated dates.
- flocator
Methods
save
()Produce output document.
-
save
()[source]¶ Produce output document.
This is the main (and the only one client-callable) method of the writers, it will parse GEDCOM structure and produce output document from it.
-
_indi_sort_key
(indi)[source]¶ Return name ordering key for individual.
- Parameters
- indi
ged4py.model.Individual
INDI record representation.
- indi
- Returns
- order
tuple
[str
]
- order
-
_events
(person)[source]¶ Returns a list of events for a given person.
Returned list contains tuples (date, info).
- Parameters
- person
ged4py.model.Individual
INDI record representation.
- person
- Returns
- events
list
[tuple
] List of tuples with two elements: date and event information.
- events
-
_make_main_image
(person)[source]¶ Returns image for a person.
- Parameters
- person
ged4py.model.Individual
INDI record representation.
- person
- Returns
- image_data
bytes
orNone
Bytes of the image data or
None
.
- image_data
-
_name_freq
(people)[source]¶ Returns name frequency table.
- Parameters
- peopleiterable of
ged4py.model.Individual
Sequence of INDI records.
- peopleiterable of
- Returns
- table
list
[tuple
] List of (name, count) ordered by name.
- table
-
_format_indi_attr
(person, attrib, prefix='ATTR.')[source]¶ Formatting of the individual’s attributes.
- Parameters
- person
ged4py.model.Individual
INDI record representation.
- attrib
ged2doc.events.Event
Attribute structure.
- prefix
str
, optional Prefix added to attribute tag before translation.
- person
- Returns
- attribute
tuple
Tuple (attribute, value).
- attribute
-
_person_ref
(person, name=None)[source]¶ Returns encoded person reference.
If person is None then None is returned. If name is not given then properly formatted person full name is used.
Encoded reference consists of ASCII character SOH () followed by reference ID, STX (), person name, and ETX (). This sequence will be embedded in the text and it should be interpreted later by subclasses to produce properly formatted reference in a backend- specific format.
- Parameters
- person
ged4py.model.Individual
INDI record representation.
- name
str
, optional Name to use instead of person name.
- person
- Returns
- person_ref
str
- person_ref
-
abstract
_render_section
(level, ref_id, title, newpage=False)[source]¶ Produces new section in the output document.
This method should also save section reference so that TOC can be later produced when
_render_toc
method is called.- Parameters
- level
int
Section level (1, 2, 3, etc.).
- ref_id
str
Unique section identifier.
- title
str
Printable section name.
- newpage
bool
, optional If
True
then start new page (for documents that support pagination).
- level
-
abstract
_render_person
(person, image_data, attributes, families, events, notes)[source]¶ Output person information.
- Parameters
- person
ged4py.model.Individual
INDI record representation.
- image_data
bytes
orNone
Either
None
or binary image data (typically content of JPEG image).- attributes
list
[tuple
] List of (attr_name, text) tuples, may be empty.
- families
list
[str
] List of strings (possibly empty), each string contains description of one family and should be typically rendered as a separate paragraph.
- events
list
[tuple
] List of (date, text) tuples, may be empty. Date is properly formatted string and does not need any other formatting.
- notes
list
[str
] List of strings, each string should be rendered as separate paragraph.
- person
Notes
Textual information in parameters to this method can include references to other persons (e.g. mother/father). Such references are embedded into text in encoded format determined by
_person_ref
method. It is responsibility of the subclasses to extract these references from text and re-encode them using proper backend representation.
-
abstract
_render_name_stat
(n_total, n_females, n_males)[source]¶ Produces summary table.
Sum of male and female counters can be lower than total count due to individuals with unknown/unspecified gender.
- Parameters
- n_total
int
Total number of individuals.
- n_females
int
Number of female individuals.
- n_males
int
Number of male individuals.
- n_total
-
abstract
_render_name_freq
(freq_table)[source]¶ Produces name statistics table.
- Parameters
- freq_table
list
[tuple
] List of (name, count) tuples.
- freq_table
-
abstract
_render_toc
()[source]¶ Produce table of contents using info collected in
_render_section()
.
-
_abc_impl
= <_abc_data object>¶