Completed
Pull Request — master (#22)
by Oleg
01:18
created

sdoc.format.HtmlFormat._read_configuration()   A

Complexity

Conditions 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 20
rs 9.2
1
"""
0 ignored issues
show
Bug introduced by
There seems to be a cyclic import (sdoc -> sdoc.SDoc -> sdoc.sdoc2.SDoc2Interpreter).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
Bug introduced by
There seems to be a cyclic import (sdoc -> sdoc.SDoc -> sdoc.sdoc1.SDoc1Interpreter -> sdoc.sdoc1.SDoc1visitor).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc1.data_type.ArrayDataType:169
==sdoc.sdoc1.data_type.IntegerDataType:68
def is_constant(self):
"""
Returns False always.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_defined(self):
"""
Returns True always.

:rtype: bool
"""
return True

# ------------------------------------------------------------------------------------------------------------------
def is_scalar(self):
"""
Returns True always.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_true(self):
"""
Returns True if this integer is not 0. Returns False otherwise.

:rtype: bool
"""
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc2.node.ItemNode:40
==sdoc.sdoc2.node.ItemizeNode:41
def get_hierarchy_level(self, parent_hierarchy_level=-1):
"""
Returns parent_hierarchy_level.

:param int parent_hierarchy_level: The level of the parent in the hierarchy.

:rtype: int
"""
self._hierarchy_level = parent_hierarchy_level + 1

return self._hierarchy_level

# ------------------------------------------------------------------------------------------------------------------
def get_hierarchy_name(self):
"""
Returns 'item'

:rtype: str
"""
return 'item'

# ------------------------------------------------------------------------------------------------------------------
def is_block_command(self):
"""
Returns False.

:rtype: bool
"""
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc2.node.TextNode:48
==sdoc.sdoc2.node.UnknownNode:36
def is_block_command(self):
"""
Returns False.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_inline_command(self):
"""
Returns True.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_phrasing(self):
"""
Returns True.

:rtype: bool
"""
return True
Loading history...
Duplication introduced by
Similar lines in 3 files
==sdoc.sdoc1.data_type.ArrayDataType:169
==sdoc.sdoc1.data_type.IntegerDataType:68
==sdoc.sdoc1.data_type.StringDataType:68
def is_constant(self):
"""
Returns False always.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_defined(self):
"""
Returns True always.

:rtype: bool
"""
return True

# ------------------------------------------------------------------------------------------------------------------
def is_scalar(self):
"""
Returns True always.

:rtype: bool
"""
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc2.node.FigureNode:37
==sdoc.sdoc2.node.HeadingNode:41
def is_block_command(self):
"""
Returns False.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_inline_command(self):
"""
Returns True.

:rtype: bool
"""
return True

# ------------------------------------------------------------------------------------------------------------------
@staticmethod
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:265
==sdoc.antlr.sdoc2Parser:162
self._errHandler.sync(self)
_la = self._input.LA(1)

except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx

class TextContext(ParserRuleContext):

def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
super().__init__(parent, invokingState)
self.parser = parser

def TEXT(self):
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:200
==sdoc.antlr.sdoc2Parser:97
def __init__(self, input:TokenStream):
super().__init__(input)
self.checkVersion("4.5.1")
self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
self._predicates = None



class SdocContext(ParserRuleContext):

def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
super().__init__(parent, invokingState)
self.parser = parser

def command(self, i:int=None):
if i is None:
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:770
==sdoc.antlr.sdoc2Parser:536
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx

class Cmd_sdoc2Context(ParserRuleContext):

def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
super().__init__(parent, invokingState)
self.parser = parser

def SDOC2_COMMAND(self):
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:305
==sdoc.antlr.sdoc2Parser:202
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx

class CommandContext(ParserRuleContext):

def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
super().__init__(parent, invokingState)
self.parser = parser
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:399
==sdoc.antlr.sdoc2Parser:269
self.cmd_sdoc2()

else:
raise NoViableAltException(self)

except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:936
==sdoc.antlr.sdoc2Parser:271
else:
raise NoViableAltException(self)

except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:790
==sdoc.antlr.sdoc2Parser:589
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitCmd_sdoc2" ):
return visitor.visitCmd_sdoc2(self)
else:
return visitor.visitChildren(self)




def cmd_sdoc2(self):
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:350
==sdoc.antlr.sdoc2Parser:235
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitCommand" ):
return visitor.visitCommand(self)
else:
return visitor.visitChildren(self)




def command(self):
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:288
==sdoc.antlr.sdoc2Parser:185
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitText" ):
return visitor.visitText(self)
else:
return visitor.visitChildren(self)




def text(self):
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:231
==sdoc.antlr.sdoc2Parser:128
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitSdoc" ):
return visitor.visitSdoc(self)
else:
return visitor.visitChildren(self)




def sdoc(self):
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Parser:1812
==sdoc.antlr.sdoc2Parser:646
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx
Loading history...
Duplication introduced by
Similar lines in 18 files
==sdoc.antlr.sdoc1Parser:1737
==sdoc.antlr.sdoc1Parser:1774
==sdoc.antlr.sdoc1Parser:1812
==sdoc.antlr.sdoc1Parser:305
==sdoc.antlr.sdoc1Parser:441
==sdoc.antlr.sdoc1Parser:500
==sdoc.antlr.sdoc1Parser:553
==sdoc.antlr.sdoc1Parser:666
==sdoc.antlr.sdoc1Parser:718
==sdoc.antlr.sdoc1Parser:770
==sdoc.antlr.sdoc1Parser:807
==sdoc.antlr.sdoc2Parser:165
==sdoc.antlr.sdoc2Parser:202
==sdoc.antlr.sdoc2Parser:274
==sdoc.antlr.sdoc2Parser:374
==sdoc.antlr.sdoc2Parser:426
==sdoc.antlr.sdoc2Parser:536
==sdoc.antlr.sdoc2Parser:646
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.antlr.sdoc1Lexer:205
==sdoc.antlr.sdoc2Lexer:144
def __init__(self, input=None):
super().__init__(input)
self.checkVersion("4.5.1")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None
Loading history...
Duplication introduced by
Similar lines in 14 files
==sdoc.antlr.sdoc1Parser:1044
==sdoc.antlr.sdoc1Parser:1136
==sdoc.antlr.sdoc1Parser:1228
==sdoc.antlr.sdoc1Parser:1352
==sdoc.antlr.sdoc1Parser:1444
==sdoc.antlr.sdoc1Parser:1545
==sdoc.antlr.sdoc1Parser:1646
==sdoc.antlr.sdoc2Parser:165
==sdoc.antlr.sdoc2Parser:202
==sdoc.antlr.sdoc2Parser:274
==sdoc.antlr.sdoc2Parser:374
==sdoc.antlr.sdoc2Parser:426
==sdoc.antlr.sdoc2Parser:536
==sdoc.antlr.sdoc2Parser:646
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
Loading history...
Bug introduced by
There seems to be a cyclic import (sdoc -> sdoc.SDoc).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc2.node.ReferenceNode:37
==sdoc.sdoc2.node.SmileNode:36
def is_block_command(self):
"""
Returns False.

:rtype: bool
"""
return False

# ------------------------------------------------------------------------------------------------------------------
def is_inline_command(self):
"""
Returns True.

:rtype: bool
"""
return True

# ------------------------------------------------------------------------------------------------------------------
def is_phrasing(self):
"""
Returns True.

:rtype: bool
"""
return True
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc2.formatter.html.FigureHtmlFormatter:18
==sdoc.sdoc2.formatter.html.ReferenceHtmlFormatter:19
def generate(self, node, file):
"""
Generates the HTML code for a figure node.

:param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
:param file file: The output file.
"""
self.write_into_file(node, file)

super().generate(node, file)

# ------------------------------------------------------------------------------------------------------------------
def generate_chapter(self, node, file):
"""
Generates the HTML code for a figure node.

:param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
:param file file: The output file.
"""
if file:
self.write_into_file(node, file)

super().generate_chapter(node, file)

# ------------------------------------------------------------------------------------------------------------------
def write_into_file(self, node, file):
"""
Writes data into opened HTML file.

:param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
:param file file: The output file.
"""
Loading history...
Duplication introduced by
Similar lines in 2 files
==sdoc.sdoc2.formatter.html.TableHtmlFormatter:18
==sdoc.sdoc2.formatter.html.UnknownHtmlFormatter:19
def generate(self, node, file):
"""
Generates the HTML code for a table node.

:param sdoc.sdoc2.node.TableNode.TableNode node: The table node.
:param file file: The output file.
"""
self.write_into_file(node, file)

# ------------------------------------------------------------------------------------------------------------------
def generate_chapter(self, node, file):
"""
Generates the HTML code for a table node.

:param sdoc.sdoc2.node.TableNode.TableNode node: The table node.
:param file file: The output file.
"""
if file:
self.write_into_file(node, file)

# ------------------------------------------------------------------------------------------------------------------
def write_into_file(self, node, file):
"""
Writes data into opened file.

:param sdoc.sdoc2.node.TableNode.TableNode node: The table node.
:param file file: The output file.
"""
Loading history...
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
from sdoc.error import SDocError
10
from sdoc.format.Format import Format
11
12
13
class HtmlFormat(Format):
14
    """
15
    Class for generating HTML
16
    """
17
18
    # ------------------------------------------------------------------------------------------------------------------
19
    def __init__(self, config):
20
        """
21
        Object constructor.
22
23
        :param configparser.SectionProxy config: The section in the config file for the target_format.
24
        """
25
        super().__init__(config)
26
27
        self._enumerate = True
28
        """
29
        If set chapters, sections, etc. must be numbered.
30
31
        :type: bool
32
        """
33
34
        self._file_per_chapter = False
35
        """
36
        If set, will generate multiple .html files for each chapter.
37
38
        :type: bool
39
        """
40
41
        self._one_file = True
42
        """
43
        If set, will generate one .html file.
44
45
        :type: bool
46
        """
47
48
        self._read_configuration(config)
49
50
    # ------------------------------------------------------------------------------------------------------------------
51
    def _read_configuration(self, config):
52
        """
53
        Reads the configuration for this formatter.
54
55
        :param configparser.SectionProxy config: The section in the config file for the target_format.
56
        """
57
        try:
58
            self._enumerate = config.getboolean('enumerate', fallback=self._enumerate)
59
        except ValueError:
60
            raise SDocError("Option 'enumerate' not set correctly")
61
62
        try:
63
            self._file_per_chapter = config.getboolean('file_per_chapter', fallback=self._file_per_chapter)
64
        except ValueError:
65
            raise SDocError("Option 'file_per_chapter' not set correctly")
66
67
        try:
68
            self._one_file = config.getboolean('one_file', fallback=self._one_file)
69
        except ValueError:
70
            raise SDocError("Option 'one_file' not set correctly")
71
72
    # ------------------------------------------------------------------------------------------------------------------
73
    @property
74
    def enumerate(self):
75
        """
76
        Getter for enumerate attribute.
77
78
        :rtype: bool
79
        """
80
        return self._enumerate
81
82
    # ------------------------------------------------------------------------------------------------------------------
83
    @property
84
    def file_per_chapter(self):
85
        """
86
        Getter for file_per_chapter attribute.
87
88
        :rtype: bool
89
        """
90
        return self._file_per_chapter
91
92
    # ------------------------------------------------------------------------------------------------------------------
93
    @property
94
    def one_file(self):
95
        """
96
        Getter for one_file attribute.
97
98
        :rtype: bool
99
        """
100
        return self._one_file
101
102
    # ------------------------------------------------------------------------------------------------------------------
103
    def generate(self):
104
        pass
105
106
# ----------------------------------------------------------------------------------------------------------------------
107