summaryrefslogtreecommitdiffstats
path: root/src/python/orcus/__init__.py
blob: 4914d95acbfe680b056316c75db3a17ab7ad3ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#######################################################################
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
########################################################################

try:
    from _orcus import *
    from _orcus import __version__
except ModuleNotFoundError:
    # We do this to enable sphinx to generate documentation without having to
    # build the C++ part.
    pass

from enum import Enum


class FormatType(Enum):
    """Collection of file format types currently used in orcus."""

    UNKNOWN    = 0
    ODS        = 1
    XLSX       = 2
    GNUMERIC   = 3
    XLS_XML    = 4
    CSV        = 5
    YAML       = 6
    JSON       = 7
    XML        = 8
    PARQUET    = 9


class CellType(Enum):
    """Collection of cell types stored in spreadsheet."""

    UNKNOWN = 0
    EMPTY   = 1
    BOOLEAN = 2
    NUMERIC = 3
    STRING  = 4
    STRING_WITH_ERROR = 5
    FORMULA = 6
    FORMULA_WITH_ERROR = 7


class FormulaTokenType(Enum):
    """Collection of formula token types."""

    UNKNOWN   = 0
    REFERENCE = 1
    VALUE     = 2
    NAME      = 3
    FUNCTION  = 4
    OPERATOR  = 5
    ERROR     = 6


class FormulaTokenOp(Enum):
    """Collection of formula token opcodes."""

    UNKNOWN          = 0
    SINGLE_REF       = 1
    RANGE_REF        = 2
    TABLE_REF        = 3
    NAMED_EXPRESSION = 4
    STRING           = 5
    VALUE            = 6
    FUNCTION         = 7
    PLUS             = 8
    MINUS            = 9
    DIVIDE           = 10
    MULTIPLY         = 11
    EXPONENT         = 12
    CONCAT           = 13
    EQUAL            = 14
    NOT_EQUAL        = 15
    LESS             = 16
    GREATER          = 17
    LESS_EQUAL       = 18
    GREATER_EQUAL    = 19
    OPEN             = 20
    CLOSE            = 21
    SEP              = 22
    ERROR            = 23


def get_document_loader_module(format_type):
    """Obtain a document loader module for the specified format type.

    Args:
        format_type (orcus.FormatType):
            Format type for which to load a document loader.

    Returns:
        Document loader module.
    """
    m = None
    if format_type == FormatType.ODS:
        from . import ods as m
    elif format_type == FormatType.XLSX:
        from . import xlsx as m
    elif format_type == FormatType.XLS_XML:
        from . import xls_xml as m
    elif format_type == FormatType.GNUMERIC:
        from . import gnumeric as m
    elif format_type == FormatType.CSV:
        from . import csv as m

    return m