Commit ae454aa7 authored by shadMod's avatar shadMod 💬

added debug param to dont create downloads.cache

Fixes: #15

init _mirrors and _sha256sums in Downloads() to fix inspector warning
parent 4a7cc433
# Source code of the Ubuntu-it website # Source code of the Ubuntu-it website
# Copyright (C) 2015-2018 Pietro Albini <pietroalbini@ubuntu.com> # Copyright (C) 2015-2018 Pietro Albini <pietroalbini@ubuntu.com>
# Copyright (C) 2023 shadMod
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published # it under the terms of the GNU Affero General Public License as published
...@@ -29,7 +30,7 @@ from . import redirects ...@@ -29,7 +30,7 @@ from . import redirects
from . import utils from . import utils
def create_app(data_path): def create_app(data_path, debug=False):
"""Create a new instance of the application""" """Create a new instance of the application"""
# Normalize the data path # Normalize the data path
data_path = os.path.expanduser(os.path.abspath(data_path)) data_path = os.path.expanduser(os.path.abspath(data_path))
...@@ -41,11 +42,11 @@ def create_app(data_path): ...@@ -41,11 +42,11 @@ def create_app(data_path):
) )
# Prepare the data directory # Prepare the data directory
init_data_directory(data_path) init_data_directory(data_path, debug)
# Load the secret key # Load the secret key
with open(os.path.join(data_path, "secret_key")) as f: with open(os.path.join(data_path, "secret_key")) as fn:
app.secret_key = f.read().strip() app.secret_key = fn.read().strip()
# Initialize the database # Initialize the database
app.db = db.Database(os.path.join(data_path, "database.db")) app.db = db.Database(os.path.join(data_path, "database.db"))
...@@ -79,14 +80,14 @@ def create_app(data_path): ...@@ -79,14 +80,14 @@ def create_app(data_path):
return app return app
def init_data_directory(data_path): def init_data_directory(data_path, debug=False):
"""Initialize the data directory""" """Initialize the data directory"""
src_directory = os.path.dirname(os.path.abspath(__file__)) src_directory = os.path.dirname(os.path.abspath(__file__))
# Create all the directories # Create all the directories
dirs = ["", "cache"] dirs = ["", "cache"]
for dir in dirs: for _dir in dirs:
os.makedirs(os.path.join(data_path, dir), exist_ok=True) os.makedirs(os.path.join(data_path, _dir), exist_ok=True)
# Initialize the cache # Initialize the cache
static_dirs = {"static": "+assets"} static_dirs = {"static": "+assets"}
...@@ -106,5 +107,7 @@ def init_data_directory(data_path): ...@@ -106,5 +107,7 @@ def init_data_directory(data_path):
os.chmod(secret_key_path, 0o400) os.chmod(secret_key_path, 0o400)
# Initialize the download files # Initialize the download files
download_inst = download.Downloads(data_path) download_inst = download.Downloads(data_path, debug=debug)
download_inst.store_cache_file() if debug is False:
# mk cache file
download_inst.store_cache_file()
...@@ -36,7 +36,11 @@ CACHE_FILE_VERSION = 1 ...@@ -36,7 +36,11 @@ CACHE_FILE_VERSION = 1
class Downloads: class Downloads:
def __init__(self, data_path): def __init__(self, data_path, debug: bool = False):
# init _mirrors and _sha256sums
self._mirrors = None
self._sha256sums = None
# Load the configuration # Load the configuration
path = UITWWW_DIR + CONFIG_FILE path = UITWWW_DIR + CONFIG_FILE
self.config = toml.load( self.config = toml.load(
...@@ -49,7 +53,8 @@ class Downloads: ...@@ -49,7 +53,8 @@ class Downloads:
with open(path, "rb") as raw: with open(path, "rb") as raw:
self._config_hash = "sha1=%s" % hashlib.sha1(raw.read()).hexdigest() self._config_hash = "sha1=%s" % hashlib.sha1(raw.read()).hexdigest()
self._cache_file = os.path.join(data_path, CACHE_FILE) if debug is False:
self._cache_file = os.path.join(data_path, CACHE_FILE)
@property @property
def _cache(self): # Cacheception def _cache(self): # Cacheception
...@@ -61,7 +66,7 @@ class Downloads: ...@@ -61,7 +66,7 @@ class Downloads:
@property @property
def mirrors(self): def mirrors(self):
"""Get a list of CD mirrors needed by the website""" """Get a list of CD mirrors needed by the website"""
if not hasattr(self, "_mirrors"): if not hasattr(self, "_mirrors") or self._mirrors is None:
if self._cache is not None: if self._cache is not None:
self._mirrors = self._cache["mirrors"] self._mirrors = self._cache["mirrors"]
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment