Changeset - bfccdcd998fc
[Not reviewed]
default
0 4 0
Dennis Fink - 3 years ago 2022-06-10 09:36:16
dennis.fink@c3l.lu
Remove dead code
4 files changed with 6 insertions and 21 deletions:
0 comments (0 inline, 0 general)
spaceapi/__init__.py
Show inline comments
 
@@ -96,12 +96,11 @@ def create_app():
 
    app.register_blueprint(state_views, url_prefix="/state")
 

	
 
    from .sensors import sensors_views
 

	
 
    app.register_blueprint(sensors_views, url_prefix="/sensors")
 

	
 
    from .utils import ActiveStatus, ActiveStatusv14
 
    from .utils import ActiveStatusv14
 

	
 
    ActiveStatus().reload()
 
    ActiveStatusv14().reload()
 

	
 
    return app
spaceapi/sensors.py
Show inline comments
 
@@ -3,13 +3,13 @@ from functools import partial
 

	
 
import jsonschema
 
from flask import Blueprint, abort, current_app, jsonify, request
 
from pkg_resources import resource_filename
 

	
 
from .auth import httpauth
 
from .utils import ActiveStatus, ActiveStatusv14, first, fuzzy_list_find
 
from .utils import ActiveStatusv14, first, fuzzy_list_find
 

	
 
sensors_views = Blueprint("sensors", __name__)
 

	
 
ALLOWED_SENSORS_KEYS = json.load(
 
    open(resource_filename("spaceapi", "schema/sensors.json"), encoding="utf-8")
 
)
spaceapi/utils.py
Show inline comments
 
@@ -5,23 +5,15 @@ from functools import wraps
 
from time import time
 

	
 
import mastodon
 
import tweepy
 
from flask import current_app, request
 

	
 
default_json_file = os.path.abspath("default.json")
 
last_state_file = os.path.abspath("laststate.json")
 

	
 
default_json_file_v14 = os.path.abspath("default_v14.json")
 
last_state_file_v14 = os.path.abspath("laststate_v14.json")
 

	
 
if not os.path.exists(default_json_file):
 
    raise RuntimeError("default.json does not exists!")
 
elif not os.path.isfile(default_json_file):
 
    raise RuntimeError("default.json is not a file!")
 

	
 
if not os.path.exists(default_json_file_v14):
 
    raise RuntimeError("default_v14.json does not exists!")
 
elif not os.path.isfile(default_json_file):
 
    raise RuntimeError("default_v14.json is not a file!")
 

	
 

	
 
@@ -86,16 +78,16 @@ class Singleton:
 
        if key not in cls._instance_dict:
 
            cls._instance_dict[key] = super().__new__(cls, *args, **kwargs)
 

	
 
        return cls._instance_dict[key]
 

	
 

	
 
class ActiveStatus(Singleton, dict):
 
class ActiveStatusv14(Singleton, dict):
 
    def __init__(self):
 
        self.default_json_file = default_json_file
 
        self.last_state_file = last_state_file
 
        self.default_json_file = default_json_file_v14
 
        self.last_state_file = last_state_file_v14
 

	
 
    def reload(self):
 

	
 
        with open(self.default_json_file, encoding="utf-8") as f:
 
            self.update(json.load(f))
 

	
 
@@ -205,18 +197,12 @@ class ActiveStatus(Singleton, dict):
 
            self["state"]["lastchange"] = int(time())
 

	
 
        if message is not None and message:
 
            self["state"]["message"] = message
 

	
 

	
 
class ActiveStatusv14(ActiveStatus):
 
    def __init__(self):
 
        self.default_json_file = default_json_file_v14
 
        self.last_state_file = last_state_file_v14
 

	
 

	
 
def request_wants_json():
 
    best = request.accept_mimetypes.best_match(["application/json", "text/html"])
 
    return (
 
        best == "application/json"
 
        and request.accept_mimetypes[best] > request.accept_mimetypes["text/html"]
 
    )
spaceapi/views.py
Show inline comments
 
@@ -7,13 +7,13 @@ from flask import (
 
    render_template,
 
    request,
 
    url_for,
 
)
 

	
 
from .auth import basicauth, httpauth
 
from .utils import ActiveStatus, ActiveStatusv14, request_wants_json
 
from .utils import ActiveStatusv14, request_wants_json
 

	
 
root_views = Blueprint("root", __name__)
 

	
 

	
 
@root_views.route("/")
 
def index():
0 comments (0 inline, 0 general)