"""Module for managing/interacting with the local data store.""" import os import glob import sqlite3 from datetime import datetime from aachaos.config import settings # Define some module constants PATH_SQL = os.path.join(os.path.dirname(__file__), 'sql') PATH_DB = settings.get('Path', 'Database') class DB(sqlite3.Connection): path_db = PATH_DB dtfmt = '%Y-%m-%d %H:%M' def __init__(self): # Connection is created on initialisation. If the database # file isn't present already, create the directory structure # and before initialising, then create the schema. fpath = self.path_db if not os.path.isfile(fpath): if fpath != ':memory:': # mkdir -p os.makedirs(os.path.dirname(fpath), exist_ok=True) super().__init__(fpath) self.create()
import os import tornado.ioloop import tornado.web from aachaos.config import settings FIG_PATH = settings.get('Path', 'Figure') TMP_PATH = '.'.join([FIG_PATH, 'tmp']) class QuasiStaticHandler(tornado.web.StaticFileHandler): def set_extra_headers(self, path): self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate') def make_app(): return tornado.web.Application([ # The fig could be mapped to e.g. server:port/netquota with # r'/netquota()' (r'/()', QuasiStaticHandler, {'path': FIG_PATH}), ]) def create_figure(): plotter = vis.Plotter() plotter.plot_month()