示例#1
0
    def cleanup_outdated_handlers(self):
        handlers = []
        pkgs = []

        # Build a collection of uninstalled handlers and orphaned packages
        # Note:
        # -- An orphaned package is one without a corresponding handler
        #    directory
        for item in os.listdir(conf.get_lib_dir()):
            path = os.path.join(conf.get_lib_dir(), item)

            if version.is_agent_package(path) or version.is_agent_path(path):
                continue

            if os.path.isdir(path):
                if re.match(HANDLER_NAME_PATTERN, item) is None:
                    continue
                try:
                    eh = ExtHandler()

                    separator = item.rfind('-')

                    eh.name = item[0:separator]
                    eh.properties.version = str(FlexibleVersion(item[separator+1:]))

                    handler = ExtHandlerInstance(eh, self.protocol)
                except Exception:
                    continue
                if handler.get_handler_state() != ExtHandlerState.NotInstalled:
                    continue
                handlers.append(handler)

            elif os.path.isfile(path) and \
                    not os.path.isdir(path[0:-len(HANDLER_PKG_EXT)]):
                if not re.match(HANDLER_PKG_PATTERN, item):
                    continue
                pkgs.append(path)

        # Then, remove the orphaned packages
        for pkg in pkgs:
            try:
                os.remove(pkg)
                logger.verbose("Removed orphaned extension package {0}".format(pkg))
            except OSError as e:
                logger.warn("Failed to remove orphaned package {0}: {1}".format(pkg, e.strerror))

        # Finally, remove the directories and packages of the
        # uninstalled handlers
        for handler in handlers:
            handler.rm_ext_handler_dir()
            pkg = os.path.join(conf.get_lib_dir(), handler.get_full_name() + HANDLER_PKG_EXT)
            if os.path.isfile(pkg):
                try:
                    os.remove(pkg)
                    logger.verbose("Removed extension package {0}".format(pkg))
                except OSError as e:
                    logger.warn("Failed to remove extension package {0}: {1}".format(pkg, e.strerror))
示例#2
0
    def cleanup_outdated_handlers(self):
        handlers = []
        pkgs = []

        # Build a collection of uninstalled handlers and orphaned packages
        # Note:
        # -- An orphaned package is one without a corresponding handler
        #    directory
        for item in os.listdir(conf.get_lib_dir()):
            path = os.path.join(conf.get_lib_dir(), item)

            if version.is_agent_package(path) or version.is_agent_path(path):
                continue

            if os.path.isdir(path):
                if re.match(HANDLER_NAME_PATTERN, item) is None:
                    continue
                try:
                    eh = ExtHandler()

                    separator = item.rfind('-')

                    eh.name = item[0:separator]
                    eh.properties.version = str(FlexibleVersion(item[separator+1:]))

                    handler = ExtHandlerInstance(eh, self.protocol)
                except Exception:
                    continue
                if handler.get_handler_state() != ExtHandlerState.NotInstalled:
                    continue
                handlers.append(handler)

            elif os.path.isfile(path) and \
                    not os.path.isdir(path[0:-len(HANDLER_PKG_EXT)]):
                if not re.match(HANDLER_PKG_PATTERN, item):
                    continue
                pkgs.append(path)

        # Then, remove the orphaned packages
        for pkg in pkgs:
            try:
                os.remove(pkg)
                logger.verbose("Removed orphaned extension package {0}".format(pkg))
            except OSError as e:
                logger.warn("Failed to remove orphaned package {0}: {1}".format(pkg, e.strerror))

        # Finally, remove the directories and packages of the
        # uninstalled handlers
        for handler in handlers:
            handler.rm_ext_handler_dir()
            pkg = os.path.join(conf.get_lib_dir(), handler.get_full_name() + HANDLER_PKG_EXT)
            if os.path.isfile(pkg):
                try:
                    os.remove(pkg)
                    logger.verbose("Removed extension package {0}".format(pkg))
                except OSError as e:
                    logger.warn("Failed to remove extension package {0}: {1}".format(pkg, e.strerror))
示例#3
0
    def del_ext_handler_files(self, warnings, actions): # pylint: disable=W0613
        ext_dirs = [d for d in os.listdir(conf.get_lib_dir())
                    if os.path.isdir(os.path.join(conf.get_lib_dir(), d))
                    and re.match(HANDLER_COMPLETE_NAME_PATTERN, d) is not None
                    and not version.is_agent_path(d)]

        for ext_dir in ext_dirs:
            ext_base = os.path.join(conf.get_lib_dir(), ext_dir)
            files = glob.glob(os.path.join(ext_base, 'status', '*.status'))
            files += glob.glob(os.path.join(ext_base, 'config', '*.settings'))
            files += glob.glob(os.path.join(ext_base, 'config', 'HandlerStatus'))
            files += glob.glob(os.path.join(ext_base, 'mrseq'))

            if len(files) > 0: # pylint: disable=len-as-condition
                actions.append(DeprovisionAction(fileutil.rm_files, files))
示例#4
0
    def del_ext_handler_files(self, warnings, actions):
        ext_dirs = [d for d in os.listdir(conf.get_lib_dir())
                    if os.path.isdir(os.path.join(conf.get_lib_dir(), d))
                    and re.match(HANDLER_NAME_PATTERN, d) is not None
                    and not version.is_agent_path(d)]

        for ext_dir in ext_dirs:
            ext_base = os.path.join(conf.get_lib_dir(), ext_dir)
            files = glob.glob(os.path.join(ext_base, 'status', '*.status'))
            files += glob.glob(os.path.join(ext_base, 'config', '*.settings'))
            files += glob.glob(os.path.join(ext_base, 'config', 'HandlerStatus'))
            files += glob.glob(os.path.join(ext_base, 'mrseq'))

            if len(files) > 0:
                actions.append(DeprovisionAction(fileutil.rm_files, files))