From e6ea859f26e50ed133fc3f1c02207ffb10f56969 Mon Sep 17 00:00:00 2001 From: grewn0uille Date: Thu, 8 Feb 2018 17:41:24 +0100 Subject: [PATCH] Add application.cfg, init, model --- sherlog/__init__.py | 21 +++++++++++++++++++++ sherlog/application.cfg | 1 + sherlog/model.py | 25 +++++++++++++++++++++++++ sherlog/sherlog.py | 0 4 files changed, 47 insertions(+) create mode 100644 sherlog/__init__.py create mode 100644 sherlog/application.cfg create mode 100644 sherlog/model.py create mode 100644 sherlog/sherlog.py diff --git a/sherlog/__init__.py b/sherlog/__init__.py new file mode 100644 index 0000000..30e003c --- /dev/null +++ b/sherlog/__init__.py @@ -0,0 +1,21 @@ +import os + +from flask import Flask +from urllib.parse import urlparse + +from sqlalchemy import create_engine + + +app = Flask(__name__) +app.config.from_envvar('FLASK_CONFIG') + +engine = create_engine(app.config['DB']) + +@app.cli.command() +def drop_db(): + filename = urlparse(app.config['DB']).path + if os.path.isfile(filename): + os.remove(filename) + + +from .sherlog import * diff --git a/sherlog/application.cfg b/sherlog/application.cfg new file mode 100644 index 0000000..233ff54 --- /dev/null +++ b/sherlog/application.cfg @@ -0,0 +1 @@ +DB = 'sqlite:////tmp/sherlog.sqlite' diff --git a/sherlog/model.py b/sherlog/model.py new file mode 100644 index 0000000..d0bd24b --- /dev/null +++ b/sherlog/model.py @@ -0,0 +1,25 @@ +from sqlalchemy import Boolean, Column, DateTime, Integer, String +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + + +class Log(Base): + __tablename__ = 'log' + + id = Column(Integer, primary_key=True) + + return_code = Column(Integer, nullable=False) + message = Column(String, nullable=False) + url = Column(String, nullable=True) + ok = Column(Boolean, nullable=False) + host = Column(String, nullable=True) + start = Column(DateTime, nullable=False) + stop = Column(DateTime, nullable=False) + status = Column(String, nullable=False) + + stderr = Column(String, nullable=True) + stdout = Column(String, nullable=True) + command = Column(String, nullable=True) + + server_name = Column(String, nullable=False) diff --git a/sherlog/sherlog.py b/sherlog/sherlog.py new file mode 100644 index 0000000..e69de29