runit-man 1.9.8 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,15 @@ runit:
53
53
  updated: "Page updated at %1"
54
54
  reload: Reload
55
55
  raw: Raw
56
+ downloads: Log downloads
57
+ download: Download
58
+ modified: Last modified
59
+ file_name: File name
60
+ file_size: File size
61
+ b: b
62
+ Kb: Kb
63
+ Mb: Mb
64
+ Gb: Gb
56
65
  view_file:
57
66
  raw: Raw
58
67
  title: 'File %1 on %2'
@@ -55,6 +55,15 @@ runit:
55
55
  updated: "Страница обновлена %1"
56
56
  reload: Обновить страницу
57
57
  raw: Текст
58
+ downloads: Загрузка логов
59
+ download: Скачать
60
+ modified: Последнее изменение
61
+ file_name: Имя файла
62
+ file_size: Размер файла
63
+ b: б
64
+ Kb: Кб
65
+ Mb: Мб
66
+ Gb: Гб
58
67
  view_file:
59
68
  raw: Текст
60
69
  title: 'Файл %1 на %2'
@@ -33,6 +33,7 @@ class RunitMan < Sinatra::Base
33
33
  end
34
34
 
35
35
  before do
36
+ @scripts = []
36
37
  base_content_type = CONTENT_TYPES.keys.detect do |t|
37
38
  request.env['REQUEST_URI'] =~ /\.#{Regexp.escape(t.to_s)}$/
38
39
  end || :html
@@ -70,11 +71,29 @@ class RunitMan < Sinatra::Base
70
71
  get %r[^/([^/]+)/log(?:/(\d+))?/?$] do |name, count|
71
72
  data = log_of_service(name, count)
72
73
  return not_found if data.nil?
73
- @scripts = []
74
74
  @title = t.runit.services.log.title(h(name), h(host_name), h(count), h(data[:log_location]))
75
75
  erubis :log, :locals => data
76
76
  end
77
77
 
78
+ get %r[^/([^/]+)/log\-downloads/?$] do |name|
79
+ srv = ServiceInfo[name]
80
+ return not_found if srv.nil? || !srv.logged?
81
+ erubis :log_downloads, :locals => {
82
+ :name => name,
83
+ :files => srv.log_files
84
+ }
85
+ end
86
+
87
+ get %r[^/([^/]+)/log\-download/(.+)$] do |name, file_name|
88
+ srv = ServiceInfo[name]
89
+ return not_found if srv.nil? || !srv.logged?
90
+ f = srv.log_files.detect { |f| f[:name] == file_name }
91
+ return not_found unless f
92
+ send_file(srv.log_file_path(file_name), :type => 'text/plain', :disposition => 'attachment', :filename => "#{name}-#{file_name}.txt", :last_modified => f[:modified].httpdate)
93
+ end
94
+
95
+
96
+
78
97
  get %r[^/([^/]+)/log(?:/(\d+))?\.txt$] do |name, count|
79
98
  data = log_of_service(name, count)
80
99
  return not_found if data.nil?
@@ -98,7 +117,6 @@ class RunitMan < Sinatra::Base
98
117
  if data.nil?
99
118
  return not_found
100
119
  end
101
- @scripts = []
102
120
  @title = t.runit.view_file.title(h(data[:name]), h(host_name))
103
121
  content_type CONTENT_TYPES[:html], :charset => 'utf-8'
104
122
  erubis :view_file, :locals => data
@@ -68,11 +68,37 @@ module Helpers
68
68
  "<a#{hint}#{blank} href=\"/#{h(name)}/log#{ (count != 100) ? "/#{count}" : '' }#{ raw ? '.txt' : '' }#footer\">#{h(title)}</a>"
69
69
  end
70
70
 
71
+ def log_downloads_link(name)
72
+ "<a target=\"_blank\" href=\"/#{h(name)}/log-downloads\/\">#{h(t.runit.services.log.downloads)}&hellip;</a>"
73
+ end
74
+
71
75
  def even_or_odd
72
76
  self.even_or_odd_state = !even_or_odd_state
73
77
  even_or_odd_state
74
78
  end
75
79
 
