pymtt
 All Classes Namespaces Files Functions Variables Groups
AlreadyInstalled.py
Go to the documentation of this file.
1 # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: f; python-indent: 4 -*-
2 #
3 # Copyright (c) 2015-2018 Intel, Inc. All rights reserved.
4 # $COPYRIGHT$
5 #
6 # Additional copyrights may follow
7 #
8 # $HEADER$
9 #
10 
11 
12 from __future__ import print_function
13 from FetchMTTTool import *
14 from distutils.spawn import find_executable
15 
16 ## @addtogroup Tools
17 # @{
18 # @addtogroup Fetch
19 # @section AlreadyInstalled
20 # No-op plugin for using existing middleware installation
21 # @param exec Executable that should be in path
22 # @param module Modules (or lmod modules) to be loaded for accessing this package
23 # @}
25 
26  def __init__(self):
27  # initialise parent class
28  FetchMTTTool.__init__(self)
29  self.options = {}
30  self.options['exec'] = (None, "Executable that should be in path")
31  self.options['module'] = (None, "Modules (or lmod modules) to be loaded for accessing this package")
32  return
33 
34  def activate(self):
35  # get the automatic procedure from IPlugin
36  IPlugin.activate(self)
37  return
38 
39 
40  def deactivate(self):
41  IPlugin.deactivate(self)
42  return
43 
44  def print_name(self):
45  return "AlreadyInstalled"
46 
47  def print_options(self, testDef, prefix):
48  lines = testDef.printOptions(self.options)
49  for line in lines:
50  print(prefix + line)
51  return
52 
53  def execute(self, log, keyvals, testDef):
54  # if we were given an executable to check for,
55  # see if we can find it
56  usedModule = False
57  try:
58  if keyvals['exec'] is not None:
59  # if we were given a module to load, then
60  # do so prior to checking for the executable
61  try:
62  if keyvals['module'] is not None:
63  status,stdout,stderr = testDef.modcmd.loadModules(keyvals['modules'], testDef)
64  if 0 != status:
65  log['status'] = status
66  log['stderr'] = stderr
67  return
68  usedModule = True
69  except KeyError:
70  pass
71  # now look for the executable in our path
72  if not find_executable(keyvals['exec']):
73  log['status'] = 1
74  log['stderr'] = "Executable {0} not found".format(keyvals['exec'])
75  else:
76  log['status'] = 0
77  if usedModule:
78  # unload the modules before returning
79  status,stdout,stderr = testDef.modcmd.unloadModules(keyvals['modules'], testDef)
80  if 0 != status:
81  log['status'] = status
82  log['stderr'] = stderr
83  return
84  usedModule = False
85  return
86  except KeyError:
87  pass
88  if usedModule:
89  # unload the modules before returning
90  status,stdout,stderr = testDef.modcmd.unloadModules(keyvals['modules'], testDef)
91  if 0 != status:
92  log['status'] = status
93  log['stderr'] = stderr
94  return
95  log['status'] = 0
96  return