def tokenize_path(self, path):
        """
        Replace known directories that will be different in the target with tokens denoting the type
        of directory

        :param path: to check for directories to be tokenized
        :return: tokenized path or original path
        """
        my_path = path_utils.fixup_path(path)
        tmp_dir = path_utils.fixup_path(tempfile.gettempdir())
        cwd = path_utils.fixup_path(os.path.dirname(os.path.abspath(__file__)))

        # decide later what is required to be in context home for appropriate exception prevention
        result = my_path
        if my_path:
            if self.get_wl_home() and my_path.startswith(self.get_wl_home()):
                result = my_path.replace(self.get_wl_home(),
                                         self.__WL_HOME_TOKEN)
            elif self.get_domain_home() and my_path.startswith(
                    self.get_domain_home()):
                result = my_path.replace(self.get_domain_home(),
                                         self.__DOMAIN_HOME_TOKEN)
            elif self.get_oracle_home() and my_path.startswith(
                    self.get_oracle_home()):
                result = my_path.replace(self.get_oracle_home(),
                                         self.__ORACLE_HOME_TOKEN)
            elif my_path.startswith(cwd):
                result = my_path.replace(cwd, self.__CURRENT_DIRECTORY_TOKEN)
            elif my_path.startswith(tmp_dir):
                result = my_path.replace(tmp_dir, self.__TEMP_DIRECTORY_TOKEN)

        return result
    def replace_token_string(self, string_value):
        """
        Replace the tokens in string value with the current value of the token.
        :param string_value: the value on which to perform token replacement
        :return: the detokenized value, or the original value if there were no tokens
        """
        if string_value is None:
            result = None
        elif string_value.startswith(self.__ORACLE_HOME_TOKEN):
            result = _replace(string_value, self.__ORACLE_HOME_TOKEN,
                              self.get_oracle_home())
        elif string_value.startswith(self.__WL_HOME_TOKEN):
            result = _replace(string_value, self.__WL_HOME_TOKEN,
                              self.get_wl_home())
        elif string_value.startswith(self.__DOMAIN_HOME_TOKEN):
            result = _replace(string_value, self.__DOMAIN_HOME_TOKEN,
                              self.get_domain_home())
        elif string_value.startswith(self.__CURRENT_DIRECTORY_TOKEN):
            result = _replace(string_value, self.__CURRENT_DIRECTORY_TOKEN,
                              path_utils.fixup_path(os.getcwd()))
        elif string_value.startswith(self.__TEMP_DIRECTORY_TOKEN):
            result = _replace(string_value, self.__TEMP_DIRECTORY_TOKEN,
                              path_utils.fixup_path(tempfile.gettempdir()))
        else:
            result = string_value

        return result
    def replace_tokens(self, resource_type, resource_name, attribute_name, resource_dict):
        """
        Replace the tokens in attribute value with the current value.
        :param resource_type: the resource type (used for logging purposes)
        :param resource_name: the resource name (used for logging purposes)
        :param attribute_name: the attribute name for which to replace tokens
        :param resource_dict: the dictionary to use to lookup and replace the attribute value
        """
        attribute_value = resource_dict[attribute_name]
        if attribute_value is None:
            return
        uri = URI(attribute_value)
        uri_scheme = uri.getScheme()
        if uri_scheme is not None and uri_scheme.startsWith('file'):
            attribute_value = uri.getPath()
        if attribute_value.startswith(self.ORACLE_HOME_TOKEN):
            message = "Replacing {0} in {1} {2} {3} with {4}"
            self._logger.fine(message, self.ORACLE_HOME_TOKEN, resource_type, resource_name, attribute_name,
                              self.get_oracle_home(), class_name=self._class_name, method_name='_replace_tokens')
            resource_dict[attribute_name] = attribute_value.replace(self.ORACLE_HOME_TOKEN,
                                                                    self.get_oracle_home())
        elif attribute_value.startswith(self.WL_HOME_TOKEN):
            message = "Replacing {0} in {1} {2} {3} with {4}"
            self._logger.fine(message, self.WL_HOME_TOKEN, resource_type, resource_name, attribute_name,
                              self.get_wl_home(), class_name=self._class_name, method_name='_replace_tokens')
            resource_dict[attribute_name] = attribute_value.replace(self.WL_HOME_TOKEN, self.get_wl_home())
        elif attribute_value.startswith(self.DOMAIN_HOME_TOKEN):
            message = "Replacing {0} in {1} {2} {3} with {4}"
            self._logger.fine(message, self.DOMAIN_HOME_TOKEN, resource_type, resource_name, attribute_name,
                              self.get_domain_home(), class_name=self._class_name, method_name='_replace_tokens')
            resource_dict[attribute_name] = attribute_value.replace(self.DOMAIN_HOME_TOKEN,
                                                                    self.get_domain_home())
        elif attribute_value.startswith(self.JAVA_HOME_TOKEN):
            message = "Replacing {0} in {1} {2} {3} with {4}"
            self._logger.fine(message, self.JAVA_HOME_TOKEN, resource_type, resource_name, attribute_name,
                              self.get_domain_home(), class_name=self._class_name, method_name='_replace_tokens')
            resource_dict[attribute_name] = attribute_value.replace(self.JAVA_HOME_TOKEN,
                                                                    self.get_java_home())
        elif attribute_value.startswith(self.CURRENT_DIRECTORY_TOKEN):
            cwd = path_utils.fixup_path(os.getcwd())
            message = "Replacing {0} in {1} {2} {3} with {4}"
            self._logger.fine(message, self.CURRENT_DIRECTORY_TOKEN, resource_type, resource_name,
                              attribute_name, cwd, class_name=self._class_name, method_name='_replace_tokens')
            resource_dict[attribute_name] = attribute_value.replace(self.CURRENT_DIRECTORY_TOKEN, cwd)
        elif attribute_value.startswith(self.TEMP_DIRECTORY_TOKEN):
            temp_dir = path_utils.fixup_path(tempfile.gettempdir())
            message = "Replacing {0} in {1} {2} {3} with {4}"
            self._logger.fine(message, self.TEMP_DIRECTORY_TOKEN, resource_type, resource_name, attribute_name,
                              temp_dir, class_name=self._class_name, method_name='_replace_tokens')
            resource_dict[attribute_name] = attribute_value.replace(self.TEMP_DIRECTORY_TOKEN, temp_dir)

        return
