/src/lib/log/conf/log_file_zipped.e
Specman e | 106 lines | 73 code | 10 blank | 23 comment | 4 complexity | 1aad041b40682ac3f9dac0f68c81e2d4 MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4class LOG_FILE_ZIPPED 5 6inherit 7 LOG_FILE_OPTION 8 9create {LOG_FILE_OPTIONS} 10 make 11 12feature {LOG_FILE_OPTIONS, LOG_FILE_OPTION} 13 retrieve (stream: OUTPUT_STREAM): OUTPUT_STREAM 14 local 15 s: STREAM 16 file: FILE_STREAM 17 do 18 Result := parent.retrieve(stream) 19 s := Result 20 if Result /= stream and then file ?:= s then 21 file ::= s 22 zip(file.path, file) 23 end 24 end 25 26feature {} 27 make (a_parent: like parent; a_command: like command) 28 require 29 a_parent /= Void 30 a_command /= Void 31 do 32 parent := a_parent 33 command := a_command 34 ensure 35 parent = a_parent 36 command = a_command 37 end 38 39 parent: LOG_FILE_OPTION 40 command: FIXED_STRING 41 42 zip (file_path: STRING; file: FILE_STREAM) 43 require 44 not file.is_connected 45 local 46 dir_name, file_name: STRING 47 cmd, rotated_file_path: STRING; i: INTEGER 48 pf: PROCESS_FACTORY; p: PROCESS 49 do 50 dir_name := once "" 51 bd.compute_parent_directory_of(file_path) 52 if bd.last_entry.is_empty then 53 dir_name.make_from_string(bd.current_working_directory) 54 else 55 dir_name.copy(bd.last_entry) 56 end 57 58 file_name := once "" 59 bd.compute_short_name_of(file_path) 60 file_name.copy(bd.last_entry) 61 file_name.append(once ".1") 62 63 bd.compute_file_path_with(dir_name, file_name) 64 rotated_file_path := once "" 65 rotated_file_path.copy(bd.last_entry) 66 if ft.file_exists(rotated_file_path) then 67 cmd := once "" 68 cmd.make_from_string(command) 69 i := cmd.substring_index(once "{}", cmd.lower) 70 if cmd.valid_index(i) then 71 cmd.replace_substring(rotated_file_path, i, i + 1) 72 else 73 cmd.extend_unless(' ') 74 cmd.append(rotated_file_path) 75 end 76 p := pf.execute_command_line(cmd) 77 check 78 p /= Void 79 end 80 end 81 end 82 83 bd: BASIC_DIRECTORY 84 ft: FILE_TOOLS 85 86end -- class LOG_FILE_ZIPPED 87-- 88-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 89-- 90-- Permission is hereby granted, free of charge, to any person obtaining a copy 91-- of this software and associated documentation files (the "Software"), to deal 92-- in the Software without restriction, including without limitation the rights 93-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 94-- copies of the Software, and to permit persons to whom the Software is 95-- furnished to do so, subject to the following conditions: 96-- 97-- The above copyright notice and this permission notice shall be included in 98-- all copies or substantial portions of the Software. 99-- 100-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 101-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 102-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 103-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 104-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 105-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 106-- THE SOFTWARE.