From 1c2d17d869feb0dd6cf20ca21f6d5ae928a05c47 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Fri, 19 Jun 2020 12:06:21 +0200 Subject: [PATCH] Reorganize catalog modules - Move the support modules inside python3-flightgear/flightgear/ and remove their shebang, if any. - Accordingly adapt the import statements. - Change shebangs from e.g. '#! /usr/bin/python' to '#! /usr/bin/env python3'. - Small changes to make Python 3 happy with all scripts. catalog/check_aircraft.py should be run under Python 3 from now on. --- catalog/README.md | 3 ++ catalog/__init__.py | 0 catalog/check_aircraft.py | 35 ++++++++++--------- catalog/test_catalog.py | 9 ++--- catalog/test_sgprops.py | 10 +++--- catalog/update-catalog.py | 12 ++++--- .../meta/aircraft_catalogs}/catalog.py | 7 ++-- .../meta/aircraft_catalogs}/catalogTags.py | 5 ++- .../flightgear/meta}/sgprops.py | 0 9 files changed, 48 insertions(+), 33 deletions(-) delete mode 100644 catalog/__init__.py rename {catalog => python3-flightgear/flightgear/meta/aircraft_catalogs}/catalog.py (99%) rename {catalog => python3-flightgear/flightgear/meta/aircraft_catalogs}/catalogTags.py (95%) rename {catalog => python3-flightgear/flightgear/meta}/sgprops.py (100%) diff --git a/catalog/README.md b/catalog/README.md index 919a1f2..bad7203 100644 --- a/catalog/README.md +++ b/catalog/README.md @@ -22,6 +22,9 @@ The script can be run directly from this directory, or the script and its modules can be copied together and run from any location. The steps to use these are: +* Have something like `export PYTHONPATH="/path/to/fgmeta/python3-flightgear"` + in your shell setup or use a .pth file (see `python3-flightgear/README.md` + for more details). * Create an output directory where the catalog and zip files will be located. * Copy the configuration files `catalog.config.xml`, `template.xml`, and `zip-excludes.lst` from one of the `*catalog*` example directories into the diff --git a/catalog/__init__.py b/catalog/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/catalog/check_aircraft.py b/catalog/check_aircraft.py index 9d9b8ff..36926bb 100755 --- a/catalog/check_aircraft.py +++ b/catalog/check_aircraft.py @@ -1,8 +1,10 @@ -#!/usr/bin/python +#! /usr/bin/env python3 import argparse import os -import sgprops + +from flightgear.meta import sgprops + def check_meta_data(aircraft_dir, set_file, includes): base_file = os.path.basename(set_file) @@ -13,44 +15,46 @@ def check_meta_data(aircraft_dir, set_file, includes): root_node = sgprops.readProps(set_path, includePaths = includes) if not root_node.hasChild("sim"): - print "-set.xml has no node:", set_path + print("-set.xml has no node:", set_path) return sim_node = root_node.getChild("sim") if not sim_node.hasChild('description'): - print "-set.xml missing :", set_path + print("-set.xml missing :", set_path) if not sim_node.hasChild('long-description'): - print "-set.xml missing :", set_path + print("-set.xml missing :", set_path) if not sim_node.hasChild('authors'): - print "-set.xml is missing structured data:", set_path + print("-set.xml is missing structured data:", set_path) if not sim_node.hasChild('tags'): - print "-set.xml does not define any tags", set_path + print("-set.xml does not define any tags", set_path) # check for non-standard tags if not sim_node.hasChild('thumbnail'): - print "-set.xml does not define a thumbnail", set_path + print("-set.xml does not define a thumbnail", set_path) # check thumbnail size and format if not sim_node.hasChild('rating'): - print "-set.xml does not define any ratings", set_path + print("-set.xml does not define any ratings", set_path) if not sim_node.hasChild('minimum-fg-version'): - print "-set.xml does not define a minimum FG version", set_path + print("-set.xml does not define a minimum FG version", set_path) -# check all the -set.xml files in an aircraft directory. + +# check all the -set.xml files in an aircraft directory. def check_aircraft_dir(d, includes): if not os.path.isdir(d): return files = os.listdir(d) - for file in sorted(files, key=lambda s: s.lower()): - if file.endswith('-set.xml'): - check_meta_data(d, file, includes) + for f in sorted(files, key=lambda s: s.lower()): + if f.endswith('-set.xml'): + check_meta_data(d, f, includes) + parser = argparse.ArgumentParser() parser.add_argument("--include", help="Include directory to validate -set.xml parsing", @@ -60,7 +64,7 @@ args = parser.parse_args() for d in args.dir: if not os.path.isdir(d): - print "Skipping missing directory:", d + print("Skipping missing directory:", d) names = os.listdir(d) for name in sorted(names, key=lambda s: s.lower()): @@ -70,4 +74,3 @@ for d in args.dir: acftDir = os.path.join(d, name) check_aircraft_dir(acftDir, args.include) - \ No newline at end of file diff --git a/catalog/test_catalog.py b/catalog/test_catalog.py index db84f94..d66e1cb 100755 --- a/catalog/test_catalog.py +++ b/catalog/test_catalog.py @@ -1,15 +1,16 @@ -#!/usr/bin/python +#! /usr/bin/env python3 import unittest -import sgprops import os from os.path import join -import catalog import lxml.etree as ET from shutil import rmtree from tempfile import mkdtemp import zipfile +from flightgear.meta import sgprops +from flightgear.meta.aircraft_catalogs import catalog + catalog.quiet = True @@ -247,7 +248,7 @@ class ZipTests(unittest.TestCase): """General checks for the zip file.""" # Check for file existence. - self.assert_(os.access(file_name, os.F_OK)) + self.assertTrue(os.access(file_name, os.F_OK)) # Check the contents. file = zipfile.ZipFile(file_name) diff --git a/catalog/test_sgprops.py b/catalog/test_sgprops.py index f731717..56b0acb 100755 --- a/catalog/test_sgprops.py +++ b/catalog/test_sgprops.py @@ -1,7 +1,9 @@ +#! /usr/bin/env python3 + import unittest -import types -import sgprops +from flightgear.meta import sgprops + class SGProps(unittest.TestCase): @@ -9,14 +11,14 @@ class SGProps(unittest.TestCase): parsed = sgprops.readProps("testData/props1.xml") self.assertEqual(parsed.getValue("value"), 42) - self.assertEqual(type(parsed.getValue("value")), types.IntType) + self.assertEqual(type(parsed.getValue("value")), int) valNode = parsed.getChild("value") self.assertEqual(valNode.parent, parsed) self.assertEqual(valNode.name, "value") self.assertEqual(valNode.value, 42) - self.assertEqual(type(valNode.value), types.IntType) + self.assertEqual(type(valNode.value), int) with self.assertRaises(IndexError): missingNode = parsed.getChild("missing") diff --git a/catalog/update-catalog.py b/catalog/update-catalog.py index bb3ceb4..1ff877e 100755 --- a/catalog/update-catalog.py +++ b/catalog/update-catalog.py @@ -8,12 +8,14 @@ import os import re import shutil import subprocess -import time -import sgprops import sys -import catalogTags -import catalog -from catalog import make_aircraft_node, make_aircraft_zip, parse_config_file, parse_template_file +import time + +from flightgear.meta import sgprops +from flightgear.meta.aircraft_catalogs import catalogTags +from flightgear.meta.aircraft_catalogs import catalog +from flightgear.meta.aircraft_catalogs.catalog import make_aircraft_node, \ + make_aircraft_zip, parse_config_file, parse_template_file CATALOG_VERSION = 4 diff --git a/catalog/catalog.py b/python3-flightgear/flightgear/meta/aircraft_catalogs/catalog.py similarity index 99% rename from catalog/catalog.py rename to python3-flightgear/flightgear/meta/aircraft_catalogs/catalog.py index 283eb7e..36e0dea 100644 --- a/catalog/catalog.py +++ b/python3-flightgear/flightgear/meta/aircraft_catalogs/catalog.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +# -*- coding: utf-8 -*- import argparse import datetime @@ -8,11 +8,12 @@ import os from os.path import exists, join, relpath from os import F_OK, access, walk import re -import sgprops import sys -import catalogTags import zipfile +from flightgear.meta import sgprops +from . import catalogTags + CATALOG_VERSION = 4 quiet = False verbose = False diff --git a/catalog/catalogTags.py b/python3-flightgear/flightgear/meta/aircraft_catalogs/catalogTags.py similarity index 95% rename from catalog/catalogTags.py rename to python3-flightgear/flightgear/meta/aircraft_catalogs/catalogTags.py index c3e01db..39e3ba7 100644 --- a/catalog/catalogTags.py +++ b/python3-flightgear/flightgear/meta/aircraft_catalogs/catalogTags.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + aircraftTypeTags = [ "aerobatic", "airship", @@ -176,7 +178,8 @@ simFeatureTags = [ "wildfire" ] -tags = aircraftTypeTags + manufacturerTags + eraTags + simFeatureTags + propulsionTags + featureTags +tags = (aircraftTypeTags + manufacturerTags + eraTags + simFeatureTags + + propulsionTags + featureTags) def isValidTag(maybeTag): return maybeTag in tags diff --git a/catalog/sgprops.py b/python3-flightgear/flightgear/meta/sgprops.py similarity index 100% rename from catalog/sgprops.py rename to python3-flightgear/flightgear/meta/sgprops.py