Configuration file parameter processing method, system and equipment based on annotation and medium
By using the replacement target data and location data in comments in the configuration file for parameter replacement, the problem of inconsistency in configuration file processing logic between traditional and containerized deployments is solved, and flexible configuration file content changes and high applicability are achieved.
Patent Information
- Application Number
- CN202411908461.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-18
AI Technical Summary
When switching between traditional deployment methods and containerized deployment methods, the application needs to use two different sets of logic to process the configuration file content, or it needs to abandon the original logic and rewrite it, resulting in a lack of universality in customized solutions.
The annotation-based configuration file parameter processing method is adopted, and the replacement target data and replacement position data are obtained from the comments containing preset replacement instructions in the configuration file, and the parameters in the configuration file are dynamically replaced, so that content changes are made without changing the semantics of the configuration file.
This method does not require preset placeholders in the configuration file, which solves the problem that the configuration file must be processed before it can be loaded and used by the application, greatly improving applicability and seamless switching between traditional deployments and containerized deployments.
Smart Images

Figure CN119847589A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the technical field of configuration files, and in particular, relates to a configuration file parameter processing method, system, electronic device and storage medium based on annotations. Background Art
[0002] Container technology represented by Docker uses the isolation function provided by the operating system kernel on the physical server to achieve lightweight isolation between processes, thereby providing independent file systems, CPUs, memory, process space and other resources to applications running in containers, and has been widely used in microservice scenarios.
[0003] However, even with the support of container technology, there may still be many variables in the actual environment of application deployment. These programs need to use two different sets of logic to process the configuration file content when executing the traditional deployment method and the containerized deployment method. Either the original configuration file processing logic is discarded and a new configuration file content processing method that can be applied to both the traditional deployment mode and the containerized deployment mode is rewritten, or a dedicated agent in the containerized deployment mode is customized for each program to handle configuration file content changes to ensure that it can work properly in both the traditional deployment mode and the containerized deployment mode.
[0004] All of the above methods are customized solutions for applications that need to support both traditional deployment methods and containerized deployment methods, and are not universal. Summary of the invention
[0005] To solve the above problems, the present disclosure provides a configuration file parameter processing method, system, electronic device and storage medium based on annotations. The parameter replacement method based on annotations in this solution does not require pre-setting placeholders at positions with semantic meanings in the replaced configuration file, thus solving the problem that the configuration file must be processed before it can be loaded and used by the application, greatly improving the applicability.
[0006] In order to solve the above technical problem, the first aspect of the present invention proposes a configuration file parameter processing method based on annotations, the method comprising:
[0007] Read the configuration file content and parse the configuration file content;
[0008] When parsing a comment in the configuration file content, determining whether the comment includes a preset replacement instruction;
[0009] When the annotation includes a preset replacement instruction, obtaining replacement target data and replacement position data in the parameters of the annotation;
[0010] The replacement position in the configuration file content is determined according to the replacement position data, and the parameters of the replacement position in the configuration file content are modified to the parameters corresponding to the replacement target data.
[0011] According to a preferred embodiment of the present invention, determining the replacement position in the configuration file according to the replacement position data includes:
[0012] Acquire row data of a replacement position from the replacement position data;
[0013] When the row data is absolute row data, the first row of the configuration file content is taken as the first row, and each row is sequentially sorted in turn, and the row position of the replacement position is determined according to the row data;
[0014] When the row data is relative row data, the row where the comment is located is taken as the initial row, and the row position of the replacement position relative to the row where the comment is located is determined by the row data.
[0015] According to a preferred embodiment of the present invention, determining the replacement position in the configuration file content according to the replacement position data includes:
[0016] Acquire the column start data and the column end data of the replacement position from the replacement position data;
[0017] The column position interval of the replacement position is determined according to the column start data and the column end data.
[0018] According to a preferred embodiment of the present invention, determining the replacement position in the configuration file content according to the replacement position data includes:
[0019] Acquire the column start data and replacement length data of the replacement position from the replacement position data;
[0020] The column position interval of the replacement position is determined according to the column start data and the replacement length data.
[0021] According to a preferred embodiment of the present invention, determining the replacement position in the configuration file content according to the replacement position data includes:
[0022] Acquire the column start data and the filter function of the replacement position from the replacement position data;
[0023] Determine the column start position according to the column start data;
[0024] Filter the parameters at and after the column start position by using the filter function, and use the parameters at and after the column start position that meet the filter function as replaced parameters;
[0025] The position of the replaced parameter is used as the replacement position.
[0026] According to a preferred embodiment of the present invention, the step of modifying the parameters of the replacement position in the configuration file content to parameters corresponding to the replacement target data includes:
[0027] Determine the environment variable by replacing the target data;
[0028] Parameters are obtained from the environment variables to modify the parameters of the replacement position in the configuration file content.
[0029] According to a preferred embodiment of the present invention, after modifying the parameters of the replacement position in the configuration file content to the parameters corresponding to the replacement target data, the method further includes:
[0030] Rewrite the configuration file content back to the corresponding configuration file.
[0031] In order to solve the above technical problem, the second aspect of the present invention proposes a configuration file parameter processing system based on annotations, the processing system comprising:
[0032] Configuration file reading and writing module, used to read the contents of the configuration file;
[0033] A configuration file parsing module, used to parse the contents of the configuration file;
[0034] A configuration file parsing module, configured to determine whether a preset replacement instruction is included in the annotation when parsing the annotation in the configuration file content;
[0035] An instruction parsing module, used for obtaining replacement target data and replacement position data in the parameters of the annotation when the annotation includes a preset replacement instruction;
[0036] The parameter replacement module is used to determine the replacement position in the configuration file content according to the replacement position data, and modify the parameters of the replacement position in the configuration file content to the parameters corresponding to the replacement target data.
[0037] In order to solve the above technical problem, the third aspect of the present invention provides an electronic device, comprising:
[0038] Processor; and
[0039] A memory storing computer executable instructions, wherein when the computer executable instructions are executed, the processor executes the method described in any one of the above embodiments.
[0040] In order to solve the above technical problems, the fourth aspect of the present invention proposes a computer storage medium, wherein the computer storage medium stores one or more programs, and when the one or more programs are executed by a processor, the method described in any one of the above embodiments is implemented.
[0041] Compared with the prior art, the present disclosure has the following advantages: the present disclosure reads and parses the content of the configuration file. When the content of the configuration file includes comments of preset replacement instructions, the parameters that need to be replaced in the content of the configuration file are replaced with the parameters corresponding to the replacement target data through the replacement target data and the replacement position data in the comments. Through this solution, annotation information in a specific format can be added to the configuration file without changing the semantics of the current configuration file, so that a configuration file with fixed content can be converted into a flexible configuration file that can be changed by a common configuration file content processing device. It can be widely used in different fields such as containerization transformation and existing application upgrades. The parameter replacement method based on annotations does not need to preset placeholders at positions with semantic meanings in the configuration file to be replaced, which solves the problem that the configuration file must be processed before it can be loaded and used by the application, greatly improving the applicability.
[0042] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or be understood by implementing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 A first flow chart of a method for processing configuration file parameters based on annotations according to an embodiment of the present disclosure is shown;
[0045] Figure 2 A second flow chart of a method for processing configuration file parameters based on annotations according to an embodiment of the present disclosure is shown;
[0046] Figure 3 A third flow chart of a method for processing configuration file parameters based on annotations according to an embodiment of the present disclosure is shown;
[0047] Figure 4A fourth flow chart of a method for processing configuration file parameters based on annotations according to an embodiment of the present disclosure is shown;
[0048] Figure 5 A fifth flow chart of a method for processing configuration file parameters based on annotations according to an embodiment of the present disclosure is shown;
[0049] Figure 6 A block diagram of a configuration file parameter processing system based on annotations according to an embodiment of the present disclosure is shown;
[0050] Figure 7 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0052] The same reference numerals in the drawings represent the same or similar elements, components or parts, and thus the repeated description of the same or similar elements, components or parts may be omitted below. It should also be understood that although the first, second, third and other attributives representing the numbers may be used herein to describe various devices, elements, components or parts, these devices, elements, components or parts should not be limited by these attributives. In other words, these attributives are only used to distinguish one from another. For example, the first device may also be called the second device, but it does not deviate from the essential technical solution of the present invention. In addition, the terms "and / or" and "and / or" refer to all combinations including any one or more of the listed items.
[0053] See also Figure 1 , Figure 1 This is a flow chart of a configuration file parameter processing method based on annotations provided by the present invention, such as Figure 1 As shown, the method includes:
[0054] S11. Read the configuration file content and parse the configuration file content.
[0055] In this embodiment, a configuration file is a document used to store and manage settings and parameters of software, systems or applications.
[0056] In this embodiment, the content of the configuration file may be completely read into the content of the processor, and then the content of the configuration file may be parsed.
[0057] S12. When parsing the comments in the configuration file content, determine whether the comments include a preset replacement instruction.
[0058] In this embodiment, the comment is a portion of the code that is not executed by the computer but is used to provide instructions to developers or other people reading the code about the function, purpose or working principle of the code.
[0059] In this embodiment, the content of the configuration file can be parsed line by line. If the line is not a comment, it will not be parsed further and will go to the next line until a comment is parsed. At this time, it is determined whether the comment includes a preset replacement instruction. The preset replacement instruction of this scheme can be set at any position of the comment. In order to facilitate the rapid determination of the comment, the preset replacement instruction can be set to the head position of the comment. When the comment does not start with the preset replacement instruction, it will not be parsed further and can go directly to the next line, thereby improving data processing efficiency.
[0060] S13. When a preset replacement instruction is included in the annotation, the replacement target data and the replacement position data in the parameters of the annotation are obtained.
[0061] In this embodiment, when a preset replacement instruction is included in a comment, the instruction in the comment is parsed according to a preset instruction definition to obtain information such as replacement target data and the location of the replaced content in the configuration file content.
[0062] S14. Determine a replacement position in the configuration file content according to the replacement position data, and modify parameters of the replacement position in the configuration file content to parameters corresponding to the replacement target data.
[0063] In this embodiment, the replacement position is determined in the configuration file content by replacing the position data. For example, the number of rows and columns can be set to locate the replaced position in the configuration file, or the replaced content can be directly written and the replacement position is determined based on the position of the replaced content in the configuration file content.
[0064] In this embodiment, after the replacement position in the configuration file content is determined, the parameters of the replacement position are modified to parameters corresponding to the replacement target data.
[0065] Specifically, in order to improve the adaptability of replacement data, the replacement target data in this solution can be a character string that complies with the naming conventions of operating system environment variables, which is used to indicate which environment variable or other data source with the same key:value structure should be used to obtain the parameter value from the processing device when performing parameter replacement. In this way, when modifying the parameters at the replacement position, it is not necessary to write the replacement data directly into the comment, but only to modify the value in the environment variable or other data source with the same key:value structure. This allows users to quickly update when parameter replacement is required. Specifically, the environment variable is determined by replacing the target data; the parameters at the replacement position in the configuration file content are modified by obtaining the parameters from the environment variable.
[0066] In this embodiment, after the parameters in the configuration file content are modified, the configuration file content is written back to the original configuration file.
[0067] The present disclosure reads and parses the content of the configuration file. When the configuration file content includes comments with preset replacement instructions, the parameters that need to be replaced in the configuration file content are replaced with the parameters corresponding to the replacement target data through the replacement target data and replacement position data in the comments. Through this solution, annotation information in a specific format can be added to the configuration file without changing the semantics of the current configuration file. A configuration file with fixed content can be converted into a flexible configuration file whose content can be changed by a common configuration file content processing device. It can be widely used in different fields such as containerization transformation and existing application upgrades. The parameter replacement method based on annotations does not need to pre-set placeholders at positions with semantic meanings in the configuration file to be replaced, which solves the problem that the configuration file must be processed before it can be loaded and used by the application, greatly improving the applicability.
[0068] See also Figure 2 , Figure 2 The second flowchart of the configuration file parameter processing method based on annotations provided by the present invention is as follows: Figure 2 As shown, in S14, determining the replacement position in the configuration file content according to the replacement position data specifically includes:
[0069] S21. Obtain row data of the replacement position from the replacement position data.
[0070] In this embodiment, the line data in this solution indicates which line of the configuration file the content to be replaced is in. The line data can be directly identified by numbers, such as line 1, line 2, etc.
[0071] S22. When the row data is absolute row data, the first row of the configuration file content is taken as the first row, and each row is sequentially sorted in sequence, and the row position of the replacement position is determined according to the row data.
[0072] In this embodiment, in the context of programming and text editing, "absolute line" and "relative line" are generally used to indicate the number of lines in a code or text, and the two have different meanings:
[0073] In this embodiment, absolute line, definition: Absolute line refers to the actual line number of a code or text file, counting from the first line. For example, the first line in a file is absolute line 1, the second line is absolute line 2, and so on. Purpose: Absolute line is usually used when you need to reference or locate a specific line in a file. For example, when debugging code, a developer may say "the error occurred on line 100 of the file", where "line 100" is the absolute line.
[0074] S23. When the row data is relative row data, the row where the comment is located is taken as the initial row, and the row position of the replacement position relative to the row where the comment is located is determined by the row data.
[0075] In this embodiment, relative lines are defined as follows: relative lines are based on the current line, and other lines are indicated by plus and minus signs. For example, if the current line is line 50, then moving down 5 lines is the relative line "+5", that is, line 55; moving up 3 lines is the relative line "-3", that is, line 47. Purpose: When browsing or editing text, using relative lines makes it easier to navigate to nearby lines. For example, when viewing code, developers may use relative lines to quickly jump to a line above or below the current line.
[0076] In this embodiment, for configuration files with a small amount of data, the use of absolute lines can allow users to more clearly determine the line number of the replaced content that needs to be modified. However, for configuration files with a large amount of data, if the number of lines is determined by counting from the first line, the workload is large. In this case, relative lines can be used to determine the line number of the replaced content that needs to be modified, thereby improving data processing efficiency.
[0077] See also Figure 3 , Figure 3 The third is a flow chart of a configuration file parameter processing method based on annotations provided by the present invention, such as Figure 3 As shown, in S14, determining the replacement position in the configuration file content according to the replacement position data specifically includes:
[0078] S31. Obtain the column start data and column end data of the replacement position from the replacement position data.
[0079] In this embodiment, after the number of rows of the replaced content is determined through the above embodiment, the specific position of the replaced content needs to be further determined. In this solution, the specific position can be determined by the column start data and the column end data.
[0080] S32. Determine a column position interval of a replacement position according to the column start data and the column end data.
[0081] In this embodiment, in combination with the solutions in the above embodiments, the annotation includes: preset replacement instructions, replacement target data and replacement position data; the replacement position data includes: row data, column start data and column end data.
[0082] In this embodiment, the column position range of the replacement position can be determined by the column start data and the column end data.
[0083] See also Figure 4 , Figure 4 The fourth is a flow chart of a configuration file parameter processing method based on annotations provided by the present invention, such as Figure 4 As shown, in S14, determining the replacement position in the configuration file content according to the replacement position data specifically includes:
[0084] S41. Obtain the column start data and replacement length data of the replacement position from the replacement position data.
[0085] In this embodiment, after the number of rows of the replaced content is determined through the above embodiment, the specific position of the replaced content needs to be further determined. In this solution, the specific position can be determined by the column start data and the replacement length data.
[0086] S42: Determine the column position interval of the replacement position according to the column start data and the replacement length data.
[0087] In this embodiment, in combination with the solutions in the above embodiments, the annotation includes: preset replacement instructions, replacement target data and replacement position data; the replacement position data includes: row data, column start data and replacement length data.
[0088] In this embodiment, the column position range of the replacement position can be determined by the column start data and the replacement length data.
[0089] In a specific embodiment, in combination with Figure 2 , Figure 3 and Figure 4 An embodiment of
[0090] Comment start tag and comment end tag: defined by the corresponding format of the configuration file to ensure that the instructions in the configuration file are all legal comment information and will not have any impact on the semantics of the original configuration file. For example: JAVA's .properties file, Python's .py file, etc., their <comment start tag> is "#" and there is no [comment end tag]; while the <comment start tag> of .xml and .html files is "<!--" and the [comment end tag] is "-->". There will be different comment tags in different language environments. In this solution, the tags for filtering comments can be adjusted according to the language environment.
[0091] The instruction start prefix is the preset replacement instruction in this solution. It can be a string of character strings with characteristic meanings that can be defined by the application developer to ensure that the instructions of the present invention are distinguished from the comments in other parts of the configuration file, so as to prevent the processing device from mistakenly processing the non-instruction comment information as an instruction.
[0092] Parameter name, which is the replacement target data in this solution, can be a string that complies with the naming convention of operating system environment variables, used to indicate which environment variable (or other data source with the same key:value structure) the processing device should obtain the parameter value from when performing parameter replacement.
[0093] The line where the content is located is the line data in the replacement position data in this solution. It can indicate which line of the configuration file the content to be replaced is in, and supports two writing methods: "absolute line" and "relative line". When <the line where the content is located> is "x" (x is a pure number of any number of digits), it means "the absolute line starting from 1", that is, the line numbers are arranged in sequence with the first line of the configuration file as the first line; and when <the line where the content is located> is "+x" or "-x" (x is a pure number of any number of digits), it means "the xth line after the line where the current comment instruction is located" or "the xth line before the line where the current comment instruction is located".
[0094] The starting column is the column starting data in the replacement position data in this solution. It can indicate the column number of the line from which the content to be replaced starts (the starting column of the first character in each line is 1, and the following characters are deduced in the same way).
[0095] The end column or length, the end column is the column end data in the replacement position data in this solution, and the length is the replacement length data in the replacement position data in this solution. It can be indicated how much content is to be replaced from the <starting column>. Considering different application scenarios, three representation forms are supported here: "x" (x is a pure number of any number of digits) represents the <end column>, and its value should be greater than or equal to the <starting column>; "+x" (x is a pure number of any number of digits) represents the <length> is "x";
[0096] For example, the configuration file content 1 may be as follows:
[0097]
[0098] The semantics of the configuration file content is to specify the output levels of two different types of logs. In a certain deployment, if we need to set the auditlevel from stat to debug and the securitylevel from stat to info.
[0099] Based on the solution disclosed in this embodiment, combined with the solution in the above embodiment, the annotation includes: preset replacement instructions, replacement target data and replacement position data; the replacement position data includes: row data.
[0100] At this point, the content of configuration file 2 in this solution is as follows:
[0101]
[0102] Configuration file content 2 and configuration file content 1 are two configuration files that are completely identical in semantics. Therefore, when configuration file content 1 is needed, it is feasible to directly replace it with configuration file content 2 without additional processing. Similarly, under the premise that the environment variables AUDIT_LEVEL=16 and SECURITY_LEVEL=64 are defined, that is, the replacement target data is AUDIT_LEVEL=16 and SECURITY_LEVEL=64, and the <comment start mark> is specified as #, that is, whether it is a comment is determined by #, and the <instruction start prefix> is VaRrEpLaCe, that is, the preset replacement instruction is VaRrEpLaCe, the configuration file content 2 is input to the processing system of the present invention, and the following processing will be performed:
[0103] a) Read the configuration file content 2 into the memory;
[0104] b) Check the first line of configuration file content 2. No <instruction start prefix> is found after <comment start tag>. This line is considered to be a normal comment and is skipped directly.
[0105] c) Check the second line of configuration file content 2 and find that it conforms to the form of comment instruction. Then further parse it and extract <parameter name> as AUDIT_LEVEL, <line> as current line + 1 (i.e. the third line), <starting column> as the 12th column (i.e. the position of the number 1 after the equal sign in the third line), and <length> as 1. Then read the value of AUDIT_LEVEL as 16 from the environment variable. Finally, replace the number 1 after the equal sign in the third line with the number 16 in the memory to complete this processing.
[0106] d) Check the third and fourth lines of configuration file content 2 respectively, and find that these two lines are not comments, so skip them directly;
[0107] e) Check the fifth line of configuration file content 2 and find that it conforms to the form of comment instruction. Then further parse it and extract <parameter name> as SECURITY_LEVEL, <line> as current line - 1 (i.e., the fourth line), <start column> as 15th column (i.e., the position of number 1 after the equal sign in the fourth line), and <end column> as 16. Then read the value of SECURITY_LEVEL as 64 from the environment variable. Finally, replace the number 1 after the equal sign in the fourth line with the number 64 in the memory to complete this processing.
[0108] f) Write the replaced file contents in the memory back to the disk. The configuration file contents at this time are as follows:
[0109]
[0110]
[0111] See also Figure 5 , Figure 5 The fifth flowchart of the configuration file parameter processing method based on annotations provided by the present invention is as follows: Figure 5 As shown, in S14, determining the replacement position in the configuration file content according to the replacement position data specifically includes:
[0112] S51. Obtain column start data and a filter function of the replacement position from the replacement position data.
[0113] In this embodiment, after the number of rows of the replaced content is determined through the above embodiment, it is necessary to further determine the specific position of the replaced content. In this solution, the specific position can be determined through the column start data and the filter function.
[0114] S52: Determine the column start position according to the column start data.
[0115] S53: Filter the parameters at and after the column start position by using a filter function, and use the parameters at and after the column start position that meet the filter function as replaced parameters.
[0116] In this embodiment, in combination with the solutions in the above embodiments, the annotation includes: preset replacement instructions, replacement target data and replacement position data; the replacement position data includes: row data, column start data and filter function.
[0117] In this embodiment, the starting position of the column and the parameters thereafter are filtered by a filtering function to determine the parameters that meet the filtering function and the replaced parameters.
[0118] S54. Use the position of the replaced parameter as the replacement position.
[0119] In this embodiment, the replacement position of this solution is determined based on the determined replaced parameter.
[0120] In a specific embodiment, the content in the .xml file is replaced, and the configuration file content 3 that needs to be replaced is as follows:
[0121]
[0122]
[0123] The semantics of the .xml file specifies the output format and output level of the console log. In a certain deployment, if we need to change the output level of the console log from info to debug, and introduce the technology of the present invention, the .xml file in the configuration file content 3 can be written in the following form (hereinafter referred to as configuration file content 4):
[0124]
[0125] Naturally, the configuration file content 4 and the configuration file content 3 are semantically identical. Under the premise that the environment variable LOG_LEVEL=debug is defined, <comment start tag> is <! --, <comment end tag> is -->, and <instruction start prefix> is VaRrEpLaCe, the configuration file content 4 is input to the processing device of the present invention, and the following processing is performed:
[0126] a) Read the configuration file content 4 into the memory;
[0127] b) Check the first three lines of configuration file content 4. If no <comment start tag> is found, skip it directly;
[0128] c) Check the fourth line of configuration file content 4. No <instruction start prefix> is found after <comment start marker> and there is no other content after <comment end marker>. This line is considered to be a normal comment and is skipped directly.
[0129] d) Check the fifth to fourteenth lines of the configuration file content 4, and if no <comment start tag> is found, skip it directly;
[0130] e) Check the 15th line of the configuration file content 4, and find that the line conforms to the form of the comment instruction. Then further parse it, extract <parameter name> as LOG_LEVEL, <line> as line 11, <start column> as column 18, use the regular expression [az]* to match the replaced content (in this case, the match will hit the word info), then read the value of LOG_LEVEL as debug from the environment variable, and finally replace "info" in line 11 with "debug" in the memory to complete this processing;
[0131] f) Write the replaced file contents in memory back to disk. The contents of the .xml file are as follows:
[0132]
[0133] See also Figure 6 , Figure 6 is a block diagram of a configuration file parameter processing system based on annotations provided by the present invention, such as Figure 6 As shown, the processing system includes: a configuration file reading and writing module 11, a configuration file parsing module 12, an instruction parsing module 13 and a parameter replacing module 14.
[0134] In this embodiment, the configuration file reading and writing module 11 is used to read the content of the configuration file.
[0135] In this embodiment, the configuration file parsing module 12 is used to parse the content of the configuration file.
[0136] In this embodiment, the configuration file parsing module 12 is used to determine whether the comment includes a preset replacement instruction when parsing the comment in the configuration file content.
[0137] In this embodiment, the instruction parsing module 13 is used to obtain the replacement target data and the replacement position data in the parameters of the annotation when the annotation includes a preset replacement instruction.
[0138] In this embodiment, the parameter replacement module 14 is used to determine the replacement position in the configuration file content according to the replacement position data, and modify the parameters of the replacement position in the configuration file content to parameters corresponding to the replacement target data.
[0139] In this embodiment, the parameter replacement module 14 is specifically used to obtain the row data of the replacement position from the replacement position data; when the row data is absolute row data, the first row of the configuration file content is taken as the first row, and each row is sequentially sorted in turn, and the row position of the replacement position is determined by the row data; when the row data is relative row data, the row where the comment is located is taken as the initial row, and the row position of the replacement position relative to the row where the comment is located is determined by the row data.
[0140] In this embodiment, the parameter replacement module 14 is specifically configured to obtain the column start data and the column end data of the replacement position from the replacement position data; and determine the column position interval of the replacement position according to the column start data and the column end data.
[0141] In this embodiment, the parameter replacement module 14 is specifically configured to obtain the column start data and replacement length data of the replacement position from the replacement position data; and determine the column position interval of the replacement position according to the column start data and the replacement length data.
[0142] In this embodiment, the parameter replacement module 14 is specifically used to obtain the column starting data and the filter function of the replacement position from the replacement position data; determine the column starting position according to the column starting data; filter the parameters at and after the column starting position through the filter function, and use the parameters at and after the column starting position that meet the filter function as the replaced parameters; and use the position of the replaced parameter as the replacement position.
[0143] In this embodiment, the parameter replacement module 14 is specifically used to determine the environment variables by replacing the target data; obtain the parameters from the environment variables to modify the parameters of the replacement position in the configuration file content.
[0144] In this embodiment, the configuration file reading and writing module 11 is also used to rewrite the configuration file content back to the corresponding configuration file.
[0145] like Figure 7 As shown, an embodiment of the present invention provides an electronic device, including a processor 1110, a communication interface 1120, a memory 1130 and a communication bus 1140, wherein the processor 1110, the communication interface 1120, and the memory 1130 communicate with each other through the communication bus 1140;
[0146] Memory 1130, used for storing computer programs;
[0147] The processor 1110 is used to implement any of the above processing methods when executing the program stored in the memory 1130.
[0148] In the electronic device provided by the embodiment of the present invention, the processor 1110 reads the configuration file content and parses the configuration file content by executing the program stored in the memory 1130; when parsing the annotation in the configuration file content, determines whether the annotation includes a preset replacement instruction; when the annotation includes a preset replacement instruction, obtains the replacement target data and replacement position data in the parameters of the annotation; determines the replacement position in the configuration file content according to the replacement position data, and modifies the parameters of the replacement position in the configuration file content to parameters corresponding to the replacement target data.
[0149] The communication bus 1140 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus 1140 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0150] The communication interface 1120 is used for communication between the above electronic device and other devices.
[0151] The memory 1130 may include a random access memory 1130 (RAM), or may include a non-volatile memory 1130 (non-volatile memory), such as at least one disk memory 1130. Optionally, the memory 1130 may also be at least one storage device located away from the processor 1110.
[0152] The above-mentioned processor 1110 can be a general-purpose processor 1110, including a central processing unit 1110 (CPU), a network processor 1110 (NP), etc.; it can also be a digital signal processor 1110 (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0153] An embodiment of the present invention provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors 1110 to implement the processing method of any of the above embodiments.
[0154] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk SolidStateDisk (SSD)), etc.
[0155] Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A configuration file parameter processing method based on annotations, characterized in that: The processing method comprises: Read the configuration file content and parse the configuration file content; When parsing a comment in the configuration file content, determining whether the comment includes a preset replacement instruction; When the annotation includes a preset replacement instruction, obtaining replacement target data and replacement position data in the parameters of the annotation; The replacement position in the configuration file content is determined according to the replacement position data, and the parameters of the replacement position in the configuration file content are modified to the parameters corresponding to the replacement target data.
2. The processing method according to claim 1, characterized in that: Determining the replacement position in the configuration file according to the replacement position data includes: Acquire row data of a replacement position from the replacement position data; When the row data is absolute row data, the first row of the configuration file content is taken as the first row, and each row is sequentially sorted in sequence, and the row position of the replacement position is determined according to the row data; When the row data is relative row data, the row where the annotation is located is taken as the initial row, and the row position of the replacement position relative to the row where the annotation is located is determined by the row data.
3. The processing method according to claim 2, characterized in that: The determining the replacement position in the configuration file content according to the replacement position data includes: Acquire the column start data and the column end data of the replacement position from the replacement position data; The column position interval of the replacement position is determined according to the column start data and the column end data.
4. The processing method according to claim 2, characterized in that: The determining the replacement position in the configuration file content according to the replacement position data includes: Acquire the column start data and replacement length data of the replacement position from the replacement position data; The column position interval of the replacement position is determined according to the column start data and the replacement length data.
5. The processing method according to claim 2, characterized in that: The determining the replacement position in the configuration file content according to the replacement position data includes: Acquire the column start data and the filter function of the replacement position from the replacement position data; Determine the column start position according to the column start data; Filter the parameters at and after the column start position by using the filter function, and use the parameters at and after the column start position that meet the filter function as replaced parameters; The position of the replaced parameter is used as the replacement position.
6. The processing method according to claim 1, characterized in that: The step of modifying the parameters of the replacement position in the configuration file content to parameters corresponding to the replacement target data includes: Determine the environment variable by replacing the target data; Parameters are obtained from the environment variables to modify the parameters of the replacement position in the configuration file content.
7. The processing method according to any one of claims 1 to 6, characterized in that: After modifying the parameters of the replacement position in the configuration file content to the parameters corresponding to the replacement target data, the method further includes: Rewrite the configuration file content back to the corresponding configuration file.
8. A configuration file parameter processing system based on annotations, characterized in that: The processing system comprises: Configuration file reading and writing module, used to read the contents of the configuration file; A configuration file parsing module, used to parse the contents of the configuration file; A configuration file parsing module, configured to determine whether a preset replacement instruction is included in the annotation when parsing the annotation in the configuration file content; An instruction parsing module, used for obtaining replacement target data and replacement position data in the parameters of the annotation when the annotation includes a preset replacement instruction; The parameter replacement module is used to determine the replacement position in the configuration file content according to the replacement position data, and modify the parameters of the replacement position in the configuration file content to the parameters corresponding to the replacement target data.
9. An electronic device, characterized in that: include: processor; as well as A memory storing computer executable instructions which, when executed, cause the processor to perform the method according to any one of claims 1-7.
10. A computer storage medium, characterized in that: in, The computer storage medium stores one or more programs, and when the one or more programs are executed by a processor, the method of any one of claims 1 to 7 is implemented.