Commit 483cbbba authored by shadMod's avatar shadMod 💬

replaced pkg_resources with os.path with quick code clenaup

Fixes: https://code.ubuntu-it.org/ubuntu-it-web/www/-/issues/13
parent 4d70476e
......@@ -14,18 +14,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import functools
import time
import uuid
import yaml
import flask
import functools
import flask_openid
import pkg_resources
import time
import yaml
from .constants import UITWWW_DIR
from uitwww.third_party import openid_teams
SESSION_EXPIRES_AFTER = 86400
......@@ -148,8 +146,8 @@ class Sessions:
class Permissions:
def __init__(self):
raw = pkg_resources.resource_string("uitwww", "data/permissions.yml")
self.config = yaml.safe_load(raw.decode("utf-8"))
with open(UITWWW_DIR + "/data/permissions.yml") as fn:
self.config = yaml.safe_load(fn.read())
def allowed_teams(self):
"""Return a list of teams allowed to log in"""
......@@ -177,6 +175,7 @@ class Permissions:
def permission(perms):
"""Process the endpoint only if the user has permission"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
......@@ -200,6 +199,7 @@ def permission(perms):
return flask.abort(403)
return wrapper
return decorator
......@@ -277,7 +277,6 @@ def prepare_blueprint(app):
flask.flash("La sessione è stata terminata correttamente.", "success")
return flask.redirect(flask.url_for("pages.index"))
@bp.route("/sessions")
@permission("auth.sessions.manage")
def sessions_list():
......
......@@ -17,9 +17,6 @@
import threading
import sqlite3
import pkg_resources
_LOCAL = threading.local()
......
......@@ -22,15 +22,14 @@ import random
import collections
import flask
import itsdangerous
import requests
import pkg_resources
import itsdangerous
from . import cache
from . import launchpad
from .constants import UITWWW_DIR
CONFIG_FILE = "data/downloads.toml"
CONFIG_FILE = "/data/downloads.toml"
CACHE_FILE = "download-cache.json"
CACHE_FILE_VERSION = 1
......@@ -39,16 +38,16 @@ class Downloads:
def __init__(self, data_path):
# Load the configuration
raw = pkg_resources.resource_string("uitwww", CONFIG_FILE)
self.config = toml.loads(
raw.decode("utf-8"),
_dict=collections.OrderedDict,
path = UITWWW_DIR + CONFIG_FILE
self.config = toml.load(
path, _dict=collections.OrderedDict,
)
self._strip_non_lts_releases()
# Save the hash of the configuration
self._config_hash = "sha1=%s" % hashlib.sha1(raw).hexdigest()
with open(path, "rb") as raw:
self._config_hash = "sha1=%s" % hashlib.sha1(raw.read()).hexdigest()
self._cache_file = os.path.join(data_path, CACHE_FILE)
......
......@@ -14,10 +14,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import flask
import json
import pkg_resources
import yaml
import flask
from .constants import UITWWW_DIR
class Navbar:
......@@ -55,8 +55,8 @@ class Navbar:
def install(self, app):
"""Install this navbar on the app"""
raw = pkg_resources.resource_string("uitwww", "data/navbar.yml")
config = yaml.load(raw.decode("utf-8"))
with open(UITWWW_DIR + "/data/navbar.yml") as fn:
config = yaml.safe_load(fn.read())
self._prepare_navbar_cache(config, [])
# Add the _navbars variable to the templates
......
......@@ -15,10 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import json
import flask
import pkg_resources
from uitwww import cache
......
......@@ -14,16 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import flask
import pkg_resources
import yaml
import flask
import hashlib
from .constants import UITWWW_DIR
def prepare_blueprint(app):
"""Prepare a blueprint containing all the redirects"""
raw = pkg_resources.resource_string("uitwww", "data/redirects.yml")
config = yaml.safe_load(raw.decode("utf-8"))
with open(UITWWW_DIR + "/data/redirects.yml") as fn:
config = yaml.safe_load(fn.read())
bp = flask.Blueprint("redirects", __name__)
......
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