示例#1
0
 def toDom(self, parentNode, flags=None):
     fieldNode = XMLIntf.SubElement(parentNode, u"field")
     XMLIntf.appendTextElements(fieldNode,
                                ((u"Number", unicode(self.FieldNumber)),
                                 (u"Name", self.FieldName),
                                 (u"Kind", self.Kind),
                                 (u"MaxLength", unicode(self.MaxLength))))
示例#2
0
 def toDom(self, parentNode):
     leaf = XMLIntf.SubElement(parentNode, u"leaf")
     XMLIntf.appendTextElements(leaf, {
         "kind": self.BroadcastType,
         "station-id": self.StationID
     })
     for frequency in self.Frequencies:
         frequency.toDom(leaf)
示例#3
0
 def toDom(self, parentNode, flags = None):
     fieldNode = XMLIntf.SubElement(parentNode, u"field")
     XMLIntf.appendTextElements(fieldNode, (
         (u"Number", unicode(self.FieldNumber)),
         (u"Name", self.FieldName),
         (u"Kind", self.Kind),
         (u"MaxLength", unicode(self.MaxLength))
     ))
示例#4
0
 def toDom(self, parentNode):
     leaf = XMLIntf.SubElement(parentNode, u"leaf")
     XMLIntf.appendTextElements(leaf, {
         "kind": self.BroadcastType,
         "station-id": self.StationID
     })
     for frequency in self.Frequencies:
         frequency.toDom(leaf)
示例#5
0
    def toDom(self, parentNode, flags=None):
        classNode = XMLIntf.SubElement(parentNode, u"transmission-class")
        XMLIntf.appendTextElements(classNode,
                                   ((u"ID", unicode(self.ID)),
                                    (u"DisplayName", self.DisplayName)))

        tablesNode = XMLIntf.SubElement(classNode, u"tables")
        for table in self.Tables:
            table.toDom(tablesNode, flags)
示例#6
0
    def toDom(self, parentNode, flags = None):
        classNode = XMLIntf.SubElement(parentNode, u"transmission-class")
        XMLIntf.appendTextElements(classNode, (
            (u"ID", unicode(self.ID)),
            (u"DisplayName", self.DisplayName)
        ))

        tablesNode = XMLIntf.SubElement(classNode, u"tables")
        for table in self.Tables:
            table.toDom(tablesNode, flags)
示例#7
0
    def toDom(self, parentNode, flags=None):
        tableNode = XMLIntf.SubElement(parentNode, u"table")
        XMLIntf.appendTextElements(tableNode,
                                   (("TableName", self.TableName),
                                    ("DisplayName", self.DisplayName),
                                    ("XMLGroupClass", self.XMLGroupClass)))

        fieldsNode = XMLIntf.SubElement(tableNode, u"fields")
        for field in self.Fields:
            field.toDom(fieldsNode, flags)
示例#8
0
    def toDom(self, parentNode, flags = None):
        tableNode = XMLIntf.SubElement(parentNode, u"table")
        XMLIntf.appendTextElements(tableNode, (
            ("TableName", self.TableName),
            ("DisplayName", self.DisplayName),
            ("XMLGroupClass", self.XMLGroupClass)
        ))

        fieldsNode = XMLIntf.SubElement(tableNode, u"fields")
        for field in self.Fields:
            field.toDom(fieldsNode, flags)
示例#9
0
    def toDom(self, parentNode, flags=None):
        transmission = XMLIntf.SubElement(parentNode, u"transmission")
        XMLIntf.SubElement(transmission, u"ID").text = unicode(self.ID)
        self._metadataToDom(transmission)

        if flags is not None and self.Broadcast is not None and "with-freqs" in flags:
            for freq in self.Broadcast.Frequencies:
                freq.toDom(transmission)

        contents = XMLIntf.SubElement(transmission, u"Contents")
        for block in self.blocks:
            block.toDom(contents)
示例#10
0
    def toDom(self, parentNode):
        group = XMLIntf.SubElement(
            parentNode, u"group", {
                u"class": self.TransmissionTable.XMLGroupClass,
                u"name": self.TransmissionTable.TableName
            })

        for (field, value) in self:
            kind = field.Kind
            XMLIntf.SubElement(group, u"item", {u"class": kind}).text = value
            supplement = self.supplements[field.FieldName]
            node = supplement.toDom(group, u"item", {u"class": kind})