80
+ KILOBYTE = 1024
81
+ MEGABYTE = 1024 * KILOBYTE
82
+ GIGABYTE = 1024 * MEGABYTE
83
+
84
+ def human_bytes(bytes)
85
+ sign = (bytes >= 0) ? '' : '-'
86
+ suffix = 'b'
87
+ bytes = bytes.abs.to_f
88
+ if bytes > GIGABYTE
89
+ bytes /= GIGABYTE
90
+ suffix = 'Gb'
91
+ elsif bytes > MEGABYTE
92
+ bytes /= MEGABYTE
93
+ suffix = 'Mb'
94
+ elsif bytes > KILOBYTE
95
+ bytes /= KILOBYTE
96
+ suffix = 'Kb'
97
+ end
98
+ bytes = ((bytes * 100 + 0.5).to_i.to_f / 100)
99
+ "#{sign}#{bytes}#{t.runit.services.log[suffix]}"
100
+ end
101
+
76
102
  def stat_subst(s)
77
103
  s.split(/\s/).map do |s|
78
104
  if s =~ /(\w+)/ && t.runit.services.table.subst[$1].translated?
@@ -2,6 +2,8 @@ require 'runit-man/log_location_cache'
2
2
  require 'runit-man/service_status'
3
3
 
4
4
  class ServiceInfo
5
+ SPECIAL_LOG_FILES = %w(lock config).freeze
6
+
5
7
  attr_reader :name
6
8
 
7
9
  def initialize(a_name)
@@ -99,6 +101,30 @@ class ServiceInfo
99
101
  File.expand_path(rel_path, log_run_folder)
100
102
  end
101
103
 
104
+ def log_file_path(file_name)
105
+ dir_name = File.dirname(log_file_location)
106
+ File.expand_path(file_name, dir_name)
107
+ end
108
+
109
+ def log_files
110
+ r = []
111
+ dir_name = File.dirname(log_file_location)
112
+ Dir.foreach(dir_name) do |name|
113
+ next if ServiceInfo.itself_or_parent?(name)
114
+ next if SPECIAL_LOG_FILES.include?(name)
115
+ full_name = File.expand_path(name, dir_name)
116
+ r << {
117
+ :name => name,
118
+ :size => File.size(full_name),
119
+ :modified => File.mtime(full_name)
120
+ }
121
+ end
122
+ if r.length >= 2
123
+ r.sort! { |a, b| a[:modified] <=> b[:modified] }
124
+ end
125
+ r
126
+ end
127
+
102
128
  def send_signal(signal)
103
129
  return unless supervise?
104
130
  File.open(File.join(supervise_folder, 'control'), 'w') do |f|
@@ -28,6 +28,7 @@ need_second_row = !service_info.files_to_view.empty? || !service_info.urls_to_vi
28
28
  <td>
29
29
  <% if service_info.logged? %>
30
30
  <%= log_link(service_info.name, :hint => t.runit.services.table.values.log_hint(service_info.name), :blank => true, :title => service_info.log_file_location) %>
31
+ <%= log_downloads_link(service_info.name) %>
31
32
  <% else %>
32
33
  <%= t.runit.services.table.values.log_absent %>
33
34
  <% end %>
@@ -19,11 +19,13 @@
19
19
  <%= yield_content :content %>
20
20
  </div>
21
21
 
22
+ <% if content_for?(:footer) %>
22
23
  <div id="footer">
23
24
  <div class="content">
24
25
  <%= yield_content :footer %>
25
26
  </div>
26
27
  </div>
28
+ <% end %>
27
29
 
28
30
  </div>
29
31
  <% @scripts.each do |name| %>
@@ -2,7 +2,9 @@
2
2
  <%= t.runit.services.log.header(h(name), h(host_name), h(count), h(log_location)) %> | <%= log_link(name, :count => count, :title => t.runit.services.log.raw, :raw => true) %>
3
3
 
4
4
  <p>
5
- <%= t.runit.services.log.counts([100, 250, 500, 1000, 5000].map { |n| log_link(name, :count => n, :title => n) }.join(' ')) %>
5
+ <%= t.runit.services.log.counts([100, 250, 500, 1000, 5000].map { |n| log_link(name, :count => n, :title => n) }.join(' ')) %>
6
+ <%= log_downloads_link(name) %>
7
+
6
8
  </p>