Exemplo n.º 4
0
    def _add_classpath_libraries_to_archive(self, model_name, model_value, location):
        """
        This is a private method.

        Add the server files and directories listed in the server classpath attribute to the archive file.
        File locations in the oracle_home will be removed from the classpath and will not be added to the archive file.
        :param model_name: attribute for the server server start classpath attribute
        :param model_value: classpath value in domain
        :param location: context containing current location information
        :return model
        """
        _method_name = 'add_classpath_libraries_to_archive'
        server_name = self._get_server_name_from_location(location)
        _logger.entering(server_name, model_name, model_value, class_name=_class_name, method_name=_method_name)

        classpath_string = None
        if not StringUtils.isEmpty(model_value):
            classpath = path_utils.fixup_path(model_value)

            # model values are comma-separated
            classpath_entries = classpath.split(MODEL_LIST_DELIMITER)

            if classpath_entries:
                classpath_list = []
                for classpath_entry in classpath_entries:
                    new_source_name = self._add_library(server_name, classpath_entry)
                    if new_source_name is not None:
                        classpath_list.append(new_source_name)

                classpath_string = StringUtils.getStringFromList(classpath_list, MODEL_LIST_DELIMITER)
                _logger.fine('WLSDPLY-06617', server_name, classpath_string, class_name=_class_name,
                             method_name=_method_name)

        _logger.exiting(class_name=_class_name, method_name=_method_name, result=classpath_string)
        return classpath_string
Exemplo n.º 5
0
    def tokenize_path(self, path):
        """
        Replace known directories that will be different in the target with tokens denoting the type
        of directory

        :param path: to check for directories to be tokenized
        :return: tokenized path or original path
        """
        my_path = path_utils.fixup_path(path)
        wl_home = path_utils.fixup_path(self.get_wl_home())
        domain_home = path_utils.fixup_path(self.get_domain_home())
        oracle_home = path_utils.fixup_path(self.get_oracle_home())
        java_home = path_utils.fixup_path(self.get_java_home())
        tmp_dir = path_utils.fixup_path(tempfile.gettempdir())
        cwd = path_utils.fixup_path(os.path.dirname(os.path.abspath(__file__)))

        # decide later what is required to be in context home for appropriate exception prevention
        result = my_path
        if not string_utils.is_empty(my_path):
            if wl_home is not None and my_path.startswith(wl_home):
                result = my_path.replace(wl_home, self.WL_HOME_TOKEN)
            elif domain_home is not None and my_path.startswith(domain_home):
                result = my_path.replace(domain_home, self.DOMAIN_HOME_TOKEN)
            elif oracle_home is not None and my_path.startswith(oracle_home):
                result = my_path.replace(oracle_home, self.ORACLE_HOME_TOKEN)
            elif java_home is not None and my_path.startswith(java_home):
                result = my_path.replace(java_home, self.JAVA_HOME_TOKEN)
            elif my_path.startswith(cwd):
                result = my_path.replace(cwd, self.CURRENT_DIRECTORY_TOKEN)
            elif my_path.startswith(tmp_dir):
                result = my_path.replace(tmp_dir, self.TEMP_DIRECTORY_TOKEN)

        return result
Exemplo n.º 6
0
    def _is_oracle_home_file(self, file_name):
        """
        Determine if the absolute file name starts with an oracle home. Disregard if the application is
        located in the domain home.

        :param file_name: to check for oracle home or weblogic home
        :return: true if in oracle home location
        """
        py_str = path_utils.fixup_path(str(file_name))
        return (not py_str.startswith(self._model_context.get_domain_home())) and \
            (py_str.startswith(self._model_context.get_oracle_home()) or
             py_str.startswith(self._model_context.get_wl_home()))