示例#11
0
    def _loadSchedules(self, element, context):
        for child in element:
            tag = XMLIntf.checkAndStripNamespace(child,
                                                 XMLIntf.importNamespace,
                                                 context)
            if tag is None:
                continue
            if tag != "schedule-reference":
                context.log(
                    "Found invalid node in schedule.schedules. Skipping.")
                continue

            try:
                id = int(child.get(u"id"))
            except:
                context.log(
                    "Schedule references in schedule.schedules must consist only of <schedule id=\"id\" />"
                )
                continue

            schedule = self.store.get(Schedule, id)
            if schedule is not None:
                if schedule.Parent is not None:
                    context.log(
                        "Schedule %d is already assigned to another parent." %
                        (schedule.ID))
                    continue
                if not Schedule.checkNestable(self.ScheduleKind,
                                              schedule.ScheduleKind):
                    context.log(
                        "Cannot nest a \"%s\" schedule into a \"%s\" schedule."
                        % (self.ScheduleKind, schedule.ScheduleKind))
                    continue
                schedule.Parent = self
示例#12
0
 def toDom(self, parentNode, flags = None):
     station = XMLIntf.SubElement(parentNode, u"station")
     XMLIntf.appendTextElement(station, u"ID", unicode(self.ID))
     if flags is None or not "no-metadata" in flags:
         self._metadataToDom(station)
     
     if flags is None or "schedule" in flags:
         if self.Schedule is not None:
             scheduleNode = self.Schedule.toDom(station, self.ID)
             if self.ScheduleConfirmed:
                 scheduleNode.set("confirmed", "true")
             else:
                 scheduleNode.set("confirmed", "false")
         elif self.ScheduleConfirmed:
             XMLIntf.SubElement(station, u"schedule", attrib={
                 u"confirmed": u"true"
             })
         
     if flags is None or "broadcasts" in flags:
         broadcasts = XMLIntf.SubElement(parentNode, u"broadcasts")
         for broadcast in self.Broadcasts:
             broadcast.toDom(broadcasts, flags)
示例#13
0
 def _broadcastsFromDom(self, element, context):
     for child in element:
         tag = XMLIntf.checkAndStripNamespace(element, context=context)
         if tag is None:
             continue
         if tag == u"broadcast":
             broadcast = context.importFromETree(child, Broadcast)
             if broadcast is None:
                 continue
             if broadcast.Station != self and broadcast.ScheduleLeaf is not None and broadcast.ScheduleLeaf.Station != self:
                 context.log("Cannot reassign a broadcast which is bound to a schedule leaf which is not assigned to target station.")
             else:
                 broadcast.Station = self
示例#14
0
    def toDom(self, parentNode, flags=None):
        broadcast = XMLIntf.SubElement(parentNode, u"broadcast")

        XMLIntf.appendTextElement(broadcast, u"ID", unicode(self.ID))
        XMLIntf.appendDateElement(broadcast, u"Start", self.BroadcastStart)
        if self.BroadcastEnd is not None:
            XMLIntf.appendDateElement(broadcast, u"End", self.BroadcastEnd)
        XMLIntf.appendTextElements(
            broadcast, [(u"StationID", unicode(self.StationID)),
                        (u"Type", self.Type),
                        (u"Confirmed", "" if self.Confirmed else None),
                        (u"on-air", "" if self.getIsOnAir() else None),
                        (u"has-transmissions",
                         "" if self.Transmissions.count() > 0 else None)])
        for frequency in self.Frequencies:
            frequency.toDom(broadcast)

        if flags is not None and "broadcast-transmissions" in flags:
            for transmission in self.Transmissions:
                transmission.toDom(broadcast, flags)
示例#15
0
 def _loadLeaves(self, element, context):
     for leaf in list(self.Leaves):
         leaf.delete()
     for child in element:
         tag = XMLIntf.checkAndStripNamespace(child, XMLIntf.importNamespace, context)
         if tag is None:
             continue
         if tag != u"leaf":
             context.log("Found invalid node in schedule.leaves. Skipping.")
             continue
         
         leaf = ScheduleLeaf()
         self.store.add(leaf)
         leaf.Schedule = self
         leaf.fromDom(child)
示例#16
0
 def _metadataToDom(self, parentNode):
     XMLIntf.appendTextElements(parentNode,
                                ((u"BroadcastID", self.Broadcast.ID),
                                 (u"ClassID", self.Class.ID),
                                 (u"Callsign", self.Callsign)))
     self.ForeignCallsign.toDom(parentNode, u"Callsign")
     XMLIntf.appendDateElement(parentNode, u"Timestamp", self.Timestamp)
     XMLIntf.appendTextElements(parentNode,
                                ((u"Recording", self.RecordingURL),
                                 (u"Remarks", self.Remarks)))
示例#17
0
    def _loadLeaves(self, element, context):
        for leaf in list(self.Leaves):
            leaf.delete()
        for child in element:
            tag = XMLIntf.checkAndStripNamespace(child,
                                                 XMLIntf.importNamespace,
                                                 context)
            if tag is None:
                continue
            if tag != u"leaf":
                context.log("Found invalid node in schedule.leaves. Skipping.")
                continue

            leaf = ScheduleLeaf()
            self.store.add(leaf)
            leaf.Schedule = self
            leaf.fromDom(child)
示例#18
0
 def _metadataToDom(self, parentNode):
     XMLIntf.appendTextElements(parentNode,
         (
             (u"EnigmaIdentifier", self.EnigmaIdentifier),
             (u"PriyomIdentifier", self.PriyomIdentifier),
             (u"Nickname", self.Nickname)
         )
     )
     subtree = ElementTree.XML((u"<Description>"+self.Description+u"</Description>").encode("utf-8"))
     XMLIntf.applyNamespace(subtree, XMLIntf.xhtmlNamespace)
     subtree.tag = u"{{{0}}}Description".format(XMLIntf.namespace)
     parentNode.append(subtree)
     
     XMLIntf.appendTextElements(parentNode,
         [
             (u"Status", self.Status)
         ],
         noneHandler = lambda name: u""
     )
     if self.Location is not None:
         XMLIntf.appendTextElement(parentNode, u"Location", self.Location)
     if self.getIsOnAir():
         XMLIntf.SubElement(parentNode, u"on-air")
示例#19
0
 def _metadataToDom(self, parentNode):
     XMLIntf.appendTextElements(parentNode,
         (
             (u"BroadcastID", self.Broadcast.ID),
             (u"ClassID", self.Class.ID),
             (u"Callsign", self.Callsign)
         )
     )
     self.ForeignCallsign.toDom(parentNode, u"Callsign")
     XMLIntf.appendDateElement(parentNode, u"Timestamp", self.Timestamp)
     XMLIntf.appendTextElements(parentNode,
         (
             (u"Recording", self.RecordingURL),
             (u"Remarks", self.Remarks)
         )
     )
示例#20
0
 def _loadSchedules(self, element, context):
     for child in element:
         tag = XMLIntf.checkAndStripNamespace(child, XMLIntf.importNamespace, context)
         if tag is None:
             continue
         if tag != "schedule-reference":
             context.log("Found invalid node in schedule.schedules. Skipping.")
             continue
         
         try:
             id = int(child.get(u"id"))
         except:
             context.log("Schedule references in schedule.schedules must consist only of <schedule id=\"id\" />")
             continue
         
         schedule = self.store.get(Schedule, id)
         if schedule is not None:
             if schedule.Parent is not None:
                 context.log("Schedule %d is already assigned to another parent." % (schedule.ID))
                 continue
             if not Schedule.checkNestable(self.ScheduleKind, schedule.ScheduleKind):
                 context.log("Cannot nest a \"%s\" schedule into a \"%s\" schedule." % (self.ScheduleKind, schedule.ScheduleKind))
                 continue
             schedule.Parent = self
