Exemplo n.º 1
0
 def __init__(self, name, description=None, inputdata=None, outputdata=None, indcalls=None,
              indmetrics=None, inddata=None, params=None, settings=None):
     if name is not None:
         self.name = name
     if description is not None:
         self.description = description
     if inputdata is not None:
         self.inputdata = inputdata
     if outputdata is not None:
         self.outputdata = outputdata
     if indcalls is not None:
         self.indcalls = indcalls
     if indmetrics is not None:
         self.indmetrics = indmetrics
     if inddata is not None:
         self.inddata = inddata
     if params is not None:
         self.params = params
     if settings is not None:
         self.settings = settings
     self._data = None
     self.res_outputdata = None
     self.res_outputpara = None
     self.res_inddata = None
     self.idx_localplot = 0
     self.config = os.path.join(pathfinder.adamodels_path(), self.__module__ + '.cfg')
     self.results = None
Exemplo n.º 2
0
 def load_models(self):
     """Searches the ADA Models folder and imports all valid models,
     returning a list of the models successfully imported as tuples:
     first element is the model name (e.g. AHat_v_A), second element is
     the class of the model."""
     return mainmodel.load_dynamic_modules(pathfinder.adamodels_path(),
                                           ADAModel)
Exemplo n.º 3
0
 def install_plugin(self):
     """Installs the ADA model in the default ADA models path.  Returns True if installation succeeded."""
     plugin_path = pathfinder.adamodels_path()
     if self.plugin is not None:
         plugin_zip = UnZipper(self.plugin_contents, self.zip_password)
         if self.verify_plugin():
             plugin_files = [
                 each_file for each_file in plugin_zip.list_contents()
                 if each_file not in self.readme_files
             ]
             for each_file in plugin_files:
                 plugin_zip.extract(each_file, plugin_path)
                 if not os.path.exists(os.path.join(plugin_path,
                                                    each_file)):
                     module_logger.warning("Plugin installation failed.")
                     return False
         else:
             module_logger.warning(
                 "Plugin installation failed - plugin does not conform to spec."
             )
             return False
     else:
         module_logger.warning(
             "Plugin installation failed - plugin is not set.")
         return False
     return True
Exemplo n.º 4
0
 def check_user_path(self):
     """Verify user data folders were created"""
     data_folders = [pathfinder.user_path(), pathfinder.data_path(),
                     pathfinder.thumbnails_path(), pathfinder.gates_path(),
                     pathfinder.plugins_path(), pathfinder.podmodels_path(),
                     pathfinder.adamodels_path(), pathfinder.colormaps_path(),
                     pathfinder.batchoutput_path()]
     self.model.check_user_path()
     for folder in data_folders:
         self.assertTrue(os.path.exists(folder))
 def test_install_plugin(self):
     """Verify install_plugin method correctly installs a plugin; also
     verifies handling of encrypted ZIPs"""
     sample_plugin_url = TestRemoteADAModelInstaller.plugin_url('good_adamodel.zip')
     installed_plugin_name = os.path.join(pathfinder.adamodels_path(), 'good_adamodel.py')
     installed_plugin_cfg = os.path.join(pathfinder.adamodels_path(), 'good_adamodel.cfg')
     installer = adamodel_installer.RemoteADAModelInstaller(sample_plugin_url)
     installer.fetch()
     self.assertTrue(installer.verify_plugin())
     install_success = installer.install_plugin()
     self.assertTrue(os.path.exists(installed_plugin_name))
     self.assertTrue(os.path.exists(installed_plugin_cfg))
     self.assertTrue(install_success)
     # Clean up - attempt to remove the sample plugin if it already exists
     for mdl_file in [installed_plugin_name, installed_plugin_cfg]:
         if os.path.exists(mdl_file):
             try:
                 os.remove(mdl_file)
             except WindowsError: # file in use
                 return
 def test_install_plugin(self):
     """Verify install_plugin method correctly installs a plugin; also
     verifies handling of encrypted ZIPs"""
     sample_plugin_url = TestRemoteADAModelInstaller.plugin_url(
         'good_adamodel.zip')
     installed_plugin_name = os.path.join(pathfinder.adamodels_path(),
                                          'good_adamodel.py')
     installed_plugin_cfg = os.path.join(pathfinder.adamodels_path(),
                                         'good_adamodel.cfg')
     installer = adamodel_installer.RemoteADAModelInstaller(
         sample_plugin_url)
     installer.fetch()
     self.assertTrue(installer.verify_plugin())
     install_success = installer.install_plugin()
     self.assertTrue(os.path.exists(installed_plugin_name))
     self.assertTrue(os.path.exists(installed_plugin_cfg))
     self.assertTrue(install_success)
     # Clean up - attempt to remove the sample plugin if it already exists
     for mdl_file in [installed_plugin_name, installed_plugin_cfg]:
         if os.path.exists(mdl_file):
             try:
                 os.remove(mdl_file)
             except WindowsError:  # file in use
                 return
