def setUp(self):
     self.config_file = os.path.join(pathfinder.podmodels_path(), 'sample_podmodel.cfg')
     if not os.path.exists(self.config_file):
         shutil.copy(self.path_to_support_file('sample_podmodel.cfg'), self.config_file)
     self.pod_file = os.path.join(pathfinder.podmodels_path(), 'sample_podmodel.py')
     if not os.path.exists(self.pod_file):
         shutil.copy(self.path_to_support_file('sample_podmodel.py'), self.pod_file)
 def load_models(self):
     """Searches the POD 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."""
     models_folder = pathfinder.podmodels_path()
     if not models_folder in sys.path:
         sys.path.append(models_folder)
     for root, dir, files in os.walk(pathfinder.podmodels_path()):
         for model_file in files:
             model_name, model_extension = os.path.splitext(model_file)
             module_hdl = None
             if model_extension == os.extsep + "py":
                 try:
                     module_hdl, path_name, description = imp.find_module(model_name)
                     podmodel_module = imp.load_module(model_name, module_hdl, path_name,
                         description)
                     podmodel_classes = inspect.getmembers(podmodel_module, inspect.isclass)
                     for podmodel_class in podmodel_classes:
                         if issubclass(podmodel_class[1], PODModel):
                             if podmodel_class[1].__module__ == model_name:
                                 self.pod_models.append(podmodel_class)
                 finally:
                     if module_hdl is not None:
                         module_hdl.close()
     return self.pod_models
 def load_models(self):
     """Searches the POD 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."""
     models_folder = pathfinder.podmodels_path()
     if not models_folder in sys.path:
         sys.path.append(models_folder)
     for root, dir, files in os.walk(pathfinder.podmodels_path()):
         for model_file in files:
             model_name, model_extension = os.path.splitext(model_file)
             module_hdl = None
             if model_extension == os.extsep + "py":
                 try:
                     module_hdl, path_name, description = imp.find_module(
                         model_name)
                     podmodel_module = imp.load_module(
                         model_name, module_hdl, path_name, description)
                     podmodel_classes = inspect.getmembers(
                         podmodel_module, inspect.isclass)
                     for podmodel_class in podmodel_classes:
                         if issubclass(podmodel_class[1], PODModel):
                             if podmodel_class[1].__module__ == model_name:
                                 self.pod_models.append(podmodel_class)
                 finally:
                     if module_hdl is not None:
                         module_hdl.close()
     return self.pod_models
 def setUp(self):
     self.config_file = os.path.join(pathfinder.podmodels_path(),
                                     'sample_podmodel.cfg')
     if not os.path.exists(self.config_file):
         shutil.copy(self.path_to_support_file('sample_podmodel.cfg'),
                     self.config_file)
     self.pod_file = os.path.join(pathfinder.podmodels_path(),
                                  'sample_podmodel.py')
     if not os.path.exists(self.pod_file):
         shutil.copy(self.path_to_support_file('sample_podmodel.py'),
                     self.pod_file)
 def install_plugin(self):
     """Installs the plugin in the default plugin path.
     Returns True if installation succeeded."""
     plugin_path = pathfinder.podmodels_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
