From 3678aeb05a94a3c092ef9b722c0bc3e4ca81fad5 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 30 Dec 2016 01:58:10 -0500 Subject: [PATCH] Add stubs for EVE universe data. --- README.md | 2 +- app.py | 2 +- calefaction/config.py | 15 +++-- calefaction/eve/__init__.py | 7 +++ calefaction/eve/universe.py | 141 ++++++++++++++++++++++++++++++++++++++++++++ scripts/read_sde.py | 4 ++ 6 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 calefaction/eve/universe.py create mode 100755 scripts/read_sde.py diff --git a/README.md b/README.md index 9748164..eb4e7de 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Guide mkdir logs sudo chmod 0600 config/config.yml data/db.sqlite3 sudo chown www-data:www-data config/config.yml data data/db.sqlite3 logs - ... # TODO: convert these into scripts, add module instructions + ... # TODO: convert these into scripts, add SDE instructions, add module instructions ### Test diff --git a/app.py b/app.py index 313ed7a..1717195 100644 --- a/app.py +++ b/app.py @@ -19,7 +19,7 @@ from calefaction.util import ( app = Flask(__name__) basepath = Path(__file__).resolve().parent -config = Config(basepath / "config") +config = Config(basepath) Database.path = str(basepath / "data" / "db.sqlite3") eve = EVE(config) auth = AuthManager(config, eve) diff --git a/calefaction/config.py b/calefaction/config.py index 34e9ca4..3c34276 100644 --- a/calefaction/config.py +++ b/calefaction/config.py @@ -30,9 +30,9 @@ class _ModuleIndex(list): class Config: """Stores application-wide configuration info.""" - def __init__(self, confdir): - self._dir = confdir - self._filename = confdir / "config.yml" + def __init__(self, basedir): + self._dir = basedir + self._filename = basedir / "config" / "config.yml" self._data = None self._modules = _ModuleIndex() self._load() @@ -60,6 +60,11 @@ class Config: return obj @property + def dir(self): + """Return the application's base directory.""" + return self._dir + + @property def modules(self): """Return a list-like object (a _ModuleIndex) of loaded modules.""" return self._modules @@ -74,7 +79,7 @@ class Config: app.config["SERVER_NAME"] = self.get("site.canonical") app.config["PREFERRED_URL_SCHEME"] = self.scheme app.config["MAKO_MODULE_DIRECTORY"] = str( - self._dir.parent / "templates" / ".cache") + self._dir / "templates" / ".cache") app.secret_key = self.get("auth.session_key") for module in self.modules: @@ -85,7 +90,7 @@ class Config: Returns a YAML parse of {confdir}/modules/{name}.yml, or None. """ - filename = self._dir / "modules" / (name + ".yml") + filename = self._dir / "config" / "modules" / (name + ".yml") try: with filename.open("rb") as fp: return yaml.load(fp) diff --git a/calefaction/eve/__init__.py b/calefaction/eve/__init__.py index 99470fc..ec08dd3 100644 --- a/calefaction/eve/__init__.py +++ b/calefaction/eve/__init__.py @@ -8,6 +8,7 @@ from .clock import Clock from .esi import EVESwaggerInterface from .image import ImageServer from .sso import SSOManager +from .universe import Universe from .zkill import ZKillboard from .. import __release__, baseLogger @@ -26,6 +27,7 @@ class EVE: self._esi = EVESwaggerInterface(session, logger.getChild("esi")) self._image = ImageServer() self._sso = SSOManager(session, logger.getChild("sso")) + self._universe = Universe(config.dir / "data" / "universe") self._zkill = ZKillboard(session, logger.getChild("zkill")) @staticmethod @@ -58,6 +60,11 @@ class EVE: return self._sso @property + def universe(self): + """The Universe API module.""" + return self._universe + + @property def zkill(self): """The zKillboard API module.""" return self._zkill diff --git a/calefaction/eve/universe.py b/calefaction/eve/universe.py new file mode 100644 index 0000000..9fee51a --- /dev/null +++ b/calefaction/eve/universe.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- + +__all__ = ["Universe"] + +class _SolarSystem: + """Represents a solar system.""" + + def __init__(self, universe, sid, data): + self._universe = universe + self._id = sid + self._data = data + + @property + def id(self): + """The solar system's ID, as an integer.""" + return self._id + + @property + def name(self): + """The solar system's name, as a string.""" + return self._data["name"] + + @property + def constellation(self): + """The solar system's constellation, as a _Constellation object.""" + return self._universe.constellation(self._data["constellation"]) + + @property + def region(self): + """The solar system's region, as a _Region object.""" + return self._universe.region(self._data["region"]) + + @property + def security(self): + """The solar system's security status, as a float.""" + return self._data["security"] + + +class _Constellation: + """Represents a constellation.""" + + def __init__(self, universe, cid, data): + self._universe = universe + self._id = cid + self._data = data + + @property + def id(self): + """The constellation's ID, as an integer.""" + return self._id + + @property + def name(self): + """The constellation's name, as a string.""" + return self._data["name"] + + @property + def region(self): + """The constellation's region, as a _Region object.""" + return self._universe.region(self._data["region"]) + + +class _Region: + """Represents a region.""" + + def __init__(self, universe, rid, data): + self._universe = universe + self._id = rid + self._data = data + + @property + def id(self): + """The region's ID, as an integer.""" + return self._id + + @property + def name(self): + """The region's name, as a string.""" + return self._data["name"] + + +class _DummySolarSystem(_SolarSystem): + """Represents an unknown or invalid solar system.""" + + def __init__(self, universe): + super().__init__(universe, -1, { + "name": "Unknown", + "constellation": -1, + "region": -1, + "security": 0.0 + }) + + +class _DummyConstellation(_Constellation): + """Represents an unknown or invalid constellation.""" + + def __init__(self, universe): + super().__init__(universe, -1, { + "name": "Unknown", + "region": -1 + }) + + +class _DummyRegion(_Region): + """Represents an unknown or invalid region.""" + + def __init__(self, universe): + super().__init__(universe, -1, { + "name": "Unknown" + }) + + +class Universe: + """EVE API module for static universe data.""" + + def __init__(self, datadir): + self._dir = datadir + + def system(self, sid): + """Return a _SolarSystem with the given ID. + + If the ID is invalid, return a dummy unknown object with ID -1. + """ + ... + return _DummySolarSystem(self) + + def constellation(self, cid): + """Return a _Constellation with the given ID. + + If the ID is invalid, return a dummy unknown object with ID -1. + """ + ... + return _DummyConstellation(self) + + def region(self, rid): + """Return a _Region with the given ID. + + If the ID is invalid, return a dummy unknown object with ID -1. + """ + ... + return _DummyRegion(self) diff --git a/scripts/read_sde.py b/scripts/read_sde.py new file mode 100755 index 0000000..a5b0d91 --- /dev/null +++ b/scripts/read_sde.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +...