pylint fixes for parser.py

This patch contains only changes to make pylint somewhat happier.

- shorten lines longer than 79 characters
- use raw strings where appropriate

Change-Id: I236856e4b01fb8b5b8967ed474e30554a2b48c31
This commit is contained in:
Roger Luethi 2017-01-11 08:36:50 +01:00
parent 6ab1007f58
commit c41a01acac
1 changed files with 21 additions and 22 deletions

View File

@ -57,9 +57,9 @@ def configure_logging():
# TODO(dbite): Remove CamelCasing. # TODO(dbite): Remove CamelCasing.
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
# Custom data-types. # Custom data-types.
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
class BlockIndex(object): class BlockIndex(object):
"""Creates indices which describes the location of blocks in rst file. """Creates indices which describes the location of blocks in rst file.
@ -225,9 +225,9 @@ class CodeBlock(object):
return self.command['distro'] return self.command['distro']
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
# Parser Logic. # Parser Logic.
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
class ParseBlocks(object): class ParseBlocks(object):
"""Convert RST block to BASH code. """Convert RST block to BASH code.
@ -280,7 +280,7 @@ class ParseBlocks(object):
return command return command
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
def _parse_inject(self, rstBlock): def _parse_inject(self, rstBlock):
"""Parse inject lines. """Parse inject lines.
@ -313,7 +313,7 @@ class ParseBlocks(object):
for line in rstBlock.split('\n'): for line in rstBlock.split('\n'):
line = line.strip() line = line.strip()
if re.search('\[[a-zA-Z0-9_]+\]', line): if re.search(r'\[[a-zA-Z0-9_]+\]', line):
operator = line[1:-1] operator = line[1:-1]
elif re.search('=', line) and not re.search('^#', line): elif re.search('=', line) and not re.search('^#', line):
line = operator + " " + line.replace("=", " ") + "\n" line = operator + " " + line.replace("=", " ") + "\n"
@ -343,7 +343,7 @@ class ParseBlocks(object):
return operator return operator
def _parse_code(self, rstBlock): def _parse_code(self, rstBlock):
"""Parse code lines. r"""Parse code lines.
Code-blocks containing bash code (console|mysql) are sent here. These Code-blocks containing bash code (console|mysql) are sent here. These
are bash code or mysql etc. which are to be formatted into proper bash are bash code or mysql etc. which are to be formatted into proper bash
@ -365,7 +365,7 @@ class ParseBlocks(object):
# Substitute HTML codes for '\' and '\n' # Substitute HTML codes for '\' and '\n'
rstBlock = rstBlock.replace("\\\n", "&#10&#10&#13") rstBlock = rstBlock.replace("\\\n", "&#10&#10&#13")
for index in re.finditer("[#\$>].*", rstBlock): for index in re.finditer(r"[#\$>].*", rstBlock):
cmd = rstBlock[index.start():index.end()].replace("&#10&#10&#13", cmd = rstBlock[index.start():index.end()].replace("&#10&#10&#13",
"\\\n") "\\\n")
@ -375,7 +375,7 @@ class ParseBlocks(object):
return parsedCmds return parsedCmds
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
class ExtractBlocks(object): class ExtractBlocks(object):
@ -453,7 +453,7 @@ class ExtractBlocks(object):
return self.filePointer.read() return self.filePointer.read()
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
def get_indice_blocks(self): def get_indice_blocks(self):
"""Should fetch regex strings from the right location.""" """Should fetch regex strings from the right location."""
@ -462,22 +462,22 @@ class ExtractBlocks(object):
# Regex string for extracting particular bits from RST file. # Regex string for extracting particular bits from RST file.
# For some reason I want to keep the generic RegEX strings. # For some reason I want to keep the generic RegEX strings.
# XXX(dbite): Figure out the index|indices confusing terms. # XXX(dbite): Figure out the index|indices confusing terms.
searchAllBlocks = '''\.\.\s # Look for '.. ' searchAllBlocks = r'''\.\.\s # Look for '.. '
(code-block::|only::|path) # Look for required blocks (code-block::|only::|path) # Look for required blocks
[a-z\s/].* [a-z\s/].*
''' '''
searchDistroBlocksStart = '''\.\.\sonly:: searchDistroBlocksStart = r'''\.\.\sonly::
[\sa-z].* # For matching all distros. [\sa-z].* # For matching all distros.
''' '''
searchDistroBlocksEnd = '''\.\.\sendonly\\n''' # Match end blocks. searchDistroBlocksEnd = r'''\.\.\sendonly\n''' # Match end blocks.
searchCodeBlocksStart = '''\.\.\scode-block:: # Look for code block searchCodeBlocksStart = r'''\.\.\scode-block:: # Look for code block
\s # Include whitespace \s # Include whitespace
(?!end) # Exclude code-block:: end (?!end) # Exclude code-block:: end
(?:[a-z])* # Include everything else. (?:[a-z])* # Include everything else.
''' '''
searchCodeBlocksEnd = '''\.\.\send\\n''' # Look for .. end searchCodeBlocksEnd = r'''\.\.\send\n''' # Look for .. end
searchPath = '''\.\.\spath\s.*''' # Look for .. path searchPath = r'''\.\.\spath\s.*''' # Look for .. path
allBlocks = BlockIndex(self._get_indices(searchAllBlocks)) allBlocks = BlockIndex(self._get_indices(searchAllBlocks))
@ -495,12 +495,11 @@ class ExtractBlocks(object):
self.blocks = {'distroBlock': distroBlocks, self.blocks = {'distroBlock': distroBlocks,
'codeBlock': codeBlocks, 'codeBlock': codeBlocks,
'pathBlock': pathBlocks, 'pathBlock': pathBlocks,
'allBlock': allBlocks 'allBlock': allBlocks}
}
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
# Recursive Generator Pattern. # Recursive Generator Pattern.
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
def extract_codeblocks(self): def extract_codeblocks(self):
"""Initialize the generator object and start the initial parsing.""" """Initialize the generator object and start the initial parsing."""
@ -597,7 +596,7 @@ class ExtractBlocks(object):
return return
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
@staticmethod @staticmethod
def write_to_file(path, value): def write_to_file(path, value):
@ -624,7 +623,7 @@ class ExtractBlocks(object):
return True return True
# ------------------------------------------------------------------------------ # -----------------------------------------------------------------------------
if __name__ == '__main__': if __name__ == '__main__':