mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-26 08:58:22 -04:00
Make testmodule.py more Pythonic
This commit is contained in:
parent
b3ba56a829
commit
e1877adf9c
1 changed files with 30 additions and 18 deletions
|
@ -16,12 +16,19 @@
|
||||||
# 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/>.
|
||||||
|
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
libcalamarespath = os.path.abspath( sys.argv[ 1 ] )
|
|
||||||
sys.path.append( libcalamarespath )
|
try:
|
||||||
import libcalamares
|
import libcalamares
|
||||||
|
except ImportError:
|
||||||
|
print( "Failed to import libcalamares. Make sure then PYTHONPATH environment variable includes the dir where libcalamares.so is installed." )
|
||||||
|
print()
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class Job:
|
class Job:
|
||||||
def __init__( self, workingPath, doc ):
|
def __init__( self, workingPath, doc ):
|
||||||
|
@ -32,31 +39,36 @@ class Job:
|
||||||
def setprogress( self, progress ):
|
def setprogress( self, progress ):
|
||||||
print ( "Job set progress to {}%.".format( progress * 100 ) )
|
print ( "Job set progress to {}%.".format( progress * 100 ) )
|
||||||
|
|
||||||
# Usage: ./testmodule.py <libcalamares.so dir> <python module dir> [global_storage yaml file]
|
|
||||||
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" )
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument( "moduledir",
|
||||||
|
help = "Dir containing the Python module" )
|
||||||
|
parser.add_argument( "globalstorage_yaml", nargs = "?",
|
||||||
|
help = "A yaml file to initialize GlobalStorage" )
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
conffile = open( confpath, 'r' )
|
print( "Testing module in: " + args.moduledir )
|
||||||
doc = yaml.load( conffile )
|
|
||||||
|
|
||||||
if not doc[ "type" ] == "job" or not doc[ "interface" ] == "python":
|
confpath = os.path.join( args.moduledir, "module.conf" )
|
||||||
|
with open( confpath ) as f:
|
||||||
|
doc = yaml.load( f )
|
||||||
|
|
||||||
|
if doc[ "type" ] != "job" or doc[ "interface" ] != "python":
|
||||||
print( "Only Python jobs can be tested." )
|
print( "Only Python jobs can be tested." )
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
libcalamares.__dict__[ "job" ] = Job( moduledirpath, doc )
|
libcalamares.job = Job( args.moduledir, doc )
|
||||||
libcalamares.__dict__[ "global_storage" ] = libcalamares.GlobalStorage()
|
libcalamares.global_storage = libcalamares.GlobalStorage()
|
||||||
|
|
||||||
# if a file for simulating global_storage contents is provided, load it
|
# if a file for simulating global_storage contents is provided, load it
|
||||||
if len( sys.argv ) > 3:
|
if args.globalstorage_yaml:
|
||||||
doc = yaml.load( open( os.path.abspath( sys.argv[ 3 ] ), 'r' ) )
|
with open( args.globalstorage_yaml ) as f:
|
||||||
|
doc = yaml.load( f )
|
||||||
for key, value in doc.items():
|
for key, value in doc.items():
|
||||||
libcalamares.global_storage.insert( key, value )
|
libcalamares.global_storage.insert( key, value )
|
||||||
|
|
||||||
scriptpath = os.path.abspath( moduledirpath )
|
scriptpath = os.path.abspath( args.moduledir )
|
||||||
sys.path.append( scriptpath )
|
sys.path.append( scriptpath )
|
||||||
import main
|
import main
|
||||||
|
|
||||||
|
@ -67,4 +79,4 @@ def main( args ):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit( main( sys.argv ) )
|
sys.exit( main() )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue