def inject_details(): g.devices = db_session.query(Device).order_by(Device.creation_time.desc())\ .all() g.connected_devices = [] g.configured_devices = [] g.new_devices = [] g.grainbin_service = Config.getboolean('services', 'grainbin_service') if g.grainbin_service: g.grainbins = [] g.configured_grainbins = [] g.new_grainbins = [] for dev in g.devices: if dev.connected: g.connected_devices.append(dev) if dev.user_configured: g.configured_devices.append(dev) else: g.new_devices.append(dev) if g.grainbin_service: if dev.user_configured: bins = dev.bins g.grainbins.extend(bins) for grainbin in bins: if grainbin.user_configured: g.configured_grainbins.append(grainbin) else: g.new_grainbins.append(grainbin) return dict()
def main(): context = zmq.Context() broker = Process(target=farm_broker) broker.start() device_service = Process(target=device_manager, args=(context,)) device_service.start() grainbin_enabled = Config.getboolean('services', 'grainbin_service') if grainbin_enabled: grainbin_service = Process(target=grainbin_manager, args=(context,)) grainbin_service.start() try: if grainbin_enabled: grainbin_service.join() device_service.join() broker.join() except KeyboardInterrupt: print("Keyboard interrupt in main") return
from logging.handlers import RotatingFileHandler from datetime import datetime # user made module imports below from user_web import user from device_web import device from grainbin_web import grain_bin from config.config import Config from database.model import db_session, Device, Grainbin app = Flask(__name__) app.secret_key = Config.get('flask', 'secret_key') app.register_blueprint(user, url_prefix='/user') app.register_blueprint(device, url_prefix='/device') if Config.getboolean('services', 'grainbin_service'): app.register_blueprint(grain_bin, url_prefix='/grain_bin') logfile_path = Config.get('flask', 'logfile_path') file_handler = RotatingFileHandler(logfile_path, maxBytes=1024 * 1024 * 10, backupCount=10) file_handler.setLevel(logging.WARNING) formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") file_handler.setFormatter(formatter) app.logger.addHandler(file_handler) @app.template_filter('datetime') def format_datetime(value, format='medium'):