Skip to content
Snippets Groups Projects
Commit 5604406f authored by Lukáš Krupčík's avatar Lukáš Krupčík
Browse files

modified: .gitlab-ci.yml

	modified:   .spelling
	modified:   scripts/titlemd.py
parent cafa83eb
No related branches found
No related tags found
1 merge request!475modified: .gitlab-ci.yml
Pipeline #39791 failed
...@@ -34,9 +34,11 @@ pysafety: ...@@ -34,9 +34,11 @@ pysafety:
capitalize: capitalize:
stage: test stage: test
image: it4innovations/docker-mkdocscheck:latest image: it4innovations/docker-mkdocscheck:latest
allow_failure: true
before_script: before_script:
- source /opt/.venv3/bin/activate - source /opt/.venv3/bin/activate
- python -V # debug - python -V # debug
- pip list | grep titlecase
script: script:
- find mkdocs.yml docs.it4i/ \( -name '*.md' -o -name '*.yml' \) -print0 | xargs -0 -n1 scripts/titlemd.py --test - find mkdocs.yml docs.it4i/ \( -name '*.md' -o -name '*.yml' \) -print0 | xargs -0 -n1 scripts/titlemd.py --test
......
...@@ -835,4 +835,4 @@ it4ifree ...@@ -835,4 +835,4 @@ it4ifree
it4ifsusage it4ifsusage
it4iuserfsusage it4iuserfsusage
it4iprojectfsusage it4iprojectfsusage
it4imotd it4imotd
\ No newline at end of file
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" titlemd """ """ titlemd """
from __future__ import print_function
import argparse import argparse
import sys import sys
...@@ -30,16 +28,14 @@ def arg_parse(): ...@@ -30,16 +28,14 @@ def arg_parse():
def mkdocs_available(location): def mkdocs_available(location):
""" Is mkdocs.yml available? """ """ Is mkdocs.yml available? """
if location.find("mkdocs.yml") != -1: return "mkdocs.yml" in location
return True
return False
def linestart(line, disabled, test, prev_line=None): def linestart(line, disabled, test, prev_line=None):
""" linestart """ """ linestart """
if test: if test:
if (line.startswith("``") or line.startswith("extra:")) and not disabled: if (line.startswith("``") or line.startswith("extra:")) and not disabled:
return True return True
if (line.startswith("``") or prev_line.startswith("pages:")) and disabled: if (line.startswith("``") or (prev_line and prev_line.startswith("pages:"))) and disabled:
return False return False
else: else:
if line.startswith("``") and not disabled: if line.startswith("``") and not disabled:
...@@ -54,7 +50,6 @@ def testdata(arg): ...@@ -54,7 +50,6 @@ def testdata(arg):
with open('.spelling') as fdata: with open('.spelling') as fdata:
spelling = fdata.readlines() spelling = fdata.readlines()
# pylint: disable=unused-argument,inconsistent-return-statements
def abbreviations(word, **kwargs): def abbreviations(word, **kwargs):
""" abbreviations """ """ abbreviations """
if word+"\n" in spelling: if word+"\n" in spelling:
...@@ -67,7 +62,7 @@ def testdata(arg): ...@@ -67,7 +62,7 @@ def testdata(arg):
# Loop through the list of lines and titlecase # Loop through the list of lines and titlecase
# any line beginning with '#'. # any line beginning with '#'.
return_value = 0 return_value = 0
prev_line = lines[0] prev_line = lines[0] if lines else ""
echo_filename = False echo_filename = False
disabled = mkdocs_available(arg.location) disabled = mkdocs_available(arg.location)
for line in lines: for line in lines:
...@@ -76,34 +71,30 @@ def testdata(arg): ...@@ -76,34 +71,30 @@ def testdata(arg):
if line != titlecase(line[:(line.find("]"))], if line != titlecase(line[:(line.find("]"))],
callback=abbreviations)+line[(line.find("]")):]: callback=abbreviations)+line[(line.find("]")):]:
if return_value == 0 and not echo_filename: if return_value == 0 and not echo_filename:
print("%s" % arg.location) print(f"{arg.location}")
echo_filename = True echo_filename = True
print("-"+line, end="") print(f"-{line}", end="")
print("+"+titlecase(line[:(line.find("]"))], print(f"+{titlecase(line[:(line.find(']'))], callback=abbreviations)}{line[(line.find(']')):]}", end="")
callback=abbreviations)+line[(line.find("]")):], end="")
print() print()
return_value = 1 return_value = 1
if (line.startswith('---') or line.startswith('===')) and not disabled: if (line.startswith('---') or line.startswith('===')) and not disabled:
if prev_line != titlecase(prev_line[:(prev_line.find("]"))], if prev_line != titlecase(prev_line[:(prev_line.find("]"))],
callback=abbreviations)+prev_line[(prev_line.find("]")):]: callback=abbreviations)+prev_line[(prev_line.find("]")):]:
if return_value == 0 and not echo_filename: if return_value == 0 and not echo_filename:
print("%s" % arg.location) print(f"{arg.location}")
echo_filename = True echo_filename = True
print("-"+prev_line, end="") print(f"-{prev_line}", end="")
print("+"+titlecase(prev_line[:(prev_line.find("]"))], print(f"+{titlecase(prev_line[:(prev_line.find(']'))], callback=abbreviations)}{prev_line[(prev_line.find(']')):]}", end="")
callback=abbreviations)+prev_line[(prev_line.find("]")):],
end="")
print() print()
return_value = 1 return_value = 1
if (mkdocs_available(arg.location) and not line.startswith('#') and not disabled): if (mkdocs_available(arg.location) and not line.startswith('#') and not disabled):
if line != titlecase(line[:(line.find(":"))], if line != titlecase(line[:(line.find(":"))],
callback=abbreviations)+line[(line.find(":")):]: callback=abbreviations)+line[(line.find(":")):]:
if return_value == 0 and not echo_filename: if return_value == 0 and not echo_filename:
print("%s" % arg.location) print(f"{arg.location}")
echo_filename = True echo_filename = True
print("-"+line, end="") print(f"-{line}", end="")
print("+"+titlecase(line[:(line.find(":"))], print(f"+{titlecase(line[:(line.find(':'))], callback=abbreviations)}{line[(line.find(':')):]}", end="")
callback=abbreviations)+line[(line.find(":")):], end="")
print() print()
return_value = 1 return_value = 1
prev_line = line prev_line = line
...@@ -115,7 +106,6 @@ def writedata(arg): ...@@ -115,7 +106,6 @@ def writedata(arg):
with open('.spelling') as fdata: with open('.spelling') as fdata:
spelling = fdata.readlines() spelling = fdata.readlines()
# pylint: disable=unused-argument,inconsistent-return-statements
def abbreviations(word, **kwargs): def abbreviations(word, **kwargs):
""" abbreviations """ """ abbreviations """
if word+"\n" in spelling: if word+"\n" in spelling:
...@@ -126,9 +116,7 @@ def writedata(arg): ...@@ -126,9 +116,7 @@ def writedata(arg):
lines = fdata.readlines() lines = fdata.readlines()
with open(arg.location, 'w') as fdata: with open(arg.location, 'w') as fdata:
# Loop through the list of lines and titlecase prev_line = lines[0] if lines else ""
# any line beginning with '#'.
prev_line = lines[0]
disabled = False disabled = False
for line in lines: for line in lines:
disabled = linestart(line, disabled, arg.test) disabled = linestart(line, disabled, arg.test)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment