# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 OpenLP Developers #
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see . #
##########################################################################
"""
:mod:`openlp.core.lib.projector.db` module
Provides the database functions for the Projector module.
The Manufacturer, Model, Source tables keep track of the video source
strings used for display of input sources. The Source table maps
manufacturer-defined or user-defined strings from PJLink default strings
to end-user readable strings; ex: PJLink code 11 would map "RGB 1"
default string to "RGB PC (analog)" string.
(Future feature).
The Projector table keeps track of entries for controlled projectors.
"""
import logging
from sqlalchemy import Column, ForeignKey, Integer, MetaData, String, and_
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.orm import relationship
from openlp.core.lib.db import Manager, init_db, init_url
from openlp.core.projectors import upgrade
from openlp.core.projectors.constants import PJLINK_DEFAULT_CODES
log = logging.getLogger(__name__)
log.debug('projector.lib.db module loaded')
Base = declarative_base(MetaData())
class CommonMixin(object):
"""
Base class to automate table name and ID column.
"""
@declared_attr
def __tablename__(self):
return self.__name__.lower()
id = Column(Integer, primary_key=True)
class Manufacturer(Base, CommonMixin):
"""
Projector manufacturer table.
Manufacturer:
name: Column(String(30))
models: Relationship(Model.id)
Model table is related.
"""
def __repr__(self):
"""
Returns a basic representation of a Manufacturer table entry.
"""
return ''.format(name=self.name)
name = Column(String(30))
models = relationship('Model',
order_by='Model.name',
backref='manufacturer',
cascade='all, delete-orphan',
primaryjoin='Manufacturer.id==Model.manufacturer_id',
lazy='joined')
class Model(Base, CommonMixin):
"""
Projector model table.
Model:
name: Column(String(20))
sources: Relationship(Source.id)
manufacturer_id: Foreign_key(Manufacturer.id)
Manufacturer table links here.
Source table is related.
"""
def __repr__(self):
"""
Returns a basic representation of a Model table entry.
"""
return ''.format(name=self.name)
manufacturer_id = Column(Integer, ForeignKey('manufacturer.id'))
name = Column(String(20))
sources = relationship('Source',
order_by='Source.pjlink_name',
backref='model',
cascade='all, delete-orphan',
primaryjoin='Model.id==Source.model_id',
lazy='joined')
class Source(Base, CommonMixin):
"""
Projector video source table.
Source:
pjlink_name: Column(String(15))
pjlink_code: Column(String(2))
text: Column(String(30))
model_id: Foreign_key(Model.id)
Model table links here.
These entries map PJLink input video source codes to text strings.
"""
def __repr__(self):
"""
Return basic representation of Source table entry.
"""
return '