Skip to content

Commit

Permalink
Code linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
nomike committed Sep 18, 2024
1 parent 4bde051 commit f507427
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 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_app():
app = 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 @@ -73,14 +73,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
34 changes: 17 additions & 17 deletions templatehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import regex
import yaml

config = None
with open("../config.yaml") as file:
config = yaml.load(file, Loader=yaml.SafeLoader)
CONFIG = None
with open("../config.yaml", encoding='utf-8') as file:
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.
#TODO: This is a redundant specification and should be avoided.
pathprefix = ''
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 @@ -71,12 +71,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')) as file:
if os.path.exists(os.path.join(PATHPREFIX, path, '.scmsignore')):
with open(os.path.join(PATHPREFIX, path, '.scmsignore'), encoding='utf-8') as file:
ignorelist.extend([line.strip('\n') for line in file.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 @@ -102,16 +102,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')) as file:
if os.path.exists(os.path.join(PATHPREFIX, path, '.scmsignore')):
with open(os.path.join(PATHPREFIX, path, '.scmsignore'), encoding='utf-8') as file:
ignorelist.extend([line.strip('\n') for line in file.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')) as file:
if os.path.exists(os.path.join(PATHPREFIX, path, '.scmslinks')):
with open(os.path.join(PATHPREFIX, path, '.scmslinks'), 'utf-8') as file:
additional_links = json.load(file)
dirlist.extend(additional_links)
removeitems = []
Expand Down Expand Up @@ -154,8 +154,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')
else:
return getfastype(path)

Expand All @@ -167,11 +167,11 @@ 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]
if not mimetype == None:
if not mimetype is None:
if mimetype in mimetype_fas_mapping:
return mimetype_fas_mapping[mimetype]
if mimetype.split('/')[0] in mimetype_fas_mapping:
Expand All @@ -180,7 +180,7 @@ def getfastype(path):

def getlastmodifiedfile(path):
path = os.path.join('..', path)
assert(os.path.isdir(path))
assert os.path.isdir(path)
newest = {"file": path, "timestamp": os.path.getmtime(path)}
for root, dirs, files in os.walk(path):
for path in dirs:
Expand Down

0 comments on commit f507427

Please sign in to comment.