diff --git a/src/modules/testmodule.py b/src/modules/testmodule.py new file mode 100755 index 000000000..008f47719 --- /dev/null +++ b/src/modules/testmodule.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# === This file is part of Calamares - === +# +# Copyright 2014, Teo Mrnjavac +# +# Calamares 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 3 of the License, or +# (at your option) any later version. +# +# Calamares 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 Calamares. If not, see . + +import os +import sys +import yaml +libcalamarespath = os.path.abspath( sys.argv[ 1 ] ) +sys.path.append( libcalamarespath ) +import libcalamares + +class Job: + def __init__( self, workingPath, doc ): + self.prettyName = "Testing job " + doc[ "name" ] + self.workingPath = workingPath + self.configuration = doc[ "configuration" ] + +# Usage: ./testmodule.py +def main( args ): + moduledirpath = os.path.abspath( sys.argv[ 2 ] ) + print( "Importing libcalamares from: " + libcalamares.__file__ ) + print( "Testing module in: " + moduledirpath ) + + confpath = os.path.join( moduledirpath, "module.conf" ) + + conffile = open( confpath, 'r' ) + doc = yaml.load( conffile ) + + if not doc[ "type" ] == "job" or not doc[ "interface" ] == "python": + print( "Only Python jobs can be tested." ) + return 1 + + libcalamares.__dict__[ "job" ] = Job( moduledirpath, doc ) + libcalamares.__dict__[ "global_storage" ] = libcalamares.GlobalStorage() + + scriptpath = os.path.abspath( moduledirpath ) + sys.path.append( scriptpath ) + import main + + print( "Output from module:" ) + print( main.calamares_main() ) + + return 0 + + +if __name__ == "__main__": + sys.exit( main( sys.argv ) ) \ No newline at end of file