1
0
Fork 0

Script to create default translation for weather

This commit is contained in:
Automatic Release Builder 2020-06-17 17:03:19 +01:00
parent eabc8534b0
commit 14b3950d44
2 changed files with 95 additions and 0 deletions

0
catalog/__init__.py Normal file
View file

View file

@ -0,0 +1,95 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2020 James Turner
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import argparse
import locale
import os
import sys
import lxml.etree as ET
from catalog import sgprops
PROGNAME = os.path.basename(sys.argv[0])
def processCommandLine():
params = argparse.Namespace()
parser = argparse.ArgumentParser(
usage="""\
%(prog)s [OPTION ...] FGDATA
Copy weather scenario descriptions to the default translation XML""",
description="""\
""",
formatter_class=argparse.RawDescriptionHelpFormatter,
# I want --help but not -h (it might be useful for something else)
add_help=False)
parser.add_argument("fgdata", metavar="FGDATA",
help="""\
location of FGData""")
parser.add_argument("--help", action="help",
help="display this message and exit")
return parser.parse_args(namespace=params)
# create an xml node with text content
def make_xml_leaf(name, text):
leaf = ET.Element(name)
if text != None:
if isinstance(text, (int)):
leaf.text = str(text)
else:
leaf.text = text
else:
leaf.text = ''
return leaf
def copyWeatherScenarios(fgdata):
environment_node = sgprops.readProps(fgdata + "/Environment/environment.xml")
scenarios = environment_node.getChild('weather-scenarios')
result = ET.Element("PropertyList")
for s in scenarios.getChildren("scenario"):
scenarioId = s.getValue("id", None)
name = s.getValue("name", None)
desc = s.getValue("description", None)
result.append(make_xml_leaf(scenarioId + "-name", name))
result.append(make_xml_leaf(scenarioId + "-desc", desc))
default_trans_file = fgdata + "/Translations/default/weather-scenarios.xml"
doc = ET.ElementTree(result)
doc.write(default_trans_file, encoding='utf-8', xml_declaration=True, pretty_print=True)
def main():
global params
locale.setlocale(locale.LC_ALL, '')
params = processCommandLine()
copyWeatherScenarios(params.fgdata)
sys.exit(0)
if __name__ == "__main__": main()