示例#21
0
    def toDom(self, parentNode, stationId=None):
        store = Store.of(self)
        schedule = XMLIntf.SubElement(u"schedule")

        XMLIntf.appendTextElements(schedule, (("id", unicode(self.ID)),
                                              ("name", self.Name)))
        if self.ScheduleKind == u"once":
            XMLIntf.SubElement(schedule, u"no-repeat")
        else:
            XMLIntf.appendTextElement(schedule,
                                      u"repeat",
                                      unicode(self.Every),
                                      attrib={
                                          u"step": self.ScheduleKind,
                                          u"skip": unicode(self.Skip)
                                      })

        start = datetime.datetime.fromtimestamp(self.StartTimeOffset)
        start = start - datetime.timedelta(hours=1)

        end = None
        if self.EndTimeOffset is not None:
            end = datetime.datetime.fromtimestamp(self.EndTimeOffset)
            end = end - datetime.timedelta(hours=1)
        else:
            end = datetime.datetime.fromtimestamp(0)

        startStr, endStr = {
            "once": self._formatOnce(start, end),
            "year": self._formatYear(start, end),
            "month": self._formatMonth(start, end),
            "week": self._formatWeek(start, end),
            "day": self._formatDay(start, end),
            "hour": self._formatHour(start, end)
        }[self.ScheduleKind]

        XMLIntf.appendTextElement(
            schedule,
            u"start-offset",
            startStr,
            attrib={u"seconds": unicode(self.StartTimeOffset)})

        if self.EndTimeOffset is not None:
            XMLIntf.appendTextElement(
                schedule,
                u"end-offset",
                endStr,
                attrib={u"seconds": unicode(self.EndTimeOffset)})

        schedules = XMLIntf.SubElement(schedule, u"schedules")
        for _schedule in self.Children:
            _schedule.toDom(schedules, stationId)

        leaves = XMLIntf.SubElement(schedule, u"leaves")
        if stationId is not None:
            leavesSelect = store.find(ScheduleLeaf,
                                      (ScheduleLeaf.StationID == stationId)
                                      and (ScheduleLeaf.ScheduleID == self.ID))
            for leaf in leavesSelect:
                leaf.toDom(leaves)
        else:
            for leaf in self.Leaves:
                leaf.toDom(leaves)

        return schedule
示例#22
0
 def toDom(self, parentNode):
     XMLIntf.appendTextElement(parentNode,
                               u"frequency",
                               unicode(self.Frequency),
                               attrib={u"modulation": self.Modulation.Name})
示例#23
0
 def toDom(self, parentNode, stationId = None):
     store = Store.of(self)
     schedule = XMLIntf.SubElement(u"schedule")
     
     XMLIntf.appendTextElements(schedule,
         (
             ("id", unicode(self.ID)),
             ("name", self.Name)
         )
     )
     if self.ScheduleKind == u"once":
         XMLIntf.SubElement(schedule, u"no-repeat")
     else:
         XMLIntf.appendTextElement(schedule, u"repeat", unicode(self.Every), attrib={
             u"step": self.ScheduleKind,
             u"skip": unicode(self.Skip)
         })
     
     start = datetime.datetime.fromtimestamp(self.StartTimeOffset)
     start = start - datetime.timedelta(hours=1)
     
     end = None
     if self.EndTimeOffset is not None:
         end = datetime.datetime.fromtimestamp(self.EndTimeOffset)
         end = end - datetime.timedelta(hours=1)
     else:
         end = datetime.datetime.fromtimestamp(0)
         
     startStr, endStr = {
         "once": self._formatOnce(start, end),
         "year": self._formatYear(start, end),
         "month": self._formatMonth(start, end),
         "week": self._formatWeek(start, end),
         "day": self._formatDay(start, end),
         "hour": self._formatHour(start, end)
     }[self.ScheduleKind]
     
     XMLIntf.appendTextElement(schedule, u"start-offset", startStr, attrib={
         u"seconds": unicode(self.StartTimeOffset)
     })
     
     if self.EndTimeOffset is not None:
         XMLIntf.appendTextElement(schedule, u"end-offset", endStr, attrib={
             u"seconds": unicode(self.EndTimeOffset)
         })
     
     schedules = XMLIntf.SubElement(schedule, u"schedules")
     for _schedule in self.Children:
         _schedule.toDom(schedules, stationId)
     
     leaves = XMLIntf.SubElement(schedule, u"leaves")
     if stationId is not None:
         leavesSelect = store.find(ScheduleLeaf, 
             (ScheduleLeaf.StationID == stationId) and (ScheduleLeaf.ScheduleID == self.ID))
         for leaf in leavesSelect:
             leaf.toDom(leaves)
     else:
         for leaf in self.Leaves:
             leaf.toDom(leaves)
     
     return schedule
示例#24
0
 def toDom(self, parentNode):
     XMLIntf.appendTextElement(parentNode, u"frequency", unicode(self.Frequency), attrib={
         u"modulation": self.Modulation.Name
     })