def verify_plugin(self):
     """Verify plugin conforms to basic plugin structure.  Returns
     True if the plugin appears ok, False otherwise."""
     plugin_ok = True
     if self.plugin is not None:
         plugin_zip = UnZipper(self.plugin_contents, self.zip_password)
         if not plugin_zip.is_ok():
             module_logger.warning("Plugin archive corrupted - failed CRC check.")
             return False
         plugin_files = [each_file for each_file in plugin_zip.list_contents()]
         readme_found = False
         for valid_readme in self.readme_files:
             if valid_readme in plugin_files:
                 readme_found = True
                 break
         if not readme_found:
             module_logger.warning("Plugin does not conform to spec - no README found.")
             return False
         zip_name = os.path.basename(self.plugin_url)
         zip_name_base, ext = os.path.splitext(zip_name)
         plugin_main = ''.join([zip_name_base, '.py'])
         if plugin_main not in plugin_files:
             module_logger.warning("Plugin does not conform to spec - no main Python file found.")
             return False
         plugin_fldr = zip_name_base
         support_files = [el for el in plugin_files if
                          el not in self.readme_files and el != plugin_main]
         for each_file in support_files:
             install_fldr = os.path.dirname(each_file)
             if os.path.commonprefix([plugin_fldr, install_fldr]) != plugin_fldr:
                 module_logger.warning("Plugin does not conform to spec - incorrect folder structure.")
                 return False
     return plugin_ok
 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
 def plugin_files(self):
     """Returns a list of the files in the plugin archive"""
     files = []
     plugin_reader = UnZipper(self.plugin_contents, self.zip_password)
     if plugin_reader.is_ok():
         files = plugin_reader.list_contents()
     else:
         module_logger.warning("Plugin archive corrupted - failed CRC check.")
     return files
 def retrieve_readme(self):
     """Returns the contents of the plugin archive's root-level
     README, or None if not found."""
     readme_content = None
     if self.plugin is not None:
         readme_extractor = UnZipper(self.plugin_contents, self.zip_password)
         if readme_extractor.is_ok():
             plugin_files = readme_extractor.list_contents()
             for readme_file in self.readme_files:
                 if readme_file in plugin_files:
                     readme_content = readme_extractor.read(readme_file)
         else:
             module_logger.warning("Plugin archive corrupted - failed CRC check.")
     return readme_content
 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