mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-01-16 04:23:35 +01:00
parsing Satellites.xml
This commit is contained in:
@@ -1,3 +1,37 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Type(Enum):
|
||||
""" Types of DVB transponders """
|
||||
Satellite = "s"
|
||||
Terestrial = "t"
|
||||
Cable = "c"
|
||||
|
||||
|
||||
class Polarization(Enum):
|
||||
H = 0
|
||||
V = 1
|
||||
L = 2
|
||||
R = 3
|
||||
|
||||
|
||||
class Plsmode(Enum):
|
||||
Root = 0
|
||||
Gold = 1
|
||||
Combo = 2
|
||||
|
||||
|
||||
# Symbol rate
|
||||
Fec = {0: "None", 1: "Auto", 2: "1/2",
|
||||
3: "2/3", 4: "3/4", 5: "5/6",
|
||||
6: "7/8", 7: "3/5", 8: "4/5",
|
||||
9: "8/9", 10: "9/10"}
|
||||
|
||||
System = {0: "DVB-S", 1: "DVB_S2"}
|
||||
|
||||
Modulation = {0: "Auto", 1: "QPSK", 2: "8PSK", 3: "16APSK", 5: "32APSK"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Description of format taken from here: http://www.satsupreme.com/showthread.php/194074-Lamedb-format-explained
|
||||
"""
|
||||
from collections import namedtuple
|
||||
from enum import Enum
|
||||
from main.eparser import Polarization, System, Fec
|
||||
|
||||
Channel = namedtuple("Channel", ["service", "package", "service_type",
|
||||
"ssid", "freq", "rate", "pol", "fec", "system", "pos"])
|
||||
@@ -14,28 +14,6 @@ _FILE_PATH = "../data/lamedb"
|
||||
_SEP = ":" # separator
|
||||
|
||||
|
||||
class Type(Enum):
|
||||
""" Types of DVB transponders """
|
||||
Satellite = "s"
|
||||
Terestrial = "t"
|
||||
Cable = "c"
|
||||
|
||||
|
||||
class Polarization(Enum):
|
||||
H = 0
|
||||
V = 1
|
||||
L = 2
|
||||
R = 3
|
||||
|
||||
|
||||
# Symbol rate
|
||||
FEC = {0: "None", 1: "Auto", 2: "1/2",
|
||||
3: "2/3", 4: "3/4", 5: "5/6",
|
||||
6: "7/8", 7: "3/5", 8: "4/5",
|
||||
9: "8/9", 10: "9/10"}
|
||||
|
||||
SYSTEM = {0: "DVB-S", 1: "DVB_S2"}
|
||||
|
||||
SERVICE_TYPE = {-2: "Unknown", 1: "TV", 2: "Radio", 3: "Data",
|
||||
10: "Radio", 12: "Data", 22: "TV", 25: "TV",
|
||||
136: "Data", 139: "Data"}
|
||||
@@ -48,7 +26,6 @@ def parse(path):
|
||||
transponders, sep, services = data.partition("transponders") # 1 step
|
||||
transponders, sep, services = services.partition("services") # 2 step
|
||||
services, sep, _ = services.partition("end") # 3 step
|
||||
|
||||
return get_channels(services.split("\n"), transponders.split("/"))
|
||||
|
||||
|
||||
@@ -59,7 +36,6 @@ def get_transponders(arg):
|
||||
tr = ar.replace("\n", "").split("\t")
|
||||
if len(tr) == 2:
|
||||
transponders[tr[0]] = tr[1]
|
||||
|
||||
return transponders
|
||||
|
||||
|
||||
@@ -81,8 +57,7 @@ def get_channels(*args):
|
||||
pack = pack[2:] if pack.find(",") < 0 else pack[2:pack.find(",")]
|
||||
channels.append(Channel(ch[1], pack, SERVICE_TYPE.get(int(data[4]), SERVICE_TYPE[-2]), data[0], tr[0],
|
||||
tr[1], Polarization(int(tr[2])).name,
|
||||
FEC[int(tr[3])], SYSTEM[int(tr[6])], "{}{}.{}".format(*list(tr[4]))))
|
||||
|
||||
Fec[int(tr[3])], System[int(tr[6])], "{}{}.{}".format(*list(tr[4]))))
|
||||
return channels
|
||||
|
||||
|
||||
|
||||
@@ -1,39 +1,65 @@
|
||||
""" Module foe parsing Satellites.xml
|
||||
|
||||
Transponder parameters:
|
||||
polarization: 0 - Horizontal, 1 - Vertical, 2 - Left Circular, 3 - Right Circular
|
||||
fec_inner: 0 - Auto, 1 - 1/2, 2 - 2_3, 3 - 3/4, 4 - 5/6, 5 - 6/7, 6 - 7/8, 7 - 8/9, 8 - 3/5, 9 - 4/5, 10 - 9/10
|
||||
modulation: 0 - Auto, 1 - QPSK, 2 - 8PSK, 3 - 16APSK, 5 - 32APSK
|
||||
rolloff: 0 - 0.35, 1 - 0.25, 2 - 0.20, 3 - Auto
|
||||
pilot: 0 - Off, 1 - On, 2 - Auto
|
||||
inversion: 0 = Off, 1 = On, 2 = Auto (default)
|
||||
system: 0 = DVB-S, 1 = DVB-S2
|
||||
is_id: 0 - 255
|
||||
pls_mode: 0 - Root, 1 - Gold, 2 - Combo
|
||||
pls_code: 0 - 262142
|
||||
"""
|
||||
from collections import namedtuple
|
||||
from xml.dom.minidom import parse
|
||||
|
||||
XML_PATH = "files/satellites.xml"
|
||||
from main.eparser import Polarization, System, Fec, Modulation, Plsmode
|
||||
|
||||
XML_PATH = "../data/satellites.xml"
|
||||
|
||||
Satellite = namedtuple("Satellite", ["name", "flags", "position", "transponders"])
|
||||
|
||||
Transponder = namedtuple("Transponder", ["frequency", "symbol_rate", "polarization", "fec_inner",
|
||||
"system", "modulation", "pls_mode", "pls_code", "is_id"])
|
||||
|
||||
|
||||
class Satellite:
|
||||
__slots__ = ["_name", "_flags", "_position", "_transponders"]
|
||||
|
||||
def __init__(self, name, flags=None, position=None, transponders=None):
|
||||
self._name = name
|
||||
self._flags = flags
|
||||
self._position = position
|
||||
self._transponders = transponders
|
||||
|
||||
def __repr__(self):
|
||||
return str([self._name, self._flags, self._position, self._transponders])
|
||||
def get_transponders(elem):
|
||||
""" Parsing satellite transponders """
|
||||
transponders = []
|
||||
for el in elem.getElementsByTagName("transponder"):
|
||||
if el.hasAttributes():
|
||||
atr = el.attributes
|
||||
tr = Transponder(atr["frequency"].value,
|
||||
atr["symbol_rate"].value,
|
||||
Polarization(int(atr["polarization"].value)).name,
|
||||
Fec[int(atr["fec_inner"].value)],
|
||||
System[int(atr["system"].value)],
|
||||
Modulation[int(atr["modulation"].value)],
|
||||
Plsmode(int(atr["pls_mode"].value)).name if "pls_mode" in atr else None,
|
||||
atr["pls_code"].value if "pls_code" in atr else None,
|
||||
atr["is_id"].value if "is_id" in atr else None)
|
||||
transponders.append(tr)
|
||||
return transponders
|
||||
|
||||
|
||||
dom = parse(XML_PATH)
|
||||
def get_sat(elem):
|
||||
""" Parsing satellite """
|
||||
return Satellite(elem.attributes["name"].value,
|
||||
elem.attributes["flags"].value,
|
||||
elem.attributes["position"].value,
|
||||
get_transponders(elem))
|
||||
|
||||
satellites = []
|
||||
|
||||
for elem in dom.getElementsByTagName("sat"):
|
||||
if elem.hasAttributes():
|
||||
# print(elem.attributes.keys())
|
||||
# print(elem.attributes.values())
|
||||
|
||||
sat = Satellite(elem.attributes["name"].value, elem.attributes["flags"].value, elem.attributes["position"].value)
|
||||
satellites.append(sat)
|
||||
# for key in elem.attributes.keys():
|
||||
# satellites.append(Sat())
|
||||
# atr = elem.attributes[key]
|
||||
# print(atr.name, atr.value)
|
||||
|
||||
for sat in satellites:
|
||||
print(sat)
|
||||
def get_satellites(path):
|
||||
""" Parsing satellites from xml"""
|
||||
dom = parse(path)
|
||||
satellites = []
|
||||
for elem in dom.getElementsByTagName("sat"):
|
||||
if elem.hasAttributes():
|
||||
satellites.append(get_sat(elem))
|
||||
return satellites
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user