Beispiel #6
0
 def load_models(self):
     """Searches the POD 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.podmodels_path(),
                                           PODModel)
Beispiel #7
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.colormaps_path(), pathfinder.batchoutput_path()]
     self.model.check_user_path()
     for folder in data_folders:
         self.assertTrue(os.path.exists(folder))
 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 = TestPODModelInstaller.local_plugin('good_podmodel.zip')
     installed_plugin_name = os.path.join(pathfinder.podmodels_path(), 'good_podmodel.py')
     installer = podmodel_installer.PODModelInstaller(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(install_success)
     # Clean up - attempt to remove the sample POD Model if it already exists
     podmodel_files = zipper.UnZipper(sample_plugin_url).list_contents()
     for each_file in podmodel_files:
         full_path = os.path.join(pathfinder.podmodels_path(), each_file)
         if os.path.exists(full_path):
             try:
                 os.remove(full_path)
             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 = TestRemotePODModelInstaller.plugin_url('good_podmodel.zip')
     installed_plugin_name = os.path.join(pathfinder.podmodels_path(), 'good_podmodel.py')
     installed_plugin_cfg = os.path.join(pathfinder.podmodels_path(), 'good_podmodel.cfg')
     installer = podmodel_installer.RemotePODModelInstaller(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 __init__(self, name, description=None, inputdata=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 params is not None:
         self.params = params
     if settings is not None:
         self.settings = settings
     self._data = None
     self.config = os.path.join(pathfinder.podmodels_path(), self.__module__ + '.cfg')
     self.results = None
Beispiel #12
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()
     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,
                  colormaps_folder, batch_folder):
         if not os.path.exists(fldr):
             os.makedirs(fldr)
Beispiel #13
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 test_install_plugin(self):
     """Verify install_plugin method correctly installs a plugin; also
     verifies handling of encrypted ZIPs"""
     sample_plugin_url = TestRemotePODModelInstaller.plugin_url('good_podmodel.zip')
     installed_plugin_name = os.path.join(pathfinder.podmodels_path(), 'good_podmodel.py')
     installer = podmodel_installer.RemotePODModelInstaller(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(install_success)
     # Clean up - attempt to remove the sample plugin if it already exists
     if os.path.exists(installed_plugin_name):
         try:
             os.remove(installed_plugin_name)
         except WindowsError: # file in use
             return
 def __init__(self,
              name,
              description=None,
              inputdata=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 params is not None:
         self.params = params
     if settings is not None:
         self.settings = settings
     self._data = None
     self.config = os.path.join(pathfinder.podmodels_path(),
                                self.__module__ + '.cfg')
     self.results = None
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
 def install_plugin(self):
     """Installs the plugin in the default plugin path.
     Returns True if installation succeeded."""
     plugin_path = pathfinder.podmodels_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
Beispiel #18
0
 def on_sheet_tool_click(self, evt):
     """Handles toolbar button clicks in the spreadsheet -
     currently supports Open File (id=20) and Save File (id=30)."""
     if evt.GetId() == 20: # Open File
         file_dlg = wx.FileDialog(self.view, message="Please select a CSV file",
                                  wildcard="CSV files (*.csv)|*.csv|Text Files (*.txt)|*"\
                                           ".txt|All Files (*.*)|*.*"
                                  ,
                                  style=wx.FD_OPEN)
         if file_dlg.ShowModal() == wx.ID_OK:
             try:
                 grid = self.get_active_grid()
                 data = self.get_data(file_dlg.GetPath(), "csv")
                 if data is not None:
                     self.populate_spreadsheet(grid, data)
                 else:
                     raise IOError("File not recognized as CSV.")
             except Exception as err:
                 if str(err) is None:
                     msg = "An unknown error occurred attempting to read the file."
                 else:
                     msg = "An error occurred attempting to read the file:\n\n{0}".format(
                         str(err))
                 module_logger.error("Unable to read file: {0}".format(err))
                 err_dlg = wx.MessageDialog(self.view, caption="Failed To Read File",
                                            message=msg, style=wx.OK | wx.ICON_ERROR)
                 err_dlg.ShowModal()
                 err_dlg.Destroy()
     elif evt.GetId() == 30: # Save File
         save_file_dlg = wx.FileDialog(self.view, message="Please specify an output filename",
                                       defaultDir=pathfinder.podmodels_path(),
                                       wildcard="CSV files (*.csv)|*.csv|Text Files (*.txt)|*"\
                                                ".txt|All Files (*.*)|*.*"
                                       ,
                                       style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
         if save_file_dlg.ShowModal() == wx.ID_OK:
             grid = self.get_active_grid()
             grid.WriteCSV(save_file_dlg.GetPath())
         save_file_dlg.Destroy()
Beispiel #19
0
 def load_models(self):
     """Searches the POD 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.podmodels_path(), PODModel)
 def test_podmodels_path(self):
     """Verify correct path to POD Toolkit models"""
     model_path = os.path.join(self.user_path, "podmodels")
     self.assertEqual(model_path, pathfinder.podmodels_path())
Beispiel #21
0
 def test_podmodels_path(self):
     """Verify correct path to POD Toolkit models"""
     model_path = os.path.join(self.user_path, "podmodels")
     self.assertEqual(model_path, pathfinder.podmodels_path())