def uninstall_extension(self, extension_name): """Uninstall the extension with name extension_name""" self.logger.log("Request to remove extension with name %s" % extension_name, level=2) # Find the subdirectory containing this extension's installer extension_installer_dir = os.path.join(self.root_dict['EXT_ROOT'], extension_name) # Retrieve it _, installer = weecfg.get_extension_installer(extension_installer_dir) # Remove any files that were added: self.uninstall_files(installer) save_config = False # Remove any services we added for service_group in all_service_groups: if service_group in installer: new_list = filter(lambda x : x not in installer[service_group], self.config_dict['Engine']['Services'][service_group]) if not self.dry_run: self.config_dict['Engine']['Services'][service_group] = new_list save_config = True # Remove any sections we added if 'config' in installer and not self.dry_run: weecfg.remove_and_prune(self.config_dict, installer['config']) save_config = True if not self.dry_run: # Finally, remove the extension's installer subdirectory: shutil.rmtree(extension_installer_dir) if save_config: weecfg.save_with_backup(self.config_dict, self.config_path)
def uninstall_extension(self, extension_name): """Uninstall the extension with name extension_name""" self.logger.log("Request to remove extension '%s'" % extension_name) # Find the subdirectory containing this extension's installer extension_installer_dir = os.path.join(self.root_dict['EXT_ROOT'], extension_name) try: # Retrieve it _, installer = weecfg.get_extension_installer( extension_installer_dir) except weecfg.ExtensionError: sys.exit("Unable to find extension %s" % extension_name) # Remove any files that were added: self.uninstall_files(installer) save_config = False # Remove any services we added for service_group in all_service_groups: if service_group in installer: new_list = filter( lambda x: x not in installer[service_group], self.config_dict['Engine']['Services'][service_group]) if not self.dry_run: self.config_dict['Engine']['Services'][ service_group] = new_list save_config = True # Remove any sections we added if 'config' in installer and not self.dry_run: weecfg.remove_and_prune(self.config_dict, installer['config']) save_config = True if not self.dry_run: # Finally, remove the extension's installer subdirectory: shutil.rmtree(extension_installer_dir) if save_config: weecfg.save_with_backup(self.config_dict, self.config_path) self.logger.log("Finished removing extension '%s'" % extension_name)
def uninstall_extension(self, extension_name): """Uninstall the extension with name extension_name""" self.logger.log("Request to remove extension '%s'" % extension_name) # Find the subdirectory containing this extension's installer extension_installer_dir = os.path.join(self.root_dict["EXT_ROOT"], extension_name) try: # Retrieve it _, installer = weecfg.get_extension_installer(extension_installer_dir) except weecfg.ExtensionError: sys.exit("Unable to find extension %s" % extension_name) # Remove any files that were added: self.uninstall_files(installer) save_config = False # Remove any services we added for service_group in all_service_groups: if service_group in installer: new_list = filter( lambda x: x not in installer[service_group], self.config_dict["Engine"]["Services"][service_group] ) if not self.dry_run: self.config_dict["Engine"]["Services"][service_group] = new_list save_config = True # Remove any sections we added if "config" in installer and not self.dry_run: weecfg.remove_and_prune(self.config_dict, installer["config"]) save_config = True if not self.dry_run: # Finally, remove the extension's installer subdirectory: shutil.rmtree(extension_installer_dir) if save_config: weecfg.save_with_backup(self.config_dict, self.config_path) self.logger.log("Finished removing extension '%s'" % extension_name)
def install_from_dir(self, extension_dir): """Install the extension whose components are in extension_dir""" self.logger.log("Request to install extension found in directory %s" % extension_dir, level=2) # The "installer" is actually a dictionary containing what is to be # installed and where. The "installer_path" is the path to the file # containing that dictionary. installer_path, installer = weecfg.get_extension_installer( extension_dir) extension_name = installer.get('name', 'Unknown') self.logger.log("Found extension with name '%s'" % extension_name, level=2) # Go through all the files used by the extension. A "source tuple" is # something like (bin, [user/myext.py, user/otherext.py]). The first # element is the directory the files go in, the second element is a # list of files to be put in that directory self.logger.log("Copying new files", level=2) N = 0 for source_tuple in installer['files']: # For each set of sources, see if it's a type we know about for directory in ExtensionEngine.target_dirs: # This will be something like 'bin', or 'skins': source_type = os.path.commonprefix( (source_tuple[0], directory)) # If there is a match, source_type will be something other # than an empty string: if source_type: # This will be something like 'BIN_ROOT' or 'SKIN_ROOT': root_type = ExtensionEngine.target_dirs[source_type] # Now go through all the files of the source tuple for install_file in source_tuple[1]: source_path = os.path.join(extension_dir, install_file) dst_file = ExtensionEngine._strip_leading_dir( install_file) destination_path = os.path.abspath( os.path.join(self.root_dict[root_type], dst_file)) self.logger.log("Copying from '%s' to '%s'" % (source_path, destination_path), level=3) if not self.dry_run: try: os.makedirs(os.path.dirname(destination_path)) except OSError: pass shutil.copy(source_path, destination_path) N += 1 break else: sys.exit("Unknown destination for file %s" % source_tuple) self.logger.log("Copied %d files" % N, level=2) save_config = False # Look for options that have to be injected into the configuration file if 'config' in installer: save_config |= self._inject_config(installer['config'], extension_name) # Go through all the possible service groups and see if the extension # includes any services that belong in any of them. self.logger.log("Adding services to service lists", level=2) for service_group in all_service_groups: if service_group in installer: extension_svcs = weeutil.weeutil.option_as_list( installer[service_group]) # Be sure that the leaf node is actually a list svc_list = weeutil.weeutil.option_as_list( self.config_dict['Engine']['Services'][service_group]) for svc in extension_svcs: # See if this service is already in the service group if svc not in svc_list: if not self.dry_run: # Add the new service into the appropriate # service group svc_list.append(svc) self.config_dict['Engine']['Services'][ service_group] = svc_list save_config = True self.logger.log("Added new service %s to %s" % (svc, service_group), level=3) # Save the extension's install.py file in the extension's installer # directory for later use enumerating and uninstalling extension_installer_dir = os.path.join(self.root_dict['EXT_ROOT'], extension_name) self.logger.log("Saving installer file to %s" % extension_installer_dir) if not self.dry_run: try: os.makedirs(os.path.join(extension_installer_dir)) except OSError: pass shutil.copy2(installer_path, extension_installer_dir) if save_config: backup_path = weecfg.save_with_backup(self.config_dict, self.config_path) self.logger.log( "Saved configuration dictionary. Backup copy at %s" % backup_path)
def install_from_dir(self, extension_dir): """Install the extension whose components are in extension_dir""" self.logger.log("Request to install extension found in directory %s" % extension_dir, level=2) # The "installer" is actually a dictionary containing what is to be # installed and where. The "installer_path" is the path to the file # containing that dictionary. installer_path, installer = weecfg.get_extension_installer(extension_dir) extension_name = installer.get('name', 'Unknown') self.logger.log("Found extension with name '%s'" % extension_name, level=2) # Go through all the files used by the extension. A "source tuple" is # something like (bin, [user/myext.py, user/otherext.py]). The first # element is the directory the files go in, the second element is a # list of files to be put in that directory self.logger.log("Copying new files", level=2) N = 0 for source_tuple in installer['files']: # For each set of sources, see if it's a type we know about for directory in ExtensionEngine.target_dirs: # This will be something like 'bin', or 'skins': source_type = os.path.commonprefix((source_tuple[0], directory)) # If there is a match, source_type will be something other # than an empty string: if source_type: # This will be something like 'BIN_ROOT' or 'SKIN_ROOT': root_type = ExtensionEngine.target_dirs[source_type] # Now go through all the files of the source tuple for install_file in source_tuple[1]: source_path = os.path.join(extension_dir, install_file) dst_file = ExtensionEngine._strip_leading_dir(install_file) destination_path = os.path.abspath(os.path.join(self.root_dict[root_type], dst_file)) self.logger.log("Copying from '%s' to '%s'" % (source_path, destination_path), level=3) if not self.dry_run: try: os.makedirs(os.path.dirname(destination_path)) except OSError: pass shutil.copy(source_path, destination_path) N += 1 break else: sys.exit("Unknown destination for file %s" % source_tuple) self.logger.log("Copied %d files" % N, level=2) save_config = False new_top_level = [] # Look for options that have to be injected into the configuration file if 'config' in installer: self.logger.log("Adding sections to configuration file", level=2) # make a copy so we can modify the sections to fit the existing # configuration cfg = dict(installer['config']) # prepend any html paths with HTML_ROOT from existing configuration weecfg.prepend_path(cfg, 'HTML_ROOT', self.config_dict['StdReport']['HTML_ROOT']) # massage the database dictionaries for this extension # FIXME: use parameterized root if possible try: sqlitecfg = self.config_dict['Databases'].get('archive_sqlite', None) mysqlcfg = self.config_dict['Databases'].get('archive_mysql', None) for i in cfg['Databases']: db = cfg['Databases'][i] if db['driver'] == 'weedb.sqlite' and sqlitecfg: db['database_name'] = os.path.join(os.path.dirname(sqlitecfg['database_name']), db['database_name']) db['root'] = sqlitecfg['root'] elif db['driver'] == 'weedb.mysql' and mysqlcfg: db['host'] = mysqlcfg['host'] db['user'] = mysqlcfg['user'] db['password'] = mysqlcfg['password'] except: pass # Remember any new top-level sections so we can inject a major # comment block for top_level in cfg: if top_level not in self.config_dict: new_top_level.append(top_level) self.logger.log("Adding section %s" % top_level, level=3) if not self.dry_run: # Inject any new config data into the configuration file weecfg.conditional_merge(self.config_dict, cfg) # Include the major comment block for any new top level sections for new_section in new_top_level: self.config_dict.comments[new_section] = \ weecfg.major_comment_block + \ ["# Options for extension '%s'" % extension_name] save_config = True self.logger.log("Merged extension settings into configuration file", level=3) # Go through all the possible service groups and see if the extension # includes any services that belong in any of them. self.logger.log("Adding services to service lists", level=2) for service_group in all_service_groups: if service_group in installer: extension_svcs = weeutil.weeutil.option_as_list(installer[service_group]) # Be sure that the leaf node is actually a list svc_list = weeutil.weeutil.option_as_list(self.config_dict['Engine']['Services'][service_group]) for svc in extension_svcs: # See if this service is already in the service group if svc not in svc_list: if not self.dry_run: # Add the new service into the appropriate # service group svc_list.append(svc) self.config_dict['Engine']['Services'][service_group] = svc_list save_config = True self.logger.log("Added new service %s to %s" % (svc, service_group), level=3) # Save the extension's install.py file in the extension's installer # directory for later use enumerating and uninstalling extension_installer_dir = os.path.join(self.root_dict['EXT_ROOT'], extension_name) self.logger.log("Saving installer file to %s" % extension_installer_dir) if not self.dry_run: try: os.makedirs(os.path.join(extension_installer_dir)) except OSError: pass shutil.copy2(installer_path, extension_installer_dir) if save_config: backup_path = weecfg.save_with_backup(self.config_dict, self.config_path) self.logger.log("Saved configuration dictionary. Backup copy at %s" % backup_path)
def install_from_dir(self, extension_dir): """Install the extension whose components are in extension_dir""" self.logger.log("Request to install extension found in directory %s" % extension_dir, level=2) # The "installer" is actually a dictionary containing what is to be # installed and where. The "installer_path" is the path to the file # containing that dictionary. installer_path, installer = weecfg.get_extension_installer(extension_dir) extension_name = installer.get("name", "Unknown") self.logger.log("Found extension with name '%s'" % extension_name, level=2) # Go through all the files used by the extension. A "source tuple" is # something like (bin, [user/myext.py, user/otherext.py]). The first # element is the directory the files go in, the second element is a # list of files to be put in that directory self.logger.log("Copying new files", level=2) N = 0 for source_tuple in installer["files"]: # For each set of sources, see if it's a type we know about for directory in ExtensionEngine.target_dirs: # This will be something like 'bin', or 'skins': source_type = os.path.commonprefix((source_tuple[0], directory)) # If there is a match, source_type will be something other # than an empty string: if source_type: # This will be something like 'BIN_ROOT' or 'SKIN_ROOT': root_type = ExtensionEngine.target_dirs[source_type] # Now go through all the files of the source tuple for install_file in source_tuple[1]: source_path = os.path.join(extension_dir, install_file) dst_file = ExtensionEngine._strip_leading_dir(install_file) destination_path = os.path.abspath(os.path.join(self.root_dict[root_type], dst_file)) self.logger.log("Copying from '%s' to '%s'" % (source_path, destination_path), level=3) if not self.dry_run: try: os.makedirs(os.path.dirname(destination_path)) except OSError: pass shutil.copy(source_path, destination_path) N += 1 break else: sys.exit("Unknown destination for file %s" % source_tuple) self.logger.log("Copied %d files" % N, level=2) save_config = False # Look for options that have to be injected into the configuration file if "config" in installer: save_config |= self._inject_config(installer["config"], extension_name) # Go through all the possible service groups and see if the extension # includes any services that belong in any of them. self.logger.log("Adding services to service lists", level=2) for service_group in all_service_groups: if service_group in installer: extension_svcs = weeutil.weeutil.option_as_list(installer[service_group]) # Be sure that the leaf node is actually a list svc_list = weeutil.weeutil.option_as_list(self.config_dict["Engine"]["Services"][service_group]) for svc in extension_svcs: # See if this service is already in the service group if svc not in svc_list: if not self.dry_run: # Add the new service into the appropriate # service group svc_list.append(svc) self.config_dict["Engine"]["Services"][service_group] = svc_list save_config = True self.logger.log("Added new service %s to %s" % (svc, service_group), level=3) # Save the extension's install.py file in the extension's installer # directory for later use enumerating and uninstalling extension_installer_dir = os.path.join(self.root_dict["EXT_ROOT"], extension_name) self.logger.log("Saving installer file to %s" % extension_installer_dir) if not self.dry_run: try: os.makedirs(os.path.join(extension_installer_dir)) except OSError: pass shutil.copy2(installer_path, extension_installer_dir) if save_config: backup_path = weecfg.save_with_backup(self.config_dict, self.config_path) self.logger.log("Saved configuration dictionary. Backup copy at %s" % backup_path)
def install_from_dir(self, extension_dir): """Install the extension that can be found in a given directory""" self.logger.log("Request to install extension found in directory %s" % extension_dir, level=2) # The "installer" is actually a dictionary containing what is to be installed and # where. The "installer_path" is the path to the file containing that dictionary. installer_path, installer = weecfg.get_extension_installer(extension_dir) extension_name = installer.get('name', 'Unknown') self.logger.log("Found extension with name '%s'" % extension_name, level=2) # Go through all the files used by the extension. A "source tuple" is something # like (bin, [user/myext.py, user/otherext.py]). The first element is the # directory the files go in, the second element is a list of files to be put # in that directory self.logger.log("Copying new files.", level=2) N = 0 for source_tuple in installer['files']: # For each set of sources, check and see if it's a type we know about for directory in ExtensionEngine.target_dirs: # This will be something like 'bin', or 'skins': source_type = os.path.commonprefix((source_tuple[0], directory)) # If there is a match, source_type will be something other than an empty string: if source_type: # This will be something like 'BIN_ROOT' or 'SKIN_ROOT': root_type = ExtensionEngine.target_dirs[source_type] # Now go through all the files of the source tuple for install_file in source_tuple[1]: source_path = os.path.join(extension_dir, install_file) destination_path = os.path.abspath(os.path.join(self.root_dict[root_type], '..', install_file)) self.logger.log("Copying from '%s' to '%s'" % (source_path, destination_path), level=3) if not self.dry_run: try: os.makedirs(os.path.dirname(destination_path)) except OSError: pass shutil.copy(source_path, destination_path) N += 1 break else: sys.exit("Unknown destination for file %s" % source_tuple) self.logger.log("Copied %d files" % N, level=2) save_config = False new_top_level = [] # Look for options that have to be injected into the configuration file if 'config' in installer: self.logger.log("Adding new sections to configuration file", level=2) # Remember any new top-level sections (so we can inject a major comment block): for top_level in installer['config']: if top_level not in self.config_dict: new_top_level.append(top_level) if not self.dry_run: # Inject any new config data into the configuration file weecfg.conditional_merge(self.config_dict, installer['config']) # Now include the major comment block for any new top level sections for new_section in new_top_level: self.config_dict.comments[new_section] = weecfg.major_comment_block + \ ["# Options for extension '%s'" % extension_name] save_config = True # Go through all the possible service groups and see if the extension provides # a new one self.logger.log("Adding new services.", level=2) for service_group in all_service_groups: if service_group in installer: extension_svcs = weeutil.weeutil.option_as_list(installer[service_group]) for svc in extension_svcs: # See if this service is already in the service group if svc not in self.config_dict['Engine']['Services'][service_group]: if not self.dry_run: # Add the new service into the appropriate service group self.config_dict['Engine']['Services'][service_group].append(svc) save_config = True self.logger.log("Added new service %s to %s" %(svc, service_group)) # Save the extension's install.py file in the extension's installer directory extension_installer_dir = os.path.join(self.root_dict['EXT_ROOT'], extension_name) self.logger.log("Saving installer file to %s" % extension_installer_dir) if not self.dry_run: try: os.makedirs(os.path.join(extension_installer_dir)) except OSError: pass shutil.copy2(installer_path, extension_installer_dir) if save_config: backup_path = weecfg.save_with_backup(self.config_dict, self.config_path) self.logger.log("Saved configuration dictionary. Backup copy at %s" % backup_path)