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 modulesopen_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_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.
-
tendril.utils.files.libreoffice.
get_xlf
(fpath)[source]¶ Gets the
XLFile
object for the spreadsheet atfpath
, 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:
- Closes all
open_files
- Closes all