"""Representation of a channel on a tuner """ import logging from sqlobject import SQLObject, StringCol, IntCol, ForeignKey from channel import Channel log = logging.getLogger("channeltuner") class ChannelTuner(SQLObject): tuner = ForeignKey("Tuner", cascade=True) channel = ForeignKey("Channel", default=None, cascade=True) freq = IntCol(default=0) vpid = IntCol(default=None) apid = IntCol(default=None) tpid = IntCol(default=None) def setup(self, name, freq, inversion, bandwidth, feca, fecb, qam, trans_mode, guard, hierarchy, vpid, apid, tpid): self.freq = int(freq) self.vpid = int(vpid) self.apid = int(apid) self.tpid = int(tpid) # Get the list of channels that are an exact match with this # one's name try: chan = Channel.select(Channel.q.label == name).getOne(default=None) if chan is None: self.channel = Channel(label=name) else: self.channel = chan except SQLObjectIntegrityError: log.error("Multiple channels with the same name (%s) found. We have a problem.", name) return self def get_data(self): d = {} for key in ("channelID", "vpid", "apid", "tpid", "freq"): d[key] = getattr(self, key) d["tuner"] = self.tuner.tid return d