rake-contrib 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/lib/rake/contrib/compositepublisher.rb +21 -0
- data/lib/rake/contrib/ftptools.rb +137 -0
- data/lib/rake/contrib/sshpublisher.rb +60 -0
- data/rake-contrib.gemspec +20 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d1eb893bff9e8fff8aed2290b83149ea1f13160
|
4
|
+
data.tar.gz: 1dd670be75a52ea4205f4594dd5bd8eaa9a6d7bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dfe2609b92eab4cc8ecd67bad6254c3dcbbaee55b6d5682fcf1def762970565c9eb382278fe2da2d1bd91acd2ba52e89d1f861121180a48b34f581368666f20
|
7
|
+
data.tar.gz: fb4bf0620f2268009446c3ec1f1005106b7aed0d29aaaa1acf6f780b533beb7b336d7edbc1e975433c229710bdfd241b06d2f34320f64ae136b6a08b75a32083
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 SHIBATA Hiroshi
|
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,33 @@
|
|
1
|
+
# Rake::Contrib
|
2
|
+
|
3
|
+
Additional libraries for Rake
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rake-contrib'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rake-contrib
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/rake-contrib.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rake
|
2
|
+
|
3
|
+
# Manage several publishers as a single entity.
|
4
|
+
class CompositePublisher
|
5
|
+
def initialize
|
6
|
+
@publishers = []
|
7
|
+
end
|
8
|
+
|
9
|
+
# Add a publisher to the composite.
|
10
|
+
def add(pub)
|
11
|
+
@publishers << pub
|
12
|
+
end
|
13
|
+
|
14
|
+
# Upload all the individual publishers.
|
15
|
+
def upload
|
16
|
+
@publishers.each { |p| p.upload }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# = Tools for FTP uploading.
|
2
|
+
#
|
3
|
+
# This file is still under development and is not released for general
|
4
|
+
# use.
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
require 'net/ftp'
|
8
|
+
require 'rake/file_list'
|
9
|
+
|
10
|
+
module Rake # :nodoc:
|
11
|
+
|
12
|
+
class FtpFile # :nodoc: all
|
13
|
+
attr_reader :name, :size, :owner, :group, :time
|
14
|
+
|
15
|
+
def self.date
|
16
|
+
@date_class ||= Date
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.time
|
20
|
+
@time_class ||= Time
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(path, entry)
|
24
|
+
@path = path
|
25
|
+
@mode, _, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
|
26
|
+
@size = size.to_i
|
27
|
+
@time = determine_time(d1, d2, d3)
|
28
|
+
end
|
29
|
+
|
30
|
+
def path
|
31
|
+
File.join(@path, @name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def directory?
|
35
|
+
@mode[0] == ?d
|
36
|
+
end
|
37
|
+
|
38
|
+
def mode
|
39
|
+
parse_mode(@mode)
|
40
|
+
end
|
41
|
+
|
42
|
+
def symlink?
|
43
|
+
@mode[0] == ?l
|
44
|
+
end
|
45
|
+
|
46
|
+
private # --------------------------------------------------------
|
47
|
+
|
48
|
+
def parse_mode(m)
|
49
|
+
result = 0
|
50
|
+
(1..9).each do |i|
|
51
|
+
result = 2 * result + ((m[i] == ?-) ? 0 : 1)
|
52
|
+
end
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
def determine_time(d1, d2, d3)
|
57
|
+
now = self.class.time.now
|
58
|
+
if /:/ !~ d3
|
59
|
+
result = Time.parse("#{d1} #{d2} #{d3}")
|
60
|
+
else
|
61
|
+
result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
|
62
|
+
result = Time.parse("#{d1} #{d2} #{now.year - 1} #{d3}") if
|
63
|
+
result > now
|
64
|
+
end
|
65
|
+
result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Manage the uploading of files to an FTP account.
|
71
|
+
class FtpUploader # :nodoc:
|
72
|
+
|
73
|
+
# Log uploads to standard output when true.
|
74
|
+
attr_accessor :verbose
|
75
|
+
|
76
|
+
class << FtpUploader
|
77
|
+
# Create an uploader and pass it to the given block as +up+.
|
78
|
+
# When the block is complete, close the uploader.
|
79
|
+
def connect(path, host, account, password)
|
80
|
+
up = self.new(path, host, account, password)
|
81
|
+
begin
|
82
|
+
yield(up)
|
83
|
+
ensure
|
84
|
+
up.close
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Create an FTP uploader targeting the directory +path+ on +host+
|
90
|
+
# using the given account and password. +path+ will be the root
|
91
|
+
# path of the uploader.
|
92
|
+
def initialize(path, host, account, password)
|
93
|
+
@created = Hash.new
|
94
|
+
@path = path
|
95
|
+
@ftp = Net::FTP.new(host, account, password)
|
96
|
+
makedirs(@path)
|
97
|
+
@ftp.chdir(@path)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Create the directory +path+ in the uploader root path.
|
101
|
+
def makedirs(path)
|
102
|
+
route = []
|
103
|
+
File.split(path).each do |dir|
|
104
|
+
route << dir
|
105
|
+
current_dir = File.join(route)
|
106
|
+
if @created[current_dir].nil?
|
107
|
+
@created[current_dir] = true
|
108
|
+
$stderr.puts "Creating Directory #{current_dir}" if @verbose
|
109
|
+
@ftp.mkdir(current_dir) rescue nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Upload all files matching +wildcard+ to the uploader's root
|
115
|
+
# path.
|
116
|
+
def upload_files(wildcard)
|
117
|
+
FileList.glob(wildcard).each do |fn|
|
118
|
+
upload(fn)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Close the uploader.
|
123
|
+
def close
|
124
|
+
@ftp.close
|
125
|
+
end
|
126
|
+
|
127
|
+
private # --------------------------------------------------------
|
128
|
+
|
129
|
+
# Upload a single file to the uploader's root path.
|
130
|
+
def upload(file)
|
131
|
+
$stderr.puts "Uploading #{file}" if @verbose
|
132
|
+
dir = File.dirname(file)
|
133
|
+
makedirs(dir)
|
134
|
+
@ftp.putbinaryfile(file, file) unless File.directory?(file)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rake/dsl_definition'
|
2
|
+
require 'rake/contrib/compositepublisher'
|
3
|
+
|
4
|
+
module Rake
|
5
|
+
# Publish an entire directory to an existing remote directory using
|
6
|
+
# SSH.
|
7
|
+
class SshDirPublisher
|
8
|
+
include Rake::DSL
|
9
|
+
|
10
|
+
# Creates an SSH publisher which will scp all files in +local_dir+ to
|
11
|
+
# +remote_dir+ on +host+
|
12
|
+
|
13
|
+
def initialize(host, remote_dir, local_dir)
|
14
|
+
@host = host
|
15
|
+
@remote_dir = remote_dir
|
16
|
+
@local_dir = local_dir
|
17
|
+
end
|
18
|
+
|
19
|
+
# Uploads the files
|
20
|
+
|
21
|
+
def upload
|
22
|
+
sh "scp", "-rq", "#{@local_dir}/*", "#{@host}:#{@remote_dir}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Publish an entire directory to a fresh remote directory using SSH.
|
27
|
+
class SshFreshDirPublisher < SshDirPublisher
|
28
|
+
|
29
|
+
# Uploads the files after removing the existing remote directory.
|
30
|
+
|
31
|
+
def upload
|
32
|
+
sh "ssh", @host, "rm", "-rf", @remote_dir rescue nil
|
33
|
+
sh "ssh", @host, "mkdir", @remote_dir
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Publish a list of files to an existing remote directory.
|
39
|
+
class SshFilePublisher
|
40
|
+
include Rake::DSL
|
41
|
+
|
42
|
+
# Creates an SSH publisher which will scp all +files+ in +local_dir+ to
|
43
|
+
# +remote_dir+ on +host+.
|
44
|
+
|
45
|
+
def initialize(host, remote_dir, local_dir, *files)
|
46
|
+
@host = host
|
47
|
+
@remote_dir = remote_dir
|
48
|
+
@local_dir = local_dir
|
49
|
+
@files = files
|
50
|
+
end
|
51
|
+
|
52
|
+
# Uploads the files
|
53
|
+
|
54
|
+
def upload
|
55
|
+
@files.each do |fn|
|
56
|
+
sh "scp", "-q", "#{@local_dir}/#{fn}", "#{@host}:#{@remote_dir}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "rake-contrib"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["SHIBATA Hiroshi"]
|
5
|
+
spec.email = ["hsbt@ruby-lang.org"]
|
6
|
+
|
7
|
+
spec.summary = %q{Additional libraries for Rake}
|
8
|
+
spec.description = %q{Additional libraries for Rake}
|
9
|
+
spec.homepage = "https://github.com/ruby/rake-contrib"
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
13
|
+
spec.bindir = "exe"
|
14
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_dependency "rake"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake-contrib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SHIBATA Hiroshi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Additional libraries for Rake
|
42
|
+
email:
|
43
|
+
- hsbt@ruby-lang.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/rake/contrib/compositepublisher.rb
|
56
|
+
- lib/rake/contrib/ftptools.rb
|
57
|
+
- lib/rake/contrib/sshpublisher.rb
|
58
|
+
- rake-contrib.gemspec
|
59
|
+
homepage: https://github.com/ruby/rake-contrib
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.6.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Additional libraries for Rake
|
83
|
+
test_files: []
|