/src/lib/log/conf/log_file_zipped.e

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