pybill.lib.config package¶
pybill.lib.config package contains all the code that manages the
configurations.
The only public class that should be used outside of this package is the
ConfigRegister class that is imported and
available in the namespace of this package.
register module¶
pybill.lib.config.register module defines the class that manages the
various configuration objects used during a PyBill run.
This class is the only public class of the pybill.lib.config package and
should be the only one used outside this package.
-
class
pybill.lib.config.register.ConfigRegister¶ Class containing the various configuration objects read by PyBill.
A configuration object is an instance of
ConfigDataclass. This register is used to get the correct configuration specified by an accounting document in its processing instruction. The register is also responsible for finding the configuration files and storing them after indexing them with their file name.Basically, the configuration files can be found in three places:
- specified on the command-line (they are then stored in any directory),
- specified in the processing instruction inside an accounting document and
stored in the user configuration directory (
~/.config/pybill/), - specified in the processing instruction inside an accounting document and
stored in the system configuration directory
(
/etc/pybill/config/).
-
configs¶ Attribute containing a dictionary that stores the configuration objects read from the disk, indexed by their reference.
- type: dictionary of
ConfigData - indexed with
unicodekeys
- type: dictionary of
-
SYSTEM_CONFIG_DIR¶ Class constant containing the name of the system directory that contains the PyBill config files. Is currently u”/etc/pybill/config/”.
type:
unicode
-
USER_CONFIG_DIR¶ Class constant containing the name of the user directory that contains the PyBill config files. Is currently u”~/.config/pybill/”.
type:
unicode
-
DEFAULT_CONFIG_REF¶ Class constant containing the reference of the default configuration. This reference is the name of the file that contains this configuration. Is currently u”default”.
type:
unicode
-
__init__()¶ Intializes a new object.
Actually there is only one single object for PyBill that manages the configurations.
-
DEFAULT_CONFIG_REF= u'default'
-
SYSTEM_CONFIG_DIR= u'/etc/pybill/config/'
-
USER_CONFIG_DIR= u'~/.config/pybill/'
-
find_config_file(config_ref)¶ Finds the file containing the configuration whose name is
config_ref.config_refcan directly be a file or can be a reference to a file located in~/.config/pybill/or in/etc/pybill/config/. In that last case, the file name is{config_ref}.xml.If the file can’t be found, returns None.
Parameters: config_ref ( unicode) – Reference of the configuration whose file must be found.Returns: The absolute path of the file containing the configuration whose name is config_ref. ReturnsNoneif the file can’t be found.Return type: unicode
-
get_config(config_ref)¶ Gets the configuration whose reference is
config_ref.If this configuration has already been read and is stored inside this object, directly returns it. Else, tries to find the file containing the desired configuration, reads it, stores it for further uses and returns it.
Parameters: config_ref ( unicode) – Reference of the desired configuration.Returns: Configuration object whose name is config_ref.Return type: ConfigData
-
store_config(config_ref, config_filename)¶ Stores a new configuration associated to the reference
config_ref.This configuration is described in the file
config_filenameand therefore must be read and stored in aConfigDataobject before being stored in this object.Parameters: - config_ref (
unicode) – reference of the configuration that will be added in this object. - config_filename (
unicode) – Absolute path of the file containing the configuration that will be added in this object.
- config_ref (
entities module¶
pybill.lib.config.entities module defines the class used to encapsulate the
configuration data.
-
class
pybill.lib.config.entities.ConfigData¶ Class holding the configuration data.
This configuration data is used to write the accounting documents in a PDF format. It mainly contains the company address and the localised words for the accounting documents.
-
reference¶ - Attribute defining the reference of the configuration that is used to store it in the configuration register. This reference is unique among configurations and matches the name of the XML file where the configuration is stored. It is also used to link the accounting XML documents with this configuration through the PyBill processing instruction.
type:class:unicode
-
name¶ Attribute defining the name of the configuration. The name can be used when displaying a list of the various configurations and is more explicit that the reference.
type:
unicode
-
company_logo¶ Attribute defining the name of the file containing the company logo (an image). This logo will be displayed on every PDF document.
type:
str
-
company_address¶ Attribute containing the specific object that describes the company address.
type:
OrganisationAddress
Attribute containing the list of the lines to be written in the footer of all the PDF documents.
type: list of
unicode
-
bank_data_lines¶ Attribute containing the list of the lines that describe the bank data. This information will be written on the PDF documents that require a payment from the client (bill, etc.)
type: list of
unicode
-
agreement_intro_lines¶ Attribute containing the list of the agreement lines to be written on the pro-forma PDF document (e.g. u”sign here”).
type: list of
unicode
-
number_separators¶ Attribute containing a dictionnary describing the characters used to format the numbers in the PDF output. There are three separators corresponding to the three keys of the dictionary:
u"sign"contains the character separating the sign and the non-signed part of the number,u"thousands"contains the character separating the thousands and the hundreds, the millions and the hundreds of thounsands, and so on,u"digits"contains the character separating the integer part of the number and the digits.
An example of
number_separatorsdictionnary is{u"sign": u"", u"thousands": u" ", \ u"digits": u"."}`type: dictionary of
unicodeindexed withunicodekeys
-
local_phrases¶ Attribute containing a dictionary whose keys are the keywords used in PyBill and whose values are the localized phrases corresponding to these keywords (e.g. u”bill”: u”Facture”).
type: dictionary of
unicodeindexed withunicodekeys
-
__init__()¶ Intializes a new object.
This object is empty and will be filled when reading an XML configuration file (cf.
ConfigXMLReader).
-
get_local_phrase(keyword)¶ Gets the local phrase corresponding to the keyword
keyword.If the keyword is not defined in the configuration data, returns the keyword itself between two
#characters (and doesn’t raise any exception).Parameters: keyword ( unicode) – keyword that must be localized. Can be for example u”bill”).Returns: The localized phrase associated to the given keyword in the configuration data. Return type: unicode
-
xmlreaders module¶
pybill.lib.config.xmlreaders module contains the function used for reading
config XML files.
This function uses the lxml library to read the XML data. The
information read from one XML file is stored in a
ConfigData object.
-
pybill.lib.config.xmlreaders.load_config(xml_file)¶ Loads the configuration data contained in the file
xml_file, stores it in aConfigDataobject, and returns the new object.The
lxmllibrary is used to read the data from the XML.Parameters: xml_file ( unicode) – name of the XML file containing the configuration data.Returns: A new configuration object filled with the data read in the XML file. Return type: ConfigData
xmlwriters module¶
pybill.lib.config.xmlwriters module contains the function used for writing
ConfigData objects into XML files.
This dump operation uses the lxml library.
-
pybill.lib.config.xmlwriters.save_config(cfg_data, xml_file, encoding=u'UTF-8')¶ Saves the configuration data contained in the
cfg_dataobject into thexml_filefile.The
lxmllibrary is used to write the XML data.Parameters: - cfg_data (
ConfigData) – Configuration object to be saved in XML. - xml_file (
unicode) – name of the XML file that will be written. data. Actually, this name is built from the reference of the configuration data. - encoding (
str) – Encoding used to write the XML file.
- cfg_data (