The LibreOffice Utils Module (tendril.utils.libreoffice)

This module provides utilities to deal with LibreOffice files. Functionality is implemented lazily, so this doesn’t really do much.

Presently, whatever it does do, it does by relying on external python code, executed in a shell by subprocess. This is required since the default LibreOffice install I have only supports a python 3 API.

For details about how it actually works, look at the documentation of the sofficehelpers package. The scripts used from that package are :

  • sofficehelpers.ssconverter for converting spreadsheets to CSV files.

Todo

Publish the sofficehelpers package somewhere, or find a pre-existing alternative. If there is a functionally sufficient alternative, it will probably be better.

tendril.utils.files.libreoffice.open_files = [<tendril.utils.files.libreoffice.XLFile object>]

A list of all files currently open which the module is responsible for.

class tendril.utils.files.libreoffice.XLFile(filepath)[source]

Bases: object

This class allows reading data from LibreOffice supported Spreadsheet files, by converting each sheet into a CSV file, which can then be read by application code. Note that this is a one way conversion only. The original spreadsheet file is not written to.

When the object is instantiated, a copy of the file is made in the temporary folder by _make_copy(), which is then converted into one CSV file per sheet in the original spreadsheet file by _make_csv_files(). It then adds itself to the modules open_files list.

Parameters:

filepath – The path of the spreadsheet to be opened.

Variables:
  • fpath – The path to the original spreadsheet file.
  • fname – The file name of the original spreadsheet file.
  • _csv_list – The list of CSV files generated from the spreadsheet, one per sheet.
get_csv_path(sheetname)[source]

Gets the path to the CSV file that was created at object initialization corresponding to the sheetname provided.

Parameters:sheetname – Name of the Spreadsheet Sheet.
_make_copy()[source]

Makes a copy of the original file in the temporary directory

_make_csv_files()[source]

Converts a SpreadSheet file supported by LibreOffice into a set of CSV files, one per sheet, using the sofficehelpers.ssconverter script. The output is parsed by _parse_sscout().

_parse_sscout(string)[source]

Parses the output of the sofficehelpers.ssconverter script, extracting the Sheet names and corresponding CSV file names from the output.

close()[source]

Closes the object and removes it from the open_files list. Also runs _clean() to remove all the files it created.

_clean()[source]

Removes all temporary files created during the object instantiation.

tendril.utils.files.libreoffice.get_xlf(fpath)[source]

Gets the XLFile object for the spreadsheet at fpath, opening the file and creating the object if it does not already exist.

Parameters:fpath – Path of the spreadsheet file to open.
Returns:The opened XLFile instance.
tendril.utils.files.libreoffice.ooutils_cleanup()[source]

Called when the python interpreter is shutting down. Cleans up all tendril.utils.libreoffice related objects and other artifacts created by the module.

Performs the following tasks: