Skip to content

Commit 45172ff

Browse files
committed
enhance code coherence
1 parent 5e688c2 commit 45172ff

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

tools/python/demo_recursive_folder_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
else None )
1515
listOfFiles.sort(reverse=True, key=lambda f:f[1])
1616
for f in listOfFiles:
17-
print('File: ' + f[0].path + ' - (' + mne_cpp.core.size_human_readable(f[1]) + ')')
17+
print('File: ' + f[0].path + ' - (' + mne_cpp.core.sizeHumanReadable(f[1]) + ')')
1818

tools/python/mne_cpp/core.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,15 @@ def version():
4242
print('MNE-CPP Project python module. - Version: 0.1.9')
4343
print('Copyright (C) 2021, Juan Garcia-Prieto. All rights reserved.')
4444

45-
def __currentPath():
45+
def __pathToThisFile():
4646
return path.abspath(path.dirname(sys.argv[0]))
4747

4848
def baseFolder():
49-
this_script_path = __currentPath().split(path.sep)
49+
this_script_path = __pathToThisFile().split(path.sep)
5050
project_path = ''
5151
for f in this_script_path[:-2]:
5252
project_path += f + '/'
5353
return project_path
54-
class File_ext_separator(Enum):
55-
FIRST = 1
56-
LAST = 2
5754

5855
def extractFilePaths(text: str, **inputArgs):
5956

@@ -90,10 +87,10 @@ def extractFilePaths(text: str, **inputArgs):
9087
pattern = re.compile(expression)
9188
fileMatches = pattern.finditer(text)
9289
for f in fileMatches:
93-
deviceLabel = none_if_empty(f.group('deviceLabel')) #f.string[f.start('deviceLabel'):f.end('deviceLabel')]
94-
filePath = none_if_empty(f.group('filePath')) #f.string[f.start('filePath'):f.end('filePath')-1]
95-
fileName = none_if_empty(f.group('fileName')) #f.string[f.start('fileName'):f.end('fileName')]
96-
fileExt = none_if_empty(f.group('fileExtension')) #f.string[f.start('fileExtension'):f.end('fileExtension')]
90+
deviceLabel = noneIfEmpty(f.group('deviceLabel')) #f.string[f.start('deviceLabel'):f.end('deviceLabel')]
91+
filePath = noneIfEmpty(f.group('filePath')) #f.string[f.start('filePath'):f.end('filePath')-1]
92+
fileName = noneIfEmpty(f.group('fileName')) #f.string[f.start('fileName'):f.end('fileName')]
93+
fileExt = noneIfEmpty(f.group('fileExtension')) #f.string[f.start('fileExtension'):f.end('fileExtension')]
9794
absFilePath = deviceLabel + filePath + fileName + '.' + fileExt
9895
print(absFilePath)
9996
return (deviceLabel, filePath, fileName, fileExt, absFilePath)
@@ -105,7 +102,7 @@ def recursiveFolderProcess(folderPath, func):
105102
if file.is_file():
106103
func(file)
107104

108-
def none_if_empty(s):
105+
def noneIfEmpty(s):
109106
return '' if s is None else s
110107

111108
def parseFilePathNameExt(inText):
@@ -124,11 +121,11 @@ def parseFilePathNameExt(inText):
124121
fileName = ''
125122
fileExt = ''
126123
if match:
127-
deviceLabel = none_if_empty(match.group('deviceLabel'))
128-
filePath = none_if_empty(match.group('filePath'))
129-
lastFolder = none_if_empty(match.group('lastFolder'))
130-
fileName = none_if_empty(match.group('fileName'))
131-
fileExt = none_if_empty(match.group('fileExt'))
124+
deviceLabel = noneIfEmpty(match.group('deviceLabel'))
125+
filePath = noneIfEmpty(match.group('filePath'))
126+
lastFolder = noneIfEmpty(match.group('lastFolder'))
127+
fileName = noneIfEmpty(match.group('fileName'))
128+
fileExt = noneIfEmpty(match.group('fileExt'))
132129
return (deviceLabel, filePath, lastFolder, fileName, fileExt)
133130

134131
def parseInputArguments(argsToParse, **opts):
@@ -162,7 +159,7 @@ def parseInputArguments(argsToParse, **opts):
162159
return (v for k, v in options.items())
163160

164161
_suffixes = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
165-
def size_human_readable(size):
162+
def sizeHumanReadable(size):
166163
# determine binary order in steps of size 10
167164
# (coerce to int, // still returns a float)
168165
order = int(log2(size) / 10) if size else 0
@@ -171,7 +168,7 @@ def size_human_readable(size):
171168
# should never resort to exponent values)
172169
return '{:.4g} {}'.format(size / (1 << (order * 10)), _suffixes[order])
173170

174-
def get_list_of_files(folder):
171+
def getListOfFiles(folder):
175172
"""Retrieve a list of files inside (recursive) a folder.
176173
177174
Args:

tools/python/mne_cpp/pdf_doc.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@ def parseMarkDownFile(file, **inputArgs):
202202
inText = parseHeaders(inText)
203203
inText = parseLinks(inText)
204204

205+
def deleteJustTheDocsHeader(inText):
206+
return re.sub(r'\n*\s*---\s*\n(.*\n)*---\n','',inText)
205207

206-
def deleteJustTheDocsHeader(text):
207-
return re.sub(r'\n*\s*---\s*\n(.*\n)*---\n','',text)
208+
def parseInlineItalicText(inText):
209+
return re.sub(r'(?<=\W)((?P<star>\*)|_)(?P<itext>\w+)(?(star)\*|_)(?=\W)',r'\\textit{\g<itext>}', inText)
208210

209-
def parseInlineItalicText(text):
210-
return re.sub(r'(?<=\W)((?P<star>\*)|_)(?P<itext>\w+)(?(star)\*|_)(?=\W)',r'\\textit{\g<itext>}', text)
211-
212-
def parseInlineBoldText(text):
213-
return re.sub(r'(?<=\W)((?P<dstar>\*\*)|__)(?P<btext>[\w ]+)((?(dstar)\*\*)|__)(?=\W)',r'\\textbf{\g<btext>}', text)
211+
def parseInlineBoldText(inText):
212+
return re.sub(r'(?<=\W)((?P<dstar>\*\*)|__)(?P<btext>[\w ]+)((?(dstar)\*\*)|__)(?=\W)',r'\\textbf{\g<btext>}', inText)
214213

215214
def parseUnorderedList(inText):
216215
match = re.search(r'(\n\s?\*\s?.+)(\n\s?\*\s?(.+))*', inText)
@@ -313,11 +312,12 @@ def parseHeaders(inText):
313312
else:
314313
return inText
315314

315+
def parseHorizontalLine(inText):
316+
return re.sub(r'(?<=\n)\*\s\*\s\*(?=\n)','\\noindent\\rule{15cm}{0.5pt}', inText)
317+
316318
# parse horizontal line
317319
# \n\* \* \*
318320

319-
mne_cpp.core.get_list_of_files
320-
321321
# parse all lists with (\n((\s*[-*]\s*)|(\s*\d+\.\s*)).+)+
322322
# see https://regex101.com/r/2uKqPB/1/
323323

@@ -338,11 +338,10 @@ def parseHeaders(inText):
338338

339339

340340
# still missing:
341-
# ordered lists parsing
341+
# ordered and unordered lists parsing
342342
# inbound links vs outbound links
343343
# parse inline code
344344
# preamble and ending file
345-
# parse horizontal lines
346345
# parse multiple terms description/definition
347346

348347

0 commit comments

Comments
 (0)