Skip to content

simulate-digital-rail/planpro-importer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

planpro-importer

This is a small library (generated by generateDS.py) that can import PlanPro files into a yaramo topology for further processing.

It supports:

  • Full model support according to the schema
  • Parsing of ppxml files
  • Finder for UUID of infrastructure elements

Current version:

  • Schema version: 1.9.0.1202_2019-02-22
  • Library version: 1.9.0.1202_2019-02-22-v2

Installation

Just install it with pip:

pip3 install git+https://github.com/arneboockmeyer/planpro-python-model

You may need some authentication (Hint 1, Hint 2).

Usage

Parse a PlanPro file:

from planpro_importer.reader import PlanProReader
topology = PlanProReader("filename.ppxml").read_topology_from_plan_pro_file()

Further examples can be found in the demo repository.

Usage UUID finder

Import:

import uuidfinder

Method:

uuidfinder.find_infrastructure_element_by_uuid(<Infrastructure Container>, <UUID>)

Example:

import planpromodel
import uuidfinder
root_object = planpromodel.parse('PlanProFile.ppxml')
container = root_object.LST_Planung.Fachdaten.Ausgabe_Fachdaten[0].LST_Zustand_Ziel.Container
uuidfinder.find_infrastructure_element_by_uuid(container, "ABCDEF12-3456-7890-ABCD-EF1234567890")

Generate a new model

Use generateDS.py to generate a model from the PlanPro-XSD-files. Therefore you need the schema files of the current PlanPro version.

CLI-Command:

python3 generateDS.py -o planpromodel.py -f --output-directory="." 1.9.0.1202_2019-02-22_Schema/PlanPro.xsd

Troubleshooting

TypeError: expected string or bytes-like object

File "path-to/planpromodel.py", line 530, in gds_validate_simple_patterns
  mo = re_.search(patterns2, target)
File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 201, in search
  return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object

Add target = str(target) at the top of the method gds_validate_simple_patterns (around line 521) in the planpromodel.py.

KeyError: 'Ra_12'

...
File "path-to/planpromodel.py", line 45362, in _buildChildren
  class_ = globals()[type_name_]
KeyError: 'Ra_12'

Thats because the schema never imports the sub-schema Signalbegriffe_Ril_301.xsd (for whatever reason). Add the import by adding:

<xs:import namespace="http://www.plan-pro.org/modell/Signalbegriffe_Ril_301/1.9.0"
          schemaLocation="Signalbegriffe_Ril_301.xsd"/>

to the other imports in the PlanPro.xsd and add the namespace to overall schema definition (top of PlanPro.xsd file):

xmlns:nsSignalbegriffe_Ril_301="http://www.plan-pro.org/modell/Signalbegriffe_Ril_301/1.9.0"

Multi-line descriptions

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "path-to/planpromodel.py", line 172595
    if self.Beschreibung != "Langsamfahrt, Fahrt erwarten; links ein grünes und senkrecht darunter ein gelbes Licht;

This happens because long strings in the Signalbegriffe_Ril_301.xsd file. Just go to that line of code in the planpromodel.py and remove the extra line breaks, which interrupts the strings.

Otherwise add .replace("\n", "\\n") to s2 in line 5146, to s1 in line 8331 and to default in line 3058.

Quotes in strings

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "path-to/planpromodel.py", line 178494
    if self.Anmerkungen != "Optionales Zusatzschild mit Werten "2", "3", "4", "5", "6", "7", "8", "9"" and 'Anmerkungen' not in already_processed:

Just escape the quotes in the lines. Template to copy: \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\". Since this is annoying for the huge number of places, you can also try to search&replace if self.%s != "%s" by if self.%s != \'%s\' in the generateDS.py.

PlanPro.GDSParseError: Requires boolean value

File "path-to/planpromodel.py", line 837, in raise_parse_error
  raise GDSParseError(msg)
PlanPro.GDSParseError: Requires boolean value (element Ersatzstecker_Gleisbezogen/line 2573)

The parser can not handle <Wert xsi:nil="true"/> in the .ppxml file. Change it in that file to <Wert>false</Wert> (or false) (only for the value of Ersatzstecker_Gleisbezogen - other places are fine).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages