ult 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ult.rb +44 -0
- data/lib/ult/assert.rb +3 -0
- data/lib/ult/copy.rb +6 -0
- data/lib/ult/dir.rb +42 -0
- data/lib/ult/execute.rb +65 -0
- data/lib/ult/file.rb +21 -0
- data/lib/ult/find.rb +3 -0
- data/lib/ult/option.rb +5 -0
- data/lib/ult/path.rb +3 -0
- data/lib/ult/platform.rb +15 -0
- data/lib/ult/remove.rb +6 -0
- data/lib/ult/replica.rb +21 -0
- data/lib/ult/safety.rb +15 -0
- data/lib/ult/version.rb +3 -0
- data/lib/ult/watchdog.rb +8 -0
- data/sample/assert.rb +4 -0
- data/sample/dir.rb +15 -0
- data/sample/execute.rb +24 -0
- data/sample/file.rb +7 -0
- data/sample/find.rb +4 -0
- data/sample/option.rb +13 -0
- data/sample/platform.rb +7 -0
- data/sample/replica.rb +13 -0
- data/sample/safety.rb +12 -0
- data/sample/watchdog.rb +9 -0
- data/ult.gemspec +24 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c08777dc4baf5747a4506a2de04f3e8f576cc951
|
4
|
+
data.tar.gz: 0c61e2d7cdf7544e230c05780ba71c15b197f278
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 054633a1c3519563e41df7096ebba7f071a61a2b548ae6f5940baa223da414b65d10f08ecee6c8fba7cd204721b06657d4c90da8157cb4bf8d4025c3b31e6024
|
7
|
+
data.tar.gz: 9d4fe1e8a393640d2e9a9b4d0b4b7fa686cb58c033321eb0ef8490c0ff3c893b8e217bb31f682664d84663cf63c839ff96f7539d730ade1d75fe31accac9505a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 liveralmask
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Ult
|
2
|
+
|
3
|
+
Ultimate tools that work anywhere.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ult'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ult
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
[Please check here](https://github.com/liveralmask/ult/tree/master/sample)
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/liveralmask/ult.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ult"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ult.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "ult/version"
|
2
|
+
|
3
|
+
module Ult
|
4
|
+
extend self
|
5
|
+
|
6
|
+
require "ult/execute"
|
7
|
+
module_function :execute, :shell
|
8
|
+
|
9
|
+
require "ult/path"
|
10
|
+
module_function :fullpath
|
11
|
+
|
12
|
+
require "ult/option"
|
13
|
+
module_function :option
|
14
|
+
|
15
|
+
require "ult/file"
|
16
|
+
module_function :file?, :filename, :extname, :mkfile, :rmfile
|
17
|
+
|
18
|
+
require "ult/dir"
|
19
|
+
module_function :dir?, :dirname, :direach, :dir, :pwd, :mkdir, :rmdir, :rmkdir
|
20
|
+
|
21
|
+
require "ult/find"
|
22
|
+
module_function :find
|
23
|
+
|
24
|
+
require "ult/platform"
|
25
|
+
module_function :platform, :mac?, :linux?, :windows?
|
26
|
+
|
27
|
+
require "ult/replica"
|
28
|
+
module_function :replica
|
29
|
+
|
30
|
+
require "ult/copy"
|
31
|
+
module_function :copy
|
32
|
+
|
33
|
+
require "ult/remove"
|
34
|
+
module_function :remove
|
35
|
+
|
36
|
+
require "ult/watchdog"
|
37
|
+
module_function :watchdog
|
38
|
+
|
39
|
+
require "ult/assert"
|
40
|
+
module_function :assert
|
41
|
+
|
42
|
+
require "ult/safety"
|
43
|
+
module_function :safety
|
44
|
+
end
|
data/lib/ult/assert.rb
ADDED
data/lib/ult/copy.rb
ADDED
data/lib/ult/dir.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "ult/path"
|
3
|
+
|
4
|
+
def dir?( path )
|
5
|
+
Dir.exist?( path )
|
6
|
+
end
|
7
|
+
|
8
|
+
def dirname( path )
|
9
|
+
File.dirname( path )
|
10
|
+
end
|
11
|
+
|
12
|
+
def direach( path )
|
13
|
+
Dir::foreach( path ){|name|
|
14
|
+
case name
|
15
|
+
when ".", ".."
|
16
|
+
else
|
17
|
+
yield( name, fullpath( name, path ) )
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def dir( path, &block )
|
23
|
+
Dir.chdir( path, &block )
|
24
|
+
end
|
25
|
+
|
26
|
+
def pwd
|
27
|
+
Dir.pwd
|
28
|
+
end
|
29
|
+
|
30
|
+
def mkdir( path, &block )
|
31
|
+
FileUtils.mkdir_p( path ) if ! dir?( path )
|
32
|
+
dir( path, &block )
|
33
|
+
end
|
34
|
+
|
35
|
+
def rmdir( path )
|
36
|
+
FileUtils.rm_rf( path ) if dir?( path )
|
37
|
+
end
|
38
|
+
|
39
|
+
def rmkdir( path )
|
40
|
+
rmdir( path )
|
41
|
+
mkdir( path )
|
42
|
+
end
|
data/lib/ult/execute.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
def execute( command, input = "", &block )
|
2
|
+
status = -1
|
3
|
+
block = lambda{|type, io, msg| io.print msg} if ! block_given?
|
4
|
+
begin
|
5
|
+
i_r, i_w = IO.pipe
|
6
|
+
o_r, o_w = IO.pipe
|
7
|
+
e_r, e_w = IO.pipe
|
8
|
+
|
9
|
+
pid = Process.fork{
|
10
|
+
i_w.close
|
11
|
+
STDIN.reopen( i_r )
|
12
|
+
STDOUT.reopen( o_w )
|
13
|
+
STDERR.reopen( e_w )
|
14
|
+
exec( command )
|
15
|
+
}
|
16
|
+
o_w.close
|
17
|
+
e_w.close
|
18
|
+
i_r.close
|
19
|
+
i_w.write input
|
20
|
+
i_w.close
|
21
|
+
|
22
|
+
# IOブロックによるプロセス停止を防ぐため、スレッドで定期的に読み取る
|
23
|
+
block.call( :cmd, $stdout, "#{command}\n" )
|
24
|
+
out_thread = Thread.start{
|
25
|
+
chars = []
|
26
|
+
o_r.each_char{|c|
|
27
|
+
chars.push c
|
28
|
+
case c
|
29
|
+
when /[\r\n]/
|
30
|
+
block.call( :out, $stdout, chars.join )
|
31
|
+
chars = []
|
32
|
+
end
|
33
|
+
}
|
34
|
+
block.call( :out, $stdout, chars.join ) if ! chars.empty?
|
35
|
+
}
|
36
|
+
err_thread = Thread.start{
|
37
|
+
chars = []
|
38
|
+
e_r.each_char{|c|
|
39
|
+
chars.push c
|
40
|
+
case c
|
41
|
+
when /[\r\n]/
|
42
|
+
block.call( :err, $stderr, chars.join )
|
43
|
+
chars = []
|
44
|
+
end
|
45
|
+
}
|
46
|
+
block.call( :err, $stderr, chars.join ) if ! chars.empty?
|
47
|
+
}
|
48
|
+
|
49
|
+
Process.waitpid( pid )
|
50
|
+
status = $?.exitstatus
|
51
|
+
out_thread.join
|
52
|
+
err_thread.join
|
53
|
+
end
|
54
|
+
status
|
55
|
+
end
|
56
|
+
|
57
|
+
def shell( command, &block )
|
58
|
+
status = execute( command )
|
59
|
+
if block_given?
|
60
|
+
status = block.call( status )
|
61
|
+
else
|
62
|
+
raise "#{command} => #{status}" if 0 != status
|
63
|
+
end
|
64
|
+
status
|
65
|
+
end
|
data/lib/ult/file.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
def file?( path )
|
2
|
+
File.exist?( path )
|
3
|
+
end
|
4
|
+
|
5
|
+
def filename( path )
|
6
|
+
File.basename( path )
|
7
|
+
end
|
8
|
+
|
9
|
+
def extname( path )
|
10
|
+
/^\.?.+?\.(.+)$/ =~ path ? $1 : ""
|
11
|
+
end
|
12
|
+
|
13
|
+
def mkfile( path, mode, &block )
|
14
|
+
open( path, mode ){|file|
|
15
|
+
block.call( file ) if block_given?
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def rmfile( path )
|
20
|
+
File.delete( path ) if file?( path )
|
21
|
+
end
|
data/lib/ult/find.rb
ADDED
data/lib/ult/option.rb
ADDED
data/lib/ult/path.rb
ADDED
data/lib/ult/platform.rb
ADDED
data/lib/ult/remove.rb
ADDED
data/lib/ult/replica.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "ult/dir"
|
2
|
+
require "ult/file"
|
3
|
+
require "ult/copy"
|
4
|
+
require "ult/remove"
|
5
|
+
|
6
|
+
def replica( count, prefix, suffix = "" )
|
7
|
+
src = "#{prefix}#{suffix}"
|
8
|
+
if dir?( src )
|
9
|
+
count.times{|index|
|
10
|
+
dst = "#{prefix}#{index + 1}#{suffix}"
|
11
|
+
remove( dst )
|
12
|
+
copy( src, dst )
|
13
|
+
}
|
14
|
+
elsif file?( src )
|
15
|
+
count.times{|index|
|
16
|
+
dst = "#{prefix}#{index + 1}#{suffix}"
|
17
|
+
remove( dst )
|
18
|
+
copy( src, dst )
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
data/lib/ult/safety.rb
ADDED
data/lib/ult/version.rb
ADDED
data/lib/ult/watchdog.rb
ADDED
data/sample/assert.rb
ADDED
data/sample/dir.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "ult"
|
2
|
+
extend Ult
|
3
|
+
|
4
|
+
puts "__FILE__=#{__FILE__}"
|
5
|
+
puts "dir?=#{dir?( __FILE__ )}"
|
6
|
+
puts "dirname=#{dirname( __FILE__ )}"
|
7
|
+
direach( "." ){|name, path|
|
8
|
+
puts "name=#{name} path=#{path}"
|
9
|
+
}
|
10
|
+
dir( "/" ){
|
11
|
+
puts "pwd=#{pwd}"
|
12
|
+
}
|
13
|
+
puts "#{pwd}"
|
14
|
+
dir( "/" )
|
15
|
+
puts "#{pwd}"
|
data/sample/execute.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "ult"
|
2
|
+
extend Ult
|
3
|
+
|
4
|
+
args = ARGV.empty? ? [ "date" ] : ARGV
|
5
|
+
puts "----- execute start [#{args.join( ' ' )}] -----"
|
6
|
+
status = execute( *args )
|
7
|
+
puts "\n----- execute end [#{args.join( ' ' )}] status=#{status} -----"
|
8
|
+
|
9
|
+
puts "----- execute start [#{args.join( ' ' )}] -----"
|
10
|
+
execute( *args ){|type, io, msg|
|
11
|
+
p [ type, io, msg ]
|
12
|
+
}
|
13
|
+
puts "----- execute end [#{args.join( ' ' )}] -----"
|
14
|
+
|
15
|
+
puts "----- shell start [#{args.join( ' ' )}] -----"
|
16
|
+
status = shell( *args ){|status|
|
17
|
+
puts "\nshell status=#{status}"
|
18
|
+
"success"
|
19
|
+
}
|
20
|
+
puts "----- shell end [#{args.join( ' ' )}] status=#{status} -----"
|
21
|
+
|
22
|
+
puts "----- shell start [#{args.join( ' ' )}] -----"
|
23
|
+
shell( *args )
|
24
|
+
puts "\n----- shell end [#{args.join( ' ' )}] -----"
|
data/sample/file.rb
ADDED
data/sample/find.rb
ADDED
data/sample/option.rb
ADDED
data/sample/platform.rb
ADDED
data/sample/replica.rb
ADDED
data/sample/safety.rb
ADDED
data/sample/watchdog.rb
ADDED
data/ult.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ult/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ult"
|
8
|
+
spec.version = Ult::VERSION
|
9
|
+
spec.licenses = [ "MIT" ]
|
10
|
+
spec.authors = ["liveralmask"]
|
11
|
+
spec.email = ["liveralmask.lisk@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Ultimate tools that work anywhere.}
|
14
|
+
spec.description = %q{Ultimate tools that work anywhere.}
|
15
|
+
spec.homepage = "https://github.com/liveralmask/ult"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ult
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- liveralmask
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Ultimate tools that work anywhere.
|
42
|
+
email:
|
43
|
+
- liveralmask.lisk@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/ult.rb
|
56
|
+
- lib/ult/assert.rb
|
57
|
+
- lib/ult/copy.rb
|
58
|
+
- lib/ult/dir.rb
|
59
|
+
- lib/ult/execute.rb
|
60
|
+
- lib/ult/file.rb
|
61
|
+
- lib/ult/find.rb
|
62
|
+
- lib/ult/option.rb
|
63
|
+
- lib/ult/path.rb
|
64
|
+
- lib/ult/platform.rb
|
65
|
+
- lib/ult/remove.rb
|
66
|
+
- lib/ult/replica.rb
|
67
|
+
- lib/ult/safety.rb
|
68
|
+
- lib/ult/version.rb
|
69
|
+
- lib/ult/watchdog.rb
|
70
|
+
- sample/assert.rb
|
71
|
+
- sample/dir.rb
|
72
|
+
- sample/execute.rb
|
73
|
+
- sample/file.rb
|
74
|
+
- sample/find.rb
|
75
|
+
- sample/option.rb
|
76
|
+
- sample/platform.rb
|
77
|
+
- sample/replica.rb
|
78
|
+
- sample/safety.rb
|
79
|
+
- sample/watchdog.rb
|
80
|
+
- ult.gemspec
|
81
|
+
homepage: https://github.com/liveralmask/ult
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.5.2.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Ultimate tools that work anywhere.
|
105
|
+
test_files: []
|