Files
DemonEditor/main/eparser/satxml.py

141 lines
5.4 KiB
Python
Raw Normal View History

2017-10-09 22:19:51 +03:00
""" Module foe parsing Satellites.xml
2017-10-06 23:27:08 +03:00
2017-10-09 22:19:51 +03:00
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
2017-10-20 14:45:51 +03:00
from xml.dom.minidom import parse, Document
2017-10-26 16:23:05 +03:00
2017-10-20 14:45:51 +03:00
from main.eparser.__constants import POLARIZATION, FEC, SYSTEM, MODULATION, PLS_MODE
2017-10-26 01:23:05 +03:00
__FILE_NAME = "satellites.xml"
2017-10-06 23:27:08 +03:00
2017-10-09 22:19:51 +03:00
Satellite = namedtuple("Satellite", ["name", "flags", "position", "transponders"])
2017-10-06 23:27:08 +03:00
2017-10-09 22:19:51 +03:00
Transponder = namedtuple("Transponder", ["frequency", "symbol_rate", "polarization", "fec_inner",
"system", "modulation", "pls_mode", "pls_code", "is_id"])
2017-10-06 23:27:08 +03:00
2017-10-20 14:45:51 +03:00
__COMMENT = (" File was created in DemonEditor\n\n"
"useable flags are\n"
" 1: Network Scan\n"
" 2: use BAT\n"
" 4: use ONIT\n"
" 8: skip NITs of known networks\n"
" and combinations of this.\n\n"
"transponder parameters:\n"
"polarization: 0 - Horizontal, 1 - Vertical, 2 - Left Circular, 3 - Right Circular\n"
"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\n"
"modulation: 0 - Auto, 1 - QPSK, 2 - 8PSK, 3 - 16APSK, 5 - 32APSK\n"
"rolloff: 0 - 0.35, 1 - 0.25, 2 - 0.20, 3 - Auto\n"
"pilot: 0 - Off, 1 - On, 2 - Auto\n"
"inversion: 0 = Off, 1 = On, 2 = Auto (default)\n"
"system: 0 = DVB-S, 1 = DVB-S2\n"
"is_id: 0 - 255\n"
"pls_mode: 0 - Root, 1 - Gold, 2 - Combo\n"
"pls_code: 0 - 262142\n\n"
"Info taken from satellites.xml generated by http://satellites-xml.eu\n")
2017-10-06 23:27:08 +03:00
def get_satellites(path):
return parse_satellites(path + "satellites.xml")
2017-10-10 14:13:35 +03:00
2017-10-20 14:45:51 +03:00
def write_satellites(satellites, data_path):
""" Creation satellites.xml file """
doc = Document()
comment = doc.createComment(__COMMENT)
doc.appendChild(comment)
root = doc.createElement("satellites")
doc.appendChild(root)
2017-10-26 01:23:05 +03:00
2017-10-20 14:45:51 +03:00
for sat in satellites:
# Create Element
sat_child = doc.createElement("sat")
sat_child.setAttribute("name", sat.name)
sat_child.setAttribute("flags", sat.flags)
sat_child.setAttribute("position", sat.position)
2017-10-26 01:23:05 +03:00
2017-10-20 14:45:51 +03:00
for tr in sat.transponders:
transponder_child = doc.createElement("transponder")
transponder_child.setAttribute("frequency", tr.frequency)
transponder_child.setAttribute("symbol_rate", tr.symbol_rate)
transponder_child.setAttribute("polarization", get_key_by_value(POLARIZATION, tr.polarization))
transponder_child.setAttribute("fec_inner", get_key_by_value(FEC, tr.fec_inner))
transponder_child.setAttribute("system", get_key_by_value(SYSTEM, tr.system))
transponder_child.setAttribute("modulation", get_key_by_value(MODULATION, tr.modulation))
if tr.pls_mode:
transponder_child.setAttribute("pls_mode", get_key_by_value(PLS_MODE, tr.pls_mode))
if tr.pls_code:
transponder_child.setAttribute("pls_code", tr.pls_code)
if tr.is_id:
transponder_child.setAttribute("is_id", tr.is_id)
sat_child.appendChild(transponder_child)
root.appendChild(sat_child)
2017-10-26 01:23:05 +03:00
doc.writexml(open(data_path + __FILE_NAME, "w"),
2017-10-20 14:45:51 +03:00
# indent="",
addindent=" ",
newl='\n',
encoding="iso-8859-1")
doc.unlink()
2017-10-10 14:13:35 +03:00
def parse_transponders(elem):
2017-10-09 22:19:51 +03:00
""" 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,
2017-10-20 14:45:51 +03:00
POLARIZATION[atr["polarization"].value],
FEC[atr["fec_inner"].value],
SYSTEM[atr["system"].value],
MODULATION[atr["modulation"].value],
PLS_MODE[atr["pls_mode"].value] if "pls_mode" in atr else None,
2017-10-09 22:19:51 +03:00
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
2017-10-06 23:27:08 +03:00
2017-10-10 14:13:35 +03:00
def parse_sat(elem):
2017-10-09 22:19:51 +03:00
""" Parsing satellite """
return Satellite(elem.attributes["name"].value,
elem.attributes["flags"].value,
elem.attributes["position"].value,
2017-10-10 14:13:35 +03:00
parse_transponders(elem))
2017-10-06 23:27:08 +03:00
2017-10-10 14:13:35 +03:00
def parse_satellites(path):
2017-10-09 22:19:51 +03:00
""" Parsing satellites from xml"""
dom = parse(path)
satellites = []
2017-10-26 01:23:05 +03:00
2017-10-09 22:19:51 +03:00
for elem in dom.getElementsByTagName("sat"):
if elem.hasAttributes():
2017-10-10 14:13:35 +03:00
satellites.append(parse_sat(elem))
2017-10-26 01:23:05 +03:00
2017-10-09 22:19:51 +03:00
return satellites
2017-10-20 14:45:51 +03:00
def get_key_by_value(dictionary, value):
for k, v in dictionary.items():
if v == value:
return k
if __name__ == "__main__":
2017-10-26 01:23:05 +03:00
pass