Skip to content

Commit

Permalink
Revert variable names cor config and pathprefix which have been chang…
Browse files Browse the repository at this point in the history
…ed in recent linting action.

Locally exempt them from pylint checks.
  • Loading branch information
nomike committed Sep 18, 2024
1 parent c0f3c35 commit 59cfdd8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
8 changes: 4 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_application():
application = Flask(
__name__,
instance_relative_config=True,
static_folder=f"templates/{templatehelper.CONFIG['template']}/static")
static_folder=f"templates/{templatehelper.config['template']}/static")
# paths sent by flask are relative to the "public" directory. This prefix should be added to
# get paths relative to the pages root directory.
pathprefix = ''
Expand Down Expand Up @@ -56,7 +56,7 @@ def serve_directory(path):
# Ensure paths always end with a "/"
return flask.redirect('/' + path + '/')
return flask.render_template(
os.path.join(templatehelper.CONFIG['template'], 'directory.html'),
os.path.join(templatehelper.config['template'], 'directory.html'),
pathprefix = pathprefix,
path = path,
templatehelper = templatehelper)
Expand All @@ -74,14 +74,14 @@ def serve_error(code, message=None):
os.path.join(
__name__,
'templates',
templatehelper.CONFIG['template'],
templatehelper.config['template'],
f'{code}.html')):
template = f'{code}.html'
else:
template = 'error.html'
return flask.make_response((
flask.render_template(
os.path.join(templatehelper.CONFIG['template'], template),
os.path.join(templatehelper.config['template'], template),
code=code,
message=message,
templatehelper=templatehelper,
Expand Down
31 changes: 17 additions & 14 deletions templatehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
import regex
import yaml

CONFIG = None
# pylint: disable=invalid-name
config = None

with open("../config.yaml", encoding='utf-8') as file:
CONFIG = yaml.load(file, Loader=yaml.SafeLoader)
config = yaml.load(file, Loader=yaml.SafeLoader)


# paths sent by flask are relative to the "public" directory. This prefix should be added to get
# paths relative to the pages root directory.
PATHPREFIX = ''
# pylint: disable=invalid-name
pathprefix = ''

# List of official MIME Types: http://www.iana.org/assignments/media-types/media-types.xhtml
# If you want additional mimetypes to be covered, add them to this list.
Expand Down Expand Up @@ -70,12 +73,12 @@ def listdir(path):
page and thus it will be ommited from the list as well.
"""
ignorelist = ['index', 'index.md', '*.scmsfasicon', '*.scmstarget']
if os.path.exists(os.path.join(PATHPREFIX, path, '.scmsignore')):
with open(os.path.join(PATHPREFIX, path, '.scmsignore'), encoding='utf-8') as scsmignore:
if os.path.exists(os.path.join(pathprefix, path, '.scmsignore')):
with open(os.path.join(pathprefix, path, '.scmsignore'), encoding='utf-8') as scsmignore:
ignorelist.extend([line.strip('\n') for line in scsmignore.readlines()])
dirlist = [
os.path.basename(f)
for f in os.listdir(os.path.join(PATHPREFIX, path))
for f in os.listdir(os.path.join(pathprefix, path))
if regex.match('^(?!\\.).*(?<!~)$', f) and not f in ignorelist
]
removeitems = []
Expand All @@ -101,16 +104,16 @@ def listchildren(path):
page and thus it will be ommited from the list as well.
"""
ignorelist = ['index', 'index.md', '*.scmsfasicon', '*.scmstarget']
if os.path.exists(os.path.join(PATHPREFIX, path, '.scmsignore')):
with open(os.path.join(PATHPREFIX, path, '.scmsignore'), encoding='utf-8') as scmsignore:
if os.path.exists(os.path.join(pathprefix, path, '.scmsignore')):
with open(os.path.join(pathprefix, path, '.scmsignore'), encoding='utf-8') as scmsignore:
ignorelist.extend([line.strip('\n') for line in scmsignore.readlines()])
dirlist = [
[os.path.basename(f), os.path.basename(f)]
for f in os.listdir(os.path.join(PATHPREFIX, path))
for f in os.listdir(os.path.join(pathprefix, path))
if regex.match('^(?!\\.).*(?<!~)$', f) and not f in ignorelist
]
if os.path.exists(os.path.join(PATHPREFIX, path, '.scmslinks')):
with open(os.path.join(PATHPREFIX, path, '.scmslinks'), encoding='utf-8') as scmslinks:
if os.path.exists(os.path.join(pathprefix, path, '.scmslinks')):
with open(os.path.join(pathprefix, path, '.scmslinks'), encoding='utf-8') as scmslinks:
additional_links = json.load(scmslinks)
dirlist.extend(additional_links)
removeitems = []
Expand Down Expand Up @@ -154,8 +157,8 @@ def getfasicon(path):
Check if a file named basename(path) + '.scmfasicon' exists, and return it's content.
If not, handover to getfastype(path)
"""
if os.path.isfile(os.path.join(PATHPREFIX, path) + '.scmsfasicon'):
return readfile(os.path.join(PATHPREFIX, path) + '.scmsfasicon')
if os.path.isfile(os.path.join(pathprefix, path) + '.scmsfasicon'):
return readfile(os.path.join(pathprefix, path) + '.scmsfasicon')
return getfastype(path)

def getfastype(path):
Expand All @@ -166,7 +169,7 @@ def getfastype(path):
(the part of the mime-type before the slash).
If this fails as well, fallback to a default.
"""
if os.path.isdir(os.path.join(PATHPREFIX, path)):
if os.path.isdir(os.path.join(pathprefix, path)):
return "fa-folder"

mimetype = mimetypes.guess_type(path)[0]
Expand Down

0 comments on commit 59cfdd8

Please sign in to comment.