Exemplo n.º 7
0
 def check_user_path(cls):
     """Verify that user data folders exist.  Creates
     any missing folders."""
     user_folder = pathfinder.user_path()
     data_folder = pathfinder.data_path()
     thumbnail_folder = pathfinder.thumbnails_path()
     plugins_folder = pathfinder.plugins_path()
     podmodels_folder = pathfinder.podmodels_path()
     adamodels_folder = pathfinder.adamodels_path()
     gates_folder = pathfinder.gates_path()
     colormaps_folder = pathfinder.colormaps_path()
     batch_folder = pathfinder.batchoutput_path()
     for fldr in (user_folder, data_folder, thumbnail_folder, plugins_folder, podmodels_folder, gates_folder,
         adamodels_folder, colormaps_folder, batch_folder):
         if not os.path.exists(fldr):
             os.makedirs(fldr)
Exemplo n.º 8
0
 def check_user_path(cls):
     """Verify that user data folders exist.  Creates
     any missing folders."""
     user_folder = pathfinder.user_path()
     data_folder = pathfinder.data_path()
     thumbnail_folder = pathfinder.thumbnails_path()
     plugins_folder = pathfinder.plugins_path()
     podmodels_folder = pathfinder.podmodels_path()
     adamodels_folder = pathfinder.adamodels_path()
     gates_folder = pathfinder.gates_path()
     colormaps_folder = pathfinder.colormaps_path()
     batch_folder = pathfinder.batchoutput_path()
     for fldr in (user_folder, data_folder, thumbnail_folder,
                  plugins_folder, podmodels_folder, gates_folder,
                  adamodels_folder, colormaps_folder, batch_folder):
         if not os.path.exists(fldr):
             os.makedirs(fldr)
 def install_plugin(self):
     """Installs the ADA model in the default ADA models path.  Returns True if installation succeeded."""
     plugin_path = pathfinder.adamodels_path()
     if self.plugin is not None:
         plugin_zip = UnZipper(self.plugin_contents, self.zip_password)
         if self.verify_plugin():
             plugin_files = [each_file for each_file in plugin_zip.list_contents() if
                             each_file not in self.readme_files]
             for each_file in plugin_files:
                 plugin_zip.extract(each_file, plugin_path)
                 if not os.path.exists(os.path.join(plugin_path, each_file)):
                     module_logger.warning("Plugin installation failed.")
                     return False
         else:
             module_logger.warning("Plugin installation failed - plugin does not conform to spec.")
             return False
     else:
         module_logger.warning("Plugin installation failed - plugin is not set.")
         return False
     return True
Exemplo n.º 10
0
def deleted_user_path():
    """Utility function to delete empty folders in the user data folders,
    used to verify that MainModel will recreate missing folders as required.
    Returns a list of folders successfully deleted or None if no folders
    were deleted."""
    data_folders = [pathfinder.user_path(), pathfinder.data_path(), pathfinder.thumbnails_path(),
                    pathfinder.plugins_path(), pathfinder.podmodels_path(), pathfinder.adamodels_path(),
                    pathfinder.colormaps_path()]
    deleted_folders = []
    for folder in data_folders:
        exists_and_empty = os.path.exists(folder) and os.listdir(folder) == []
        if exists_and_empty:
            try:
                os.rmdir(folder)
                deleted_folders.append(folder)
            except WindowsError: # folder in use (Explorer, cmd, etc.)
                pass
    if deleted_folders:
        return deleted_folders
    return None
Exemplo n.º 11
0
 def __init__(self,
              name,
              description=None,
              inputdata=None,
              outputdata=None,
              indcalls=None,
              indmetrics=None,
              inddata=None,
              params=None,
              settings=None):
     if name is not None:
         self.name = name
     if description is not None:
         self.description = description
     if inputdata is not None:
         self.inputdata = inputdata
     if outputdata is not None:
         self.outputdata = outputdata
     if indcalls is not None:
         self.indcalls = indcalls
     if indmetrics is not None:
         self.indmetrics = indmetrics
     if inddata is not None:
         self.inddata = inddata
     if params is not None:
         self.params = params
     if settings is not None:
         self.settings = settings
     self._data = None
     self.res_outputdata = None
     self.res_outputpara = None
     self.res_inddata = None
     self.idx_localplot = 0
     self.config = os.path.join(pathfinder.adamodels_path(),
                                self.__module__ + '.cfg')
     self.results = None
Exemplo n.º 12
0
 def load_models(self):
     """Searches the ADA Models folder and imports all valid models,
     returning a list of the models successfully imported as tuples:
     first element is the model name (e.g. AHat_v_A), second element is
     the class of the model."""
     return mainmodel.load_dynamic_modules(pathfinder.adamodels_path(), ADAModel)
Exemplo n.º 13
0
 def test_adamodels_path(self):
     """Verify returning correct path to ADA models"""
     ada_path = os.path.join(self.user_path, 'ada')
     self.assertEqual(ada_path, pathfinder.adamodels_path())
Exemplo n.º 14
0
 def test_adamodels_path(self):
     """Verify returning correct path to ADA models"""
     ada_path = os.path.join(self.user_path, 'ada')
     self.assertEqual(ada_path, pathfinder.adamodels_path())