7
9
  <pre><%= h(text) %></pre>
8
10
  <% end %>
@@ -0,0 +1,24 @@
1
+ <% content_for :content do %>
2
+ <h2><%= h(name) %></h2>
3
+ <h3><%= h(t.runit.services.log.downloads) %></h3>
4
+ <table>
5
+ <caption><%= h(name + ': ' + t.runit.services.log.downloads) %></caption>
6
+ <thead>
7
+ <tr>
8
+ <th><%= h(t.runit.services.log.modified) %></th>
9
+ <th><%= h(t.runit.services.log.file_name) %></th>
10
+ <th><%= h(t.runit.services.log.file_size) %></th>
11
+ <th></th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+ <% files.each do |f| %>
16
+ <tr class="<%= even_or_odd ? 'even' : 'odd' %>">
17
+ <td title="<%= h(l(f[:modified], :full)) %>"><%= h(l(f[:modified], :human)) %></td>
18
+ <td><%= h(f[:name]) %></td>
19
+ <td title="<%= h(f[:size]) %>"><%= h(human_bytes(f[:size])) %></td>
20
+ <td><a href="/<%= h(name) %>/log-download/<%= h(f[:name]) %>"><%= h(t.runit.services.log.download) %>&hellip;</a></td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ <% end %>
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runit-man
3
3
  version: !ruby/object:Gem::Version
4
- hash: 35
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 9
9
- - 8
10
- version: 1.9.8
7
+ - 10
8
+ - 0
9
+ version: 1.10.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Akzhan Abdulin
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-02-01 00:00:00 +03:00
17
+ date: 2011-02-07 00:00:00 +03:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 13
58
54
  segments:
59
55
  - 1
60
56
  - 1
@@ -69,10 +65,11 @@ dependencies:
69
65
  requirements:
70
66
  - - ">="
71
67
  - !ruby/object:Gem::Version
72
- hash: 3
73
68
  segments:
74
69
  - 0
75
- version: "0"
70
+ - 2
71
+ - 4
72
+ version: 0.2.4
76
73
  type: :runtime
77
74
  version_requirements: *id004
78
75
  - !ruby/object:Gem::Dependency
@@ -83,7 +80,6 @@ dependencies:
83
80
  requirements:
84
81
  - - ">="
85
82
  - !ruby/object:Gem::Version
86
- hash: 11
87
83
  segments:
88
84
  - 0
89
85
  - 4
@@ -99,7 +95,6 @@ dependencies:
99
95
  requirements:
100
96
  - - ">="
101
97
  - !ruby/object:Gem::Version
102
- hash: 3
103
98
  segments:
104
99
  - 0
105
100
  version: "0"
@@ -113,7 +108,6 @@ dependencies:
113
108
  requirements:
114
109
  - - ">="
115
110
  - !ruby/object:Gem::Version
116
- hash: 3
117
111
  segments:
118
112
  - 0
119
113
  version: "0"
@@ -127,7 +121,6 @@ dependencies:
127
121
  requirements:
128
122
  - - ">="
129
123
  - !ruby/object:Gem::Version
130
- hash: 3
131
124
  segments:
132
125
  - 0
133
126
  version: "0"
@@ -141,7 +134,6 @@ dependencies:
141
134
  requirements:
142
135
  - - ">="
143
136
  - !ruby/object:Gem::Version
144
- hash: 3
145
137
  segments:
146
138
  - 0
147
139
  version: "0"
@@ -184,6 +176,7 @@ files:
184
176
  - views/index.erubis
185
177
  - views/layout.erubis
186
178
  - views/log.erubis
179
+ - views/log_downloads.erubis
187
180
  - views/view_file.erubis
188
181
  - i18n/en.yml
189
182
  - i18n/ru.yml
@@ -203,7 +196,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
196
  requirements:
204
197
  - - ">="
205
198
  - !ruby/object:Gem::Version
206
- hash: 3
207
199
  segments:
208
200
  - 0
209
201
  version: "0"
@@ -212,7 +204,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
204
  requirements:
213
205
  - - ">="
214
206
  - !ruby/object:Gem::Version
215
- hash: 3
216
207
  segments:
217
208
  - 0
218
209
  version: "0"