Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert variable names vor config and pathprefix which have been changed in recent linting action. #9

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading