sumire 24.03.30
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.
- checksums.yaml +7 -0
- data/.rubocop.yml +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/exe/sumire +95 -0
- data/lib/sumire/version.rb +5 -0
- data/lib/sumire.rb +85 -0
- data/sig/sumire.rbs +4 -0
- metadata +96 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c16de0e198ae8999524f348b21c2795b12fbaadb35d889b4396e8ac7b3741ee9
|
|
4
|
+
data.tar.gz: fac8e873d7eca4cbbbcb79533befddd719f34708b43ecce6390f28498b361764
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e324b6edcef778c876ab4e9575bdca84828cac1fdd8a5c71aebf00cada46b00eca81f4f659430f8d732eda1e1d604da8a0a0bcdbc803daedb6ce309c9da9bacc
|
|
7
|
+
data.tar.gz: 8fff912fd5b8f2f9bc30533de3db975d4488eadb48b3b27f07af12135a49854df125b272e6b06ff6012982d5b3d1aee157038d496b39ec27fb314d571e08ade2
|
data/.rubocop.yml
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 MURATA Mitsuharu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Sumire
|
|
2
|
+
|
|
3
|
+
The sumire monitors the results of the `script` command and adds the recorded time.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install sumire
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
sumire
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
When specifying a directory
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
sumire -d /home/user
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Himeyama/sumire.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/sumire
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "sumire"
|
|
5
|
+
require "listen"
|
|
6
|
+
require "optparse"
|
|
7
|
+
require "sys/proctable"
|
|
8
|
+
|
|
9
|
+
@i18n = {
|
|
10
|
+
"en": {
|
|
11
|
+
"arg_less_one": "The number of arguments must be less than or equal to 1",
|
|
12
|
+
"output_log": "Output logs to standard output",
|
|
13
|
+
"save_log": "Save the log to a file",
|
|
14
|
+
"exist_process": "The `script` process exists\nExecute the following command to stop the process",
|
|
15
|
+
"option_not_appropriate": "Option is not appropriate",
|
|
16
|
+
"start_recording": "\e[31;1m● Start recording\e[0m",
|
|
17
|
+
"EOR": "\e[31;1m■ End of record\e[0m",
|
|
18
|
+
"specify_dir": "Specify the directory",
|
|
19
|
+
"no_directory": "\e[31mDirectory does not exist\e[0m",
|
|
20
|
+
"save_to": "Save to: "
|
|
21
|
+
},
|
|
22
|
+
"ja": {
|
|
23
|
+
"arg_less_one": "引数の個数は 1 個以下でなければなりません",
|
|
24
|
+
"output_log": "標準出力に表示します",
|
|
25
|
+
"save_log": "ログファイルに記録します",
|
|
26
|
+
"exist_process": "`script` プロセスが存在しています\n以下のコマンドを実行してプロセスを停止してください。",
|
|
27
|
+
"option_not_appropriate": "オプションが適切ではありません\n次のコマンドを実行し使い方を確認して下さい\n\e[32m#{File.basename($PROGRAM_NAME)} -h\e[0m",
|
|
28
|
+
"start_recording": "\e[31;1m● 記録を開始します\e[0m",
|
|
29
|
+
"EOR": "\e[31;1m■ 記録を終了します\e[0m",
|
|
30
|
+
"specify_dir": "ディレクトリを指定します",
|
|
31
|
+
"no_directory": "\e[31mディレクトリが存在しません\e[0m",
|
|
32
|
+
"save_to": "保存先: "
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
def comment(tag)
|
|
37
|
+
lang = :en
|
|
38
|
+
lang = :ja if ENV["LANG"].downcase.include?("ja")
|
|
39
|
+
@i18n[lang][tag]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def main(**kwargs) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
43
|
+
dir = kwargs[:directory]
|
|
44
|
+
dir = "." if dir.nil? || dir.empty?
|
|
45
|
+
dir = dir.sub(%r{/\z}, "")
|
|
46
|
+
|
|
47
|
+
processes = Sys::ProcTable.ps
|
|
48
|
+
processes.each do |process|
|
|
49
|
+
next unless process.cmdline.match(/^script/)
|
|
50
|
+
|
|
51
|
+
warn("#{comment(:exist_process)}\n\n")
|
|
52
|
+
warn("\e[32mkill #{process.pid}\e[0m")
|
|
53
|
+
exit(false)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
print(comment(:save_to))
|
|
57
|
+
puts("#{dir}/#{Time.now.strftime("%Y%m%d_%H%M%S")}.log")
|
|
58
|
+
puts(comment(:start_recording))
|
|
59
|
+
system("sumire -m #{dir}& script -f")
|
|
60
|
+
puts(comment(:EOR))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
opt = OptionParser.new
|
|
64
|
+
|
|
65
|
+
opt.on("-v", "--verbose", comment(:output_log)) do |_v|
|
|
66
|
+
Sumire::Sumire.exec(verbose: true)
|
|
67
|
+
exit(true)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
opt.on("-m [Directory]", "--monitor", comment(:save_log)) do |dir|
|
|
71
|
+
Sumire::Sumire.exec(directory: dir)
|
|
72
|
+
exit(true)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
opt.on("-d [Directory]", "--directory [Directory]", comment(:specify_dir)) do |dir|
|
|
76
|
+
if dir.nil?
|
|
77
|
+
dir = ""
|
|
78
|
+
elsif !Dir.exist?(dir)
|
|
79
|
+
warn(comment(:no_directory))
|
|
80
|
+
exit(false)
|
|
81
|
+
end
|
|
82
|
+
main(directory: dir)
|
|
83
|
+
exit(true)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
opt.on("") do |_v|
|
|
87
|
+
main
|
|
88
|
+
exit(true)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
begin
|
|
92
|
+
opt.parse!(ARGV)
|
|
93
|
+
rescue OptionParser::InvalidOption
|
|
94
|
+
warn(comment(:option_not_appropriate))
|
|
95
|
+
end
|
data/lib/sumire.rb
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "sumire/version"
|
|
4
|
+
require "ansi2txt"
|
|
5
|
+
|
|
6
|
+
module Sumire
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
class Sumire # rubocop:disable Style/Documentation
|
|
10
|
+
class << self
|
|
11
|
+
attr_accessor :directory
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity, Lint/MissingCopEnableDirective
|
|
15
|
+
def self.exec(**kwargs)
|
|
16
|
+
directory = kwargs[:directory]
|
|
17
|
+
directory = "." if directory.nil?
|
|
18
|
+
target = kwargs[:target]
|
|
19
|
+
target = "typescript" if target.nil?
|
|
20
|
+
verbose = kwargs[:verbose] || false
|
|
21
|
+
old_lines = 0
|
|
22
|
+
list = []
|
|
23
|
+
old_text = ""
|
|
24
|
+
start_time = Time.now.strftime("%Y%m%d_%H%M%S")
|
|
25
|
+
|
|
26
|
+
# rubocop:disable Metrics/BlockLength
|
|
27
|
+
listener = Listen.to(".") do |modified, _added, _removed|
|
|
28
|
+
if modified.map { |file| File.basename(file) }.include?(target)
|
|
29
|
+
input = File.open(target)
|
|
30
|
+
|
|
31
|
+
# txt: string
|
|
32
|
+
txt = Ansi2txt::ANSI2TXT.from_io(input)
|
|
33
|
+
|
|
34
|
+
# Add target text
|
|
35
|
+
add_line_txt = txt[old_text.size...-1]
|
|
36
|
+
|
|
37
|
+
regex = /Script\sdone\son\s\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\s\[COMMAND_EXIT_CODE="\d+"\]/
|
|
38
|
+
exit if !add_line_txt.nil? && add_line_txt.match(regex)
|
|
39
|
+
next if add_line_txt.nil?
|
|
40
|
+
|
|
41
|
+
add_line = add_line_txt.gsub("\n\r", "\n").lines.map(&:chomp).map do |line|
|
|
42
|
+
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
43
|
+
"[#{time}] #{line}"
|
|
44
|
+
end
|
|
45
|
+
add_line_color = add_line_txt.gsub("\n\r", "\n").lines.map(&:chomp).map do |line|
|
|
46
|
+
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
47
|
+
"\e[32m[#{time}]\e[0m #{line}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
input.seek(0)
|
|
51
|
+
new_lines = input.read.lines.count
|
|
52
|
+
|
|
53
|
+
# Add new line
|
|
54
|
+
if old_lines < new_lines
|
|
55
|
+
add_line.each do |line|
|
|
56
|
+
list.append(line)
|
|
57
|
+
File.open("#{directory}/#{start_time}.log", "a") do |f|
|
|
58
|
+
f.puts(line)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
if verbose
|
|
63
|
+
add_line_color.each do |line|
|
|
64
|
+
puts(line)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
old_text = txt
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
old_lines = new_lines
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
listener.start
|
|
75
|
+
|
|
76
|
+
begin
|
|
77
|
+
sleep
|
|
78
|
+
rescue Interrupt
|
|
79
|
+
nil
|
|
80
|
+
rescue NoMethodError
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/sig/sumire.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sumire
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 24.03.30
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- MURATA Mitsuharu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-03-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: ansi2txt
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 24.03.29
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 24.03.29
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: listen
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 3.9.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 3.9.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: sys-proctable
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.3'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.3'
|
|
55
|
+
description: Monitor the `script` command and add the recorded time.
|
|
56
|
+
email:
|
|
57
|
+
- hikari.photon+dev@gmail.com
|
|
58
|
+
executables:
|
|
59
|
+
- sumire
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".rubocop.yml"
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- exe/sumire
|
|
68
|
+
- lib/sumire.rb
|
|
69
|
+
- lib/sumire/version.rb
|
|
70
|
+
- sig/sumire.rbs
|
|
71
|
+
homepage: https://github.com/Himeyama/sumire
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata:
|
|
75
|
+
homepage_uri: https://github.com/Himeyama/sumire
|
|
76
|
+
source_code_uri: https://github.com/Himeyama/sumire
|
|
77
|
+
post_install_message:
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: 2.6.0
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
requirements: []
|
|
92
|
+
rubygems_version: 3.5.3
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 4
|
|
95
|
+
summary: Monitor the `script` command and add the recorded time.
|
|
96
|
+
test_files: []
|