matrixb.source package¶
Submodules¶
matrixb.source.base module¶
-
class
matrixb.source.base.SourceBase(filename=None, worksheet=None, header_ignore=0, postheader_ignore=0, footer_ignore=0, **matrixparams)[source]¶ Bases:
object-
classmethod
export_to(matrix, destination, topmatter=None, autosize=False)[source]¶ The export_to class method is designed to export a matrixb matrix to the source type. This method is abstract in the base class, and implementers should override it to export correctly. In many cases, this will be delegated to from the Matrixb.export() method, which attempts to identify the export based on the file extension.
Parameters: - matrix (matrixb.Matrix) – The Matrix object to export.
- destination – The full path to the destination to export the data to.
- topmatter (list|str, optional) – A line or lines to appear above the exported matrix.
- autosize (bool) – This parameter may be removed in the future - the original intent was for Excel and ODS files to autosize the columns, but that’s not very generic.
TODO: Changing autosize to a more generic format configuration may be in order.
-
filename¶
-
get_matrix(worksheet=None, **additionalparams)[source]¶ Gets the matrixb.Matrix for the current parameters.
Parameters: - worksheet (str) – Specifies a worksheet name, for sources that can have multiple worksheet matrices. The default is the worksheet property; if None and there are multiple worksheets, it will choose either the active or default, based on the functions available in the underlying handler class.
- other keyword parameters will be passed directly to the matrix init call alongside any unrecognized parameters that were passed into the source's init call. It is therefore possible that invalid parameters passed into the SourceBase constructor will lead to a deferred Exception when get_matrix is called. (All) –
Returns: A matrixb.Matrix given the current parameters.
-
header_ignore¶
-
ignored_header¶
-
ignored_postheader¶
-
nonemptyre= re.compile('\\s*\\S')¶
-
postheader_ignore¶
-
worksheet¶
-
worksheets¶ Worksheets returns a list of worksheet names available for this matrix class. By default, and if it is not a traditional spreadsheet with multiple possible worksheets, it should return a 1-element list of [‘<default>’]. Otherwise, when subclassing MatrixSource, the programmer should defined _worksheets based on the possible values
-
classmethod
matrixb.source.csv module¶
-
class
matrixb.source.csv.CSV(*args, encoding='utf-8-sig', csvdialect='excel', **kwargs)[source]¶ Bases:
matrixb.source.base.SourceBase-
classmethod
export_to(matrix, filename, topmatter=None, autosize=None)[source]¶ The export_to class method to export a matrixb matrix to a CSV file.
Parameters: - matrix (matrixb.Matrix) – The Matrix object to export.
- filename (str) – The full path to send the file.
- topmatter (list|str, optional) – Lines to appear above the exported table.
- autosize – This parameter is not used, only maintained for consistency with the export_to interface.
-
classmethod
matrixb.source.googlesheet module¶
matrixb.source.resident module¶
matrixb.source.xls module¶
matrixb.source.xlsx module¶
-
class
matrixb.source.xlsx.XLSX(*args, **kwargs)[source]¶ Bases:
matrixb.source.base.SourceBase-
classmethod
export_to(matrix, filename, topmatter=None, autosize=None)[source]¶ The export_to class method to export a matrixb matrix to a modern Excel (‘.xlsx’) file.
Parameters:
-
iterator¶
-
worksheet¶
-
worksheets¶ Worksheets returns a list of worksheet names available for this matrix class. By default, and if it is not a traditional spreadsheet with multiple possible worksheets, it should return a 1-element list of [‘<default>’]. Otherwise, when subclassing MatrixSource, the programmer should defined _worksheets based on the possible values
-
classmethod
Module contents¶
-
matrixb.source.factory(source, *args, **kwargs)[source]¶ A function to allow for the generic import of any file-based source.
Parameters: - source – A key that determines the source. The following are recognized. For any other source type, instantiate the source object directly: 1. filename with a known extension (csv, ods, xls, xlsx) 2. matrix (list of lists) 3. A Google Spreadsheet ID. It is assumed that an alphanumeric character string of >10 characters that matches w{10,} is such a sheet.
- other parameters are delegated to the matrix source class without validation. It is assumed that the source class or subclass will handle them. (All) –
Returns: An object that is the appropriate descendant of SourceBase.
-
matrixb.source.find_source_class(extension=None, filename=None)[source]¶ Returns a valid source class given the paramers passed in.
Parameters: Returns: A matrixb.source.SourceBase class for the given extension, if one exists. None if the extension is identified but no source class exists.
Raises: Exception if no extension could be determined.