em-file-utils 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +20 -0
- data/README.md +52 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/lib/em-file-utils.rb +105 -0
- data/test +35 -0
- data/test-em +26 -0
- metadata +121 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
|
5
|
+
gem "hash-utils", ">= 0.8.0"
|
6
|
+
gem "command-builder", ">= 0.2.0"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "bundler", ">= 1.0.0"
|
12
|
+
gem "jeweler", ">= 1.5.2"
|
13
|
+
gem "riot", ">= 0.12.3"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
command-builder (0.2.0)
|
5
|
+
hash-utils (>= 0.18.0)
|
6
|
+
pipe-run (>= 0.2.1)
|
7
|
+
git (1.2.5)
|
8
|
+
hash-utils (0.18.0)
|
9
|
+
jeweler (1.6.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
pipe-run (0.2.1)
|
14
|
+
rake (0.9.2)
|
15
|
+
riot (0.12.4)
|
16
|
+
rr
|
17
|
+
rr (1.0.3)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler (>= 1.0.0)
|
24
|
+
command-builder (>= 0.2.0)
|
25
|
+
hash-utils (>= 0.8.0)
|
26
|
+
jeweler (>= 1.5.2)
|
27
|
+
riot (>= 0.12.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
EventMachine FileUtils
|
2
|
+
======================
|
3
|
+
|
4
|
+
**em-file-utils** allows base file operations using UNIX commands such
|
5
|
+
as standard library [FileUtils][1], but returns [CommandBuilder][2]
|
6
|
+
objects which allows wide customizations to final call and asynchronous
|
7
|
+
evented [EventMachine][3] interface support (although it isn't required).
|
8
|
+
[UNIX][4]/[GNU][5] based systems only are supported.
|
9
|
+
|
10
|
+
Some example:
|
11
|
+
|
12
|
+
# synchronous
|
13
|
+
require "em-file-utils"
|
14
|
+
output = EM::FileUtils::touch("./~test1").execute!
|
15
|
+
|
16
|
+
# asynchronous
|
17
|
+
EM::run # eventmachine
|
18
|
+
EM::FileUtils::touch("./~test1").execute do |output|
|
19
|
+
# ...
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
It returns [CommandBuilder][2] object which allows it to be flexible:
|
24
|
+
|
25
|
+
cmd = EM::FileUtils::touch("./~test1")
|
26
|
+
cmd.params.unshift(:a) # change access time only
|
27
|
+
cmd.execute!
|
28
|
+
|
29
|
+
Contributing
|
30
|
+
------------
|
31
|
+
|
32
|
+
1. Fork it.
|
33
|
+
2. Create a branch (`git checkout -b 20101220-my-change`).
|
34
|
+
3. Commit your changes (`git commit -am "Added something"`).
|
35
|
+
4. Push to the branch (`git push origin 20101220-my-change`).
|
36
|
+
5. Create an [Issue][9] with a link to your branch.
|
37
|
+
6. Enjoy a refreshing Diet Coke and wait.
|
38
|
+
|
39
|
+
|
40
|
+
Copyright
|
41
|
+
---------
|
42
|
+
|
43
|
+
Copyright © 2011 [Martin Kozák][10]. See `LICENSE.txt` for
|
44
|
+
further details.
|
45
|
+
|
46
|
+
[1]: http://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/classes/FileUtils.html
|
47
|
+
[2]: http://github.com/martinkozak/command-builder
|
48
|
+
[3]: http://rubyeventmachine.com/
|
49
|
+
[4]: http://en.wikipedia.org/wiki/Unix
|
50
|
+
[5]: http://en.wikipedia.org/wiki/GNU
|
51
|
+
[9]: http://github.com/martinkozak/em-file-utils/issues
|
52
|
+
[10]: http://www.martinkozak.net/
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rake'
|
14
|
+
require 'jeweler'
|
15
|
+
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "em-file-utils"
|
19
|
+
gem.homepage = "http://github.com/martinkozak/em-file-utils"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = "Allows base file operations using UNIX commands such as standard library FileUtils, but returns CommandBuilder objects which allows wide customizations to final call and asynchronous evented EventMachine interface support (although it isn't required). UNIX/Linux based systems only supported."
|
22
|
+
gem.email = "martinkozak@martinkozak.net"
|
23
|
+
gem.authors = ["Martin Kozák"]
|
24
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
26
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "command-builder"
|
5
|
+
require "hash-utils/object" # >= 0.8.0
|
6
|
+
|
7
|
+
|
8
|
+
##
|
9
|
+
# Main EventMachine module.
|
10
|
+
# @see http://rubyeventmachine.com/
|
11
|
+
#
|
12
|
+
|
13
|
+
module EM
|
14
|
+
|
15
|
+
##
|
16
|
+
# Evented FileUtils.
|
17
|
+
#
|
18
|
+
|
19
|
+
module FileUtils
|
20
|
+
|
21
|
+
##
|
22
|
+
# Commands instances cache.
|
23
|
+
#
|
24
|
+
|
25
|
+
@@cache = { }
|
26
|
+
|
27
|
+
##
|
28
|
+
# Copy object using +cp -r+ command.
|
29
|
+
#
|
30
|
+
# @param [String] from source path
|
31
|
+
# @param [String] to target path
|
32
|
+
# @return [CommandBuilder] returns the command builder object
|
33
|
+
#
|
34
|
+
|
35
|
+
def self.cp(from, to)
|
36
|
+
cmd = __get(:cp)
|
37
|
+
cmd << :r
|
38
|
+
cmd << from
|
39
|
+
cmd << to
|
40
|
+
cmd
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Renames object using +mv+ command.
|
45
|
+
#
|
46
|
+
# @param [String] from source path
|
47
|
+
# @param [String] to target path
|
48
|
+
# @return [CommandBuilder] returns the command builder object
|
49
|
+
#
|
50
|
+
|
51
|
+
def self.mv(from, to)
|
52
|
+
cmd = __get(:mv)
|
53
|
+
cmd << from
|
54
|
+
cmd << to
|
55
|
+
cmd
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Removes object using +rm -r+ command.
|
60
|
+
#
|
61
|
+
# @param [String] path path to file
|
62
|
+
# @return [CommandBuilder] returns the command builder object
|
63
|
+
#
|
64
|
+
|
65
|
+
def self.rm(path)
|
66
|
+
cmd = __get(:rm)
|
67
|
+
cmd << :r
|
68
|
+
cmd << path
|
69
|
+
cmd
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Touches file using +touch+ command.
|
74
|
+
#
|
75
|
+
# @param [String] path to the file
|
76
|
+
# @return [CommandBuilder] returns the command builder object
|
77
|
+
#
|
78
|
+
|
79
|
+
def self.touch(path)
|
80
|
+
cmd = __get(:touch)
|
81
|
+
cmd << path
|
82
|
+
cmd
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
##
|
89
|
+
# Returns instance of command builder from cache.
|
90
|
+
#
|
91
|
+
|
92
|
+
def self.__get(command)
|
93
|
+
command = command.to_sym
|
94
|
+
|
95
|
+
if command.in? @@cache
|
96
|
+
command = @@cache[command]
|
97
|
+
command.reset! # returns
|
98
|
+
else
|
99
|
+
@@cache[command] = CommandBuilder::new(command)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
data/test
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
$:.unshift("./lib")
|
7
|
+
|
8
|
+
require "em-file-utils"
|
9
|
+
require "riot"
|
10
|
+
|
11
|
+
## FILE
|
12
|
+
|
13
|
+
context "EM::FileUtils" do
|
14
|
+
asserts("#touch") do
|
15
|
+
EM::FileUtils::touch("./~test1").execute!
|
16
|
+
File.exists? "./~test1"
|
17
|
+
end
|
18
|
+
asserts("#cp") do
|
19
|
+
EM::FileUtils::cp("./~test1", "./~test2").execute!
|
20
|
+
File.exists? "./~test2"
|
21
|
+
end
|
22
|
+
asserts("#mv") do
|
23
|
+
EM::FileUtils::mv("./~test2", "./~test3").execute!
|
24
|
+
File.exists? "./~test3"
|
25
|
+
end
|
26
|
+
asserts("#rm") do
|
27
|
+
EM::FileUtils::rm("./~test3").execute!
|
28
|
+
not File.exists? "./~test3"
|
29
|
+
end
|
30
|
+
|
31
|
+
teardown do
|
32
|
+
File.unlink("./~test1")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/test-em
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
$:.unshift("./lib")
|
7
|
+
|
8
|
+
require "eventmachine"
|
9
|
+
require "em-file-utils"
|
10
|
+
|
11
|
+
## FILE
|
12
|
+
|
13
|
+
EM::run do
|
14
|
+
EM::FileUtils::touch("./~test1").execute do
|
15
|
+
EM::FileUtils::cp("./~test1", "./~test2").execute do
|
16
|
+
EM::FileUtils::mv("./~test2", "./~test3").execute do
|
17
|
+
EM::FileUtils::rm("./~test1").execute do
|
18
|
+
puts (not File.exists? "./~test1" and File.exists? "./~test3")
|
19
|
+
|
20
|
+
File.unlink("./~test3")
|
21
|
+
EM::stop
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-file-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Martin Koz\xC3\xA1k"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-30 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hash-utils
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.8.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: command-builder
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.5.2
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: riot
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.12.3
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
description:
|
71
|
+
email: martinkozak@martinkozak.net
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
files:
|
80
|
+
- .document
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- lib/em-file-utils.rb
|
88
|
+
- test
|
89
|
+
- test-em
|
90
|
+
homepage: http://github.com/martinkozak/em-file-utils
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 2894996730163653254
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
requirements: []
|
114
|
+
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Allows base file operations using UNIX commands such as standard library FileUtils, but returns CommandBuilder objects which allows wide customizations to final call and asynchronous evented EventMachine interface support (although it isn't required). UNIX/Linux based systems only supported.
|
120
|
+
test_files: []
|
121
|
+
|