Testing: expand the testmodule script.
Do a better job determining what the arguments could mean; this supports lazy devlopers who don't want to pass in full paths to all kinds of things. Simple invocation can now be: testmodule.py <modulename> - + to read <modulename>.conf from src/modules/<modulename>/
This commit is contained in:
parent
0d413ba750
commit
c8a6ebe404
@ -19,14 +19,25 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
Testing tool to run a single Python module; optionally a
|
Testing tool to run a single Python module; optionally a global configuration
|
||||||
global configuration and module configuration can be read
|
and module configuration can be read from YAML files.
|
||||||
from YAML files. Give a full path to the module-directory,
|
|
||||||
and also full paths to the configuration files. An empty
|
|
||||||
configuration file name, or "-" (a single dash) is used
|
|
||||||
to indicate that no file should be read -- useful to load
|
|
||||||
a module configuratioon file without a global configuration.
|
|
||||||
"""
|
"""
|
||||||
|
argumentepilog = """
|
||||||
|
moduledir may be a module name (e.g. "welcome") or a full path to the
|
||||||
|
module (e.g. "src/modules/welcome"). In the former case, an attempt
|
||||||
|
is made to find the module in several sensible places.
|
||||||
|
globalstorage_yaml may be given as a full path to a YAML file containing
|
||||||
|
the global configuration, or as "" or "-" which will leave the
|
||||||
|
global storage empty.
|
||||||
|
configuration_yaml may be given as a full path to a YAML file with the
|
||||||
|
module configuration, as "" or "-" to leave the configuration
|
||||||
|
empty, or as "+" to load the standard configuration from the
|
||||||
|
module-directory (e.g. welcome.conf if the welcome module is given).
|
||||||
|
|
||||||
|
The simplest invocation to test a module, with its default configuration, is
|
||||||
|
to call this program as follows (for, e.g., the welcome module):
|
||||||
|
|
||||||
|
testmodule.py welcome - +"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
@ -34,14 +45,15 @@ import sys
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
calamaresimporterror = ("Can not import libcalamares. Ensure the PYTHONPATH "
|
||||||
|
"environment variable includes the dir where libcalamares.so is "
|
||||||
|
"installed.")
|
||||||
try:
|
try:
|
||||||
import libcalamares
|
import libcalamares
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("Failed to import libcalamares. Make sure then PYTHONPATH "
|
print(calamaresimporterror)
|
||||||
"environment variable includes the dir where libcalamares.so is "
|
|
||||||
"installed.")
|
|
||||||
print()
|
print()
|
||||||
raise
|
libcalamares = None
|
||||||
|
|
||||||
|
|
||||||
class Job:
|
class Job:
|
||||||
@ -114,18 +126,37 @@ def test_module(moduledir, globalconfigfilename, moduleconfigfilename, lang):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def munge_filename(filename):
|
def munge_filename(filename, module=None):
|
||||||
"""
|
"""
|
||||||
Maps files "" (empty) and "-" (just a dash) to None,
|
Maps files "" (empty) and "-" (just a dash) to None,
|
||||||
to simplify processing elsewhere.
|
to simplify processing elsewhere.
|
||||||
"""
|
"""
|
||||||
if not filename or filename == "-":
|
if not filename or filename == "-":
|
||||||
return None
|
return None
|
||||||
|
if filename == "+" and module is not None:
|
||||||
|
d, name = os.path.split(module)
|
||||||
|
if d and not name:
|
||||||
|
# Ended in a /
|
||||||
|
d, name = os.path.split(module)
|
||||||
|
if name:
|
||||||
|
return os.path.join(module, name + ".conf")
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
def find_module(modulename):
|
||||||
|
if "/" in modulename:
|
||||||
|
return modulename
|
||||||
|
else:
|
||||||
|
for prefix in ("src/modules", "build/src/modules", "../src/modules"):
|
||||||
|
mp = os.path.join( prefix, modulename )
|
||||||
|
if os.path.exists( mp ):
|
||||||
|
return mp
|
||||||
|
# Not found? Bail out elsewhere
|
||||||
|
return modulename
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description=globals()["__doc__"])
|
parser = argparse.ArgumentParser(description=globals()["__doc__"], epilog=argumentepilog, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
parser.add_argument("moduledir",
|
parser.add_argument("moduledir",
|
||||||
help="Dir containing the Python module.")
|
help="Dir containing the Python module.")
|
||||||
parser.add_argument("globalstorage_yaml", nargs="?",
|
parser.add_argument("globalstorage_yaml", nargs="?",
|
||||||
@ -136,9 +167,15 @@ def main():
|
|||||||
help="Set translation language.")
|
help="Set translation language.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
return test_module(args.moduledir,
|
# If we get here, it wasn't a --help invocation, so complain
|
||||||
|
# if libcalamares wasn't found.
|
||||||
|
if not libcalamares:
|
||||||
|
parser.error(calamaresimporterror)
|
||||||
|
|
||||||
|
moduledir = find_module(args.moduledir)
|
||||||
|
return test_module(moduledir,
|
||||||
munge_filename(args.globalstorage_yaml),
|
munge_filename(args.globalstorage_yaml),
|
||||||
munge_filename(args.configuration_yaml),
|
munge_filename(args.configuration_yaml, moduledir),
|
||||||
args.lang)
|
args.lang)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user