@@ -23,7 +23,7 @@ Guide | |||||
mkdir logs | mkdir logs | ||||
sudo chmod 0600 config/config.yml data/db.sqlite3 | sudo chmod 0600 config/config.yml data/db.sqlite3 | ||||
sudo chown www-data:www-data config/config.yml data data/db.sqlite3 logs | 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 | ### Test | ||||
@@ -19,7 +19,7 @@ from calefaction.util import ( | |||||
app = Flask(__name__) | app = Flask(__name__) | ||||
basepath = Path(__file__).resolve().parent | basepath = Path(__file__).resolve().parent | ||||
config = Config(basepath / "config") | |||||
config = Config(basepath) | |||||
Database.path = str(basepath / "data" / "db.sqlite3") | Database.path = str(basepath / "data" / "db.sqlite3") | ||||
eve = EVE(config) | eve = EVE(config) | ||||
auth = AuthManager(config, eve) | auth = AuthManager(config, eve) | ||||
@@ -30,9 +30,9 @@ class _ModuleIndex(list): | |||||
class Config: | class Config: | ||||
"""Stores application-wide configuration info.""" | """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._data = None | ||||
self._modules = _ModuleIndex() | self._modules = _ModuleIndex() | ||||
self._load() | self._load() | ||||
@@ -60,6 +60,11 @@ class Config: | |||||
return obj | return obj | ||||
@property | @property | ||||
def dir(self): | |||||
"""Return the application's base directory.""" | |||||
return self._dir | |||||
@property | |||||
def modules(self): | def modules(self): | ||||
"""Return a list-like object (a _ModuleIndex) of loaded modules.""" | """Return a list-like object (a _ModuleIndex) of loaded modules.""" | ||||
return self._modules | return self._modules | ||||
@@ -74,7 +79,7 @@ class Config: | |||||
app.config["SERVER_NAME"] = self.get("site.canonical") | app.config["SERVER_NAME"] = self.get("site.canonical") | ||||
app.config["PREFERRED_URL_SCHEME"] = self.scheme | app.config["PREFERRED_URL_SCHEME"] = self.scheme | ||||
app.config["MAKO_MODULE_DIRECTORY"] = str( | app.config["MAKO_MODULE_DIRECTORY"] = str( | ||||
self._dir.parent / "templates" / ".cache") | |||||
self._dir / "templates" / ".cache") | |||||
app.secret_key = self.get("auth.session_key") | app.secret_key = self.get("auth.session_key") | ||||
for module in self.modules: | for module in self.modules: | ||||
@@ -85,7 +90,7 @@ class Config: | |||||
Returns a YAML parse of {confdir}/modules/{name}.yml, or None. | 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: | try: | ||||
with filename.open("rb") as fp: | with filename.open("rb") as fp: | ||||
return yaml.load(fp) | return yaml.load(fp) | ||||
@@ -8,6 +8,7 @@ from .clock import Clock | |||||
from .esi import EVESwaggerInterface | from .esi import EVESwaggerInterface | ||||
from .image import ImageServer | from .image import ImageServer | ||||
from .sso import SSOManager | from .sso import SSOManager | ||||
from .universe import Universe | |||||
from .zkill import ZKillboard | from .zkill import ZKillboard | ||||
from .. import __release__, baseLogger | from .. import __release__, baseLogger | ||||
@@ -26,6 +27,7 @@ class EVE: | |||||
self._esi = EVESwaggerInterface(session, logger.getChild("esi")) | self._esi = EVESwaggerInterface(session, logger.getChild("esi")) | ||||
self._image = ImageServer() | self._image = ImageServer() | ||||
self._sso = SSOManager(session, logger.getChild("sso")) | self._sso = SSOManager(session, logger.getChild("sso")) | ||||
self._universe = Universe(config.dir / "data" / "universe") | |||||
self._zkill = ZKillboard(session, logger.getChild("zkill")) | self._zkill = ZKillboard(session, logger.getChild("zkill")) | ||||
@staticmethod | @staticmethod | ||||
@@ -58,6 +60,11 @@ class EVE: | |||||
return self._sso | return self._sso | ||||
@property | @property | ||||
def universe(self): | |||||
"""The Universe API module.""" | |||||
return self._universe | |||||
@property | |||||
def zkill(self): | def zkill(self): | ||||
"""The zKillboard API module.""" | """The zKillboard API module.""" | ||||
return self._zkill | return self._zkill |
@@ -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) |
@@ -0,0 +1,4 @@ | |||||
#!/usr/bin/env python3 | |||||
# -*- coding: utf-8 -*- | |||||
... |