photocopier 0.0.10 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9653d2b9d9c48cead649c2a9ce05db2b9620ed2f
4
- data.tar.gz: 3bed95de37b30e22b05bd67eea32bb4d39032930
3
+ metadata.gz: 3ba20dc26aeefaef97481f03d7195f203b74800c
4
+ data.tar.gz: 02e7e5bb7a24ad4052a39c75cb8d86f2e6125374
5
5
  SHA512:
6
- metadata.gz: f3e37d9509d326bf57b4ec75d62a9e2ca918ae6218c0d8634f9dec892aca1e69e0464df7037f942e50eb35a3d7d18581162191a746618fde47af17a64fc20ee0
7
- data.tar.gz: 54526e7532807c40184236d575338c03fa4b691910bc691d8285b319646f8128a76be3d0b24d2713beb58103b7d7785dfe8f03410937fb5dd8486fe5fca6b953
6
+ metadata.gz: d568ac3259e1609af3efa5c0609385ef255a5479ce8d7800a7e068eab727ce1ad02dbabd3e805ac351ed4e2740f783dcdcb874aaa1c96964ecaeb63aea93474a
7
+ data.tar.gz: 9f5b43f82fbed2e7e78d459001a2a84aeb650fd56c494f1a1df2b03b8394955faf9334d4b9903a3530bd730ba57b8afbb8b1591568f43d128df8122690b89529
data/.gitignore CHANGED
@@ -1 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
1
12
  pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec CHANGED
@@ -1 +1,2 @@
1
- --colour
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ photocopier
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p247
1
+ 2.1.2
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 1.9.3
3
+ - 2.1.2
4
+ - 2.2.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # 1.0.0.pre (2015-03-21)
2
+ - semantic versioning
3
+ - use ruby version 2.1.2
4
+ - allow scheme (protocol) for ftp in options
5
+ - fixed ftp password escaping
6
+ - replace `escape` gem with `Shellwords`
7
+ - public interface with less methods
8
+
data/README.md CHANGED
@@ -44,7 +44,7 @@ ssh.put('./local_file.txt', 'remote_file.txt')
44
44
  # deletes a file
45
45
  ssh.delete('remote_file.txt')
46
46
 
47
- # mirros the remote directory into the local machine (needs rsync on the local machine)
47
+ # mirros the remote directory content into the local machine (needs rsync on the local machine)
48
48
  ssh.get_directory('remote_dir', './local_dir')
49
49
 
50
50
  # and viceversa
@@ -57,14 +57,14 @@ The very same commands are valid for the `Photocopier::FTP` adapter.
57
57
 
58
58
  ## FTP
59
59
 
60
- `Photocopier::FTP.new` accepts the following parameters (you need to pass them
61
- all).
60
+ `Photocopier::FTP.new` accepts the following parameters
62
61
 
63
62
  ```ruby
64
63
  {
65
- host: '',
66
- user: '',
67
- password: ''
64
+ host: '', #mandatory
65
+ user: '', #mandatory
66
+ password: '', #mandatory
67
+ scheme: 'ftp' #default, could be any scheme compatibile with your lftp version
68
68
  }
69
69
  ```
70
70
  For performance reasons, the `.get_directory` and `.put_directory` commands make
@@ -107,7 +107,7 @@ On Linux, you can install it with your standard package manager. On Mac, you can
107
107
  have it via [`brew`](https://github.com/mxcl/homebrew):
108
108
 
109
109
  ```
110
- sudo brew install https://raw.github.com/gist/1513663/3e98bf9e03feb7e31eeddcd08f89ca86163a376d/sshpass.rb
110
+ brew install https://raw.github.com/eugeneoden/homebrew/eca9de1/Library/Formula/sshpass.rb
111
111
  ```
112
112
 
113
113
  **Please note that on Ubuntu 11.10 `sshpass` is at version 1.04, which has a
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "photocopier"
5
+ require "pry-byebug"
6
+
7
+ Pry.start
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,8 +1,3 @@
1
- require 'escape'
2
- require 'tempfile'
3
- require 'logger'
4
- require 'active_support/all'
5
-
6
1
  module Photocopier
7
2
 
8
3
  class Adapter
@@ -30,8 +25,7 @@ module Photocopier
30
25
 
31
26
  protected
32
27
 
33
- def run(*args)
34
- command = Escape.shell_command(args)
28
+ def run(command)
35
29
  if logger.present?
36
30
  logger.info command
37
31
  end
@@ -1,7 +1,3 @@
1
- require 'net/ftp'
2
- require 'photocopier/adapter'
3
- require 'fileutils'
4
-
5
1
  module Photocopier
6
2
  class FTP < Adapter
7
3
 
@@ -34,6 +30,8 @@ module Photocopier
34
30
  lftp(local_path, remote_path, true, exclude)
35
31
  end
36
32
 
33
+ private
34
+
37
35
  def session
38
36
  if @session.nil?
39
37
  @session = Net::FTP.open(options[:host], options[:user], options[:password])
@@ -42,26 +40,25 @@ module Photocopier
42
40
  @session
43
41
  end
44
42
 
45
- private
46
-
47
43
  def lftp(local, remote, reverse, exclude)
48
- run "lftp",
49
- "-c",
50
- [
51
- "set ftp:list-options -a",
52
- "open #{remote_ftp_url}",
53
- "mkdir -p #{remote}",
54
- "cd #{remote}",
55
- "lcd #{local}",
56
- lftp_mirror_arguments(reverse, exclude)
57
- ].join("; ")
44
+ command = [
45
+ "set ftp:list-options -a",
46
+ "open #{remote_ftp_url}",
47
+ "mkdir -p #{Shellwords.escape(remote)}",
48
+ "cd #{Shellwords.escape(remote)}",
49
+ "lcd #{Shellwords.escape(local)}",
50
+ lftp_mirror_arguments(reverse, exclude)
51
+ ].join("; ")
52
+
53
+ run "lftp -c '#{command}'"
58
54
  end
59
55
 
60
56
  def remote_ftp_url
61
- url = "ftp://"
57
+ url = options[:scheme].presence || "ftp"
58
+ url << "://"
62
59
  if options[:user].present?
63
- url << options[:user]
64
- url << ":#{options[:password]}" if options[:password].present?
60
+ url << CGI.escape(options[:user])
61
+ url << ":#{CGI.escape(options[:password])}" if options[:password].present?
65
62
  url << "@"
66
63
  end
67
64
  url << options[:host]
@@ -1,10 +1,3 @@
1
- require 'net/ssh'
2
- require 'net/ssh/gateway'
3
- require 'net/scp'
4
- require 'fileutils'
5
-
6
- require 'photocopier/adapter'
7
-
8
1
  module Photocopier
9
2
  class SSH < Adapter
10
3
 
@@ -29,28 +22,18 @@ module Photocopier
29
22
  end
30
23
 
31
24
  def delete(remote_path)
32
- exec!("rm -rf #{remote_path}")
25
+ exec!("rm -rf #{Shellwords.escape(remote_path)}")
33
26
  end
34
27
 
35
28
  def get_directory(remote_path, local_path, exclude = [])
36
29
  FileUtils.mkdir_p(local_path)
30
+ remote_path << "/" unless remote_path.end_with?("/")
37
31
  rsync ":#{remote_path}", local_path, exclude
38
32
  end
39
33
 
40
34
  def put_directory(local_path, remote_path, exclude = [])
41
- rsync local_path, ":#{remote_path}", exclude
42
- end
43
-
44
- def session
45
- opts = options
46
- host = opts.delete(:host)
47
- user = opts.delete(:user)
48
-
49
- @session ||= if gateway_options
50
- gateway.ssh(host, user, opts)
51
- else
52
- Net::SSH.start(host, user, opts)
53
- end
35
+ local_path << "/" unless local_path.end_with?("/")
36
+ rsync "#{local_path}", ":#{remote_path}", exclude
54
37
  end
55
38
 
56
39
  def exec!(cmd)
@@ -74,31 +57,47 @@ module Photocopier
74
57
  [ stdout, stderr, exit_code ]
75
58
  end
76
59
 
60
+ private
61
+
62
+ def session
63
+ opts = options
64
+ host = opts.delete(:host)
65
+ user = opts.delete(:user)
66
+
67
+ @session ||= if gateway_options
68
+ gateway.ssh(host, user, opts)
69
+ else
70
+ Net::SSH.start(host, user, opts)
71
+ end
72
+ end
73
+
77
74
  def rsync_command
78
- [
75
+ command = [
79
76
  "rsync",
80
77
  "--progress",
81
78
  "-e",
82
- rsh_arguments,
79
+ "'#{rsh_arguments}'",
83
80
  "-rlpt",
84
81
  "--compress",
85
82
  "--omit-dir-times",
86
83
  "--delete",
87
- rsync_options
88
- ].compact
84
+ ]
85
+ command.concat Shellwords.split(rsync_options) if rsync_options
86
+ command.compact
89
87
  end
90
88
 
91
89
  def rsync(source, destination, exclude = [])
92
90
  command = rsync_command
93
91
 
94
- exclude.map do |glob|
92
+ exclude.each do |glob|
95
93
  command << "--exclude"
96
94
  command << glob
97
95
  end
98
96
 
99
- command << "#{source}/" << destination
97
+ command << Shellwords.escape(source)
98
+ command << Shellwords.escape(destination)
100
99
 
101
- run *command
100
+ run command.join(" ")
102
101
  end
103
102
 
104
103
  def rsh_arguments
@@ -119,8 +118,6 @@ module Photocopier
119
118
  command
120
119
  end
121
120
 
122
- private
123
-
124
121
  def gateway
125
122
  return unless gateway_options
126
123
 
@@ -130,6 +127,5 @@ module Photocopier
130
127
 
131
128
  @gateway ||= Net::SSH::Gateway.new(host, user, opts)
132
129
  end
133
-
134
130
  end
135
131
  end
@@ -1,3 +1,3 @@
1
1
  module Photocopier
2
- VERSION = "0.0.10"
2
+ VERSION = "1.0.0.pre"
3
3
  end
data/lib/photocopier.rb CHANGED
@@ -1,4 +1,14 @@
1
- require "active_support/core_ext"
1
+ require 'tempfile'
2
+ require 'logger'
3
+ require 'fileutils'
4
+ require 'net/ftp'
5
+ require 'net/ssh'
6
+ require 'net/ssh/gateway'
7
+ require 'net/scp'
8
+ require 'fileutils'
9
+ require 'shellwords'
10
+ require 'active_support/all'
2
11
 
12
+ require 'photocopier/adapter'
3
13
  require "photocopier/ssh"
4
14
  require "photocopier/ftp"
data/photocopier.gemspec CHANGED
@@ -1,27 +1,34 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/photocopier/version', __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "photocopier/version"
3
5
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Stefano Verna", "Ju Liu"]
6
- gem.email = ["stefano.verna@welaika.com", "ju.liu@welaika.com"]
7
- gem.description = %q{Photocopier provides FTP/SSH adapters to abstract away file and directory copying.}
8
- gem.summary = %q{Photocopier provides FTP/SSH adapters to abstract away file and directory copying.}
9
- gem.homepage = "https://github.com/welaika/photocopier"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "photocopier"
8
+ spec.version = Photocopier::VERSION
9
+ spec.authors = ["Stefano Verna", "Ju Liu", "Fabrizio Monti"]
10
+ spec.email = ["stefano.verna@welaika.com", "ju.liu@welaika.com", "fabrizio.monti@welaika.com"]
10
11
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "photocopier"
15
- gem.require_paths = ["lib"]
16
- gem.version = Photocopier::VERSION
12
+ spec.summary = %q{Photocopier provides FTP/SSH adapters to abstract away file and directory copying.}
13
+ spec.description = %q{Photocopier provides FTP/SSH adapters to abstract away file and directory copying.}
14
+ spec.homepage = "https://github.com/welaika/photocopier"
15
+ spec.license = "MIT"
17
16
 
18
- gem.add_dependency "activesupport"
19
- gem.add_dependency "i18n"
20
- gem.add_dependency "net-ssh"
21
- gem.add_dependency "net-scp"
22
- gem.add_dependency "net-ssh-gateway"
23
- gem.add_dependency "escape"
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"]
24
21
 
25
- gem.add_development_dependency "rake"
26
- gem.add_development_dependency "rspec"
22
+ spec.required_ruby_version = ">= 2.1.2"
23
+
24
+ spec.add_dependency "activesupport", "~> 4.2.0"
25
+ spec.add_dependency "net-ssh", "~> 2.9.2"
26
+ spec.add_dependency "net-scp", "~> 1.2.1"
27
+ spec.add_dependency "net-ssh-gateway", "~> 1.2.0"
28
+ spec.add_dependency "escape", "~> 0.0.4"
29
+
30
+ spec.add_development_dependency "bundler", ">= 1.6.2"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.2"
33
+ spec.add_development_dependency "pry-byebug", "~> 3.0.1"
27
34
  end
metadata CHANGED
@@ -1,159 +1,175 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photocopier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  - Ju Liu
9
+ - Fabrizio Monti
9
10
  autorequire:
10
- bindir: bin
11
+ bindir: exe
11
12
  cert_chain: []
12
- date: 2013-08-30 00:00:00.000000000 Z
13
+ date: 2015-03-21 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activesupport
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - '>='
19
+ - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: '0'
21
+ version: 4.2.0
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - '>='
26
+ - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: '0'
28
+ version: 4.2.0
28
29
  - !ruby/object:Gem::Dependency
29
- name: i18n
30
+ name: net-ssh
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
- - - '>='
33
+ - - "~>"
33
34
  - !ruby/object:Gem::Version
34
- version: '0'
35
+ version: 2.9.2
35
36
  type: :runtime
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - '>='
40
+ - - "~>"
40
41
  - !ruby/object:Gem::Version
41
- version: '0'
42
+ version: 2.9.2
42
43
  - !ruby/object:Gem::Dependency
43
- name: net-ssh
44
+ name: net-scp
44
45
  requirement: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - '>='
47
+ - - "~>"
47
48
  - !ruby/object:Gem::Version
48
- version: '0'
49
+ version: 1.2.1
49
50
  type: :runtime
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - '>='
54
+ - - "~>"
54
55
  - !ruby/object:Gem::Version
55
- version: '0'
56
+ version: 1.2.1
56
57
  - !ruby/object:Gem::Dependency
57
- name: net-scp
58
+ name: net-ssh-gateway
58
59
  requirement: !ruby/object:Gem::Requirement
59
60
  requirements:
60
- - - '>='
61
+ - - "~>"
61
62
  - !ruby/object:Gem::Version
62
- version: '0'
63
+ version: 1.2.0
63
64
  type: :runtime
64
65
  prerelease: false
65
66
  version_requirements: !ruby/object:Gem::Requirement
66
67
  requirements:
67
- - - '>='
68
+ - - "~>"
68
69
  - !ruby/object:Gem::Version
69
- version: '0'
70
+ version: 1.2.0
70
71
  - !ruby/object:Gem::Dependency
71
- name: net-ssh-gateway
72
+ name: escape
72
73
  requirement: !ruby/object:Gem::Requirement
73
74
  requirements:
74
- - - '>='
75
+ - - "~>"
75
76
  - !ruby/object:Gem::Version
76
- version: '0'
77
+ version: 0.0.4
77
78
  type: :runtime
78
79
  prerelease: false
79
80
  version_requirements: !ruby/object:Gem::Requirement
80
81
  requirements:
81
- - - '>='
82
+ - - "~>"
82
83
  - !ruby/object:Gem::Version
83
- version: '0'
84
+ version: 0.0.4
84
85
  - !ruby/object:Gem::Dependency
85
- name: escape
86
+ name: bundler
86
87
  requirement: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - '>='
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :runtime
91
+ version: 1.6.2
92
+ type: :development
92
93
  prerelease: false
93
94
  version_requirements: !ruby/object:Gem::Requirement
94
95
  requirements:
95
- - - '>='
96
+ - - ">="
96
97
  - !ruby/object:Gem::Version
97
- version: '0'
98
+ version: 1.6.2
98
99
  - !ruby/object:Gem::Dependency
99
100
  name: rake
100
101
  requirement: !ruby/object:Gem::Requirement
101
102
  requirements:
102
- - - '>='
103
+ - - "~>"
103
104
  - !ruby/object:Gem::Version
104
- version: '0'
105
+ version: '10.0'
105
106
  type: :development
106
107
  prerelease: false
107
108
  version_requirements: !ruby/object:Gem::Requirement
108
109
  requirements:
109
- - - '>='
110
+ - - "~>"
110
111
  - !ruby/object:Gem::Version
111
- version: '0'
112
+ version: '10.0'
112
113
  - !ruby/object:Gem::Dependency
113
114
  name: rspec
114
115
  requirement: !ruby/object:Gem::Requirement
115
116
  requirements:
116
- - - '>='
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.2'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '3.2'
127
+ - !ruby/object:Gem::Dependency
128
+ name: pry-byebug
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
117
132
  - !ruby/object:Gem::Version
118
- version: '0'
133
+ version: 3.0.1
119
134
  type: :development
120
135
  prerelease: false
121
136
  version_requirements: !ruby/object:Gem::Requirement
122
137
  requirements:
123
- - - '>='
138
+ - - "~>"
124
139
  - !ruby/object:Gem::Version
125
- version: '0'
140
+ version: 3.0.1
126
141
  description: Photocopier provides FTP/SSH adapters to abstract away file and directory
127
142
  copying.
128
143
  email:
129
144
  - stefano.verna@welaika.com
130
145
  - ju.liu@welaika.com
146
+ - fabrizio.monti@welaika.com
131
147
  executables: []
132
148
  extensions: []
133
149
  extra_rdoc_files: []
134
150
  files:
135
- - .gitignore
136
- - .rspec
137
- - .ruby-version
138
- - .rvmrc
139
- - .travis.yml
151
+ - ".gitignore"
152
+ - ".rspec"
153
+ - ".ruby-gemset"
154
+ - ".ruby-version"
155
+ - ".travis.yml"
156
+ - CHANGELOG.md
140
157
  - Gemfile
141
- - Gemfile.lock
142
158
  - LICENSE
143
159
  - README.md
144
160
  - Rakefile
161
+ - bin/console
162
+ - bin/rspec
163
+ - bin/setup
145
164
  - lib/photocopier.rb
146
165
  - lib/photocopier/adapter.rb
147
166
  - lib/photocopier/ftp.rb
148
167
  - lib/photocopier/ssh.rb
149
168
  - lib/photocopier/version.rb
150
169
  - photocopier.gemspec
151
- - spec/adapter_spec.rb
152
- - spec/ftp_spec.rb
153
- - spec/shared_examples_for_adapter.rb
154
- - spec/ssh_spec.rb
155
170
  homepage: https://github.com/welaika/photocopier
156
- licenses: []
171
+ licenses:
172
+ - MIT
157
173
  metadata: {}
158
174
  post_install_message:
159
175
  rdoc_options: []
@@ -161,23 +177,19 @@ require_paths:
161
177
  - lib
162
178
  required_ruby_version: !ruby/object:Gem::Requirement
163
179
  requirements:
164
- - - '>='
180
+ - - ">="
165
181
  - !ruby/object:Gem::Version
166
- version: '0'
182
+ version: 2.1.2
167
183
  required_rubygems_version: !ruby/object:Gem::Requirement
168
184
  requirements:
169
- - - '>='
185
+ - - ">"
170
186
  - !ruby/object:Gem::Version
171
- version: '0'
187
+ version: 1.3.1
172
188
  requirements: []
173
189
  rubyforge_project:
174
- rubygems_version: 2.0.3
190
+ rubygems_version: 2.4.5
175
191
  signing_key:
176
192
  specification_version: 4
177
193
  summary: Photocopier provides FTP/SSH adapters to abstract away file and directory
178
194
  copying.
179
- test_files:
180
- - spec/adapter_spec.rb
181
- - spec/ftp_spec.rb
182
- - spec/shared_examples_for_adapter.rb
183
- - spec/ssh_spec.rb
195
+ test_files: []
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@photocopier
data/Gemfile.lock DELETED
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- photocopier (0.0.10)
5
- activesupport
6
- escape
7
- i18n
8
- net-scp
9
- net-ssh
10
- net-ssh-gateway
11
-
12
- GEM
13
- remote: https://rubygems.org/
14
- specs:
15
- activesupport (4.0.0)
16
- i18n (~> 0.6, >= 0.6.4)
17
- minitest (~> 4.2)
18
- multi_json (~> 1.3)
19
- thread_safe (~> 0.1)
20
- tzinfo (~> 0.3.37)
21
- atomic (1.1.13)
22
- diff-lcs (1.1.3)
23
- escape (0.0.4)
24
- i18n (0.6.5)
25
- minitest (4.7.5)
26
- multi_json (1.7.9)
27
- net-scp (1.1.2)
28
- net-ssh (>= 2.6.5)
29
- net-ssh (2.6.8)
30
- net-ssh-gateway (1.2.0)
31
- net-ssh (>= 2.6.5)
32
- rake (10.1.0)
33
- rspec (2.11.0)
34
- rspec-core (~> 2.11.0)
35
- rspec-expectations (~> 2.11.0)
36
- rspec-mocks (~> 2.11.0)
37
- rspec-core (2.11.1)
38
- rspec-expectations (2.11.3)
39
- diff-lcs (~> 1.1.3)
40
- rspec-mocks (2.11.3)
41
- thread_safe (0.1.2)
42
- atomic
43
- tzinfo (0.3.37)
44
-
45
- PLATFORMS
46
- ruby
47
-
48
- DEPENDENCIES
49
- photocopier!
50
- rake
51
- rspec
data/spec/adapter_spec.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'photocopier/adapter'
2
- require 'shared_examples_for_adapter'
3
-
4
- describe Photocopier::Adapter do
5
- it_behaves_like "a Photocopier adapter"
6
- end
data/spec/ftp_spec.rb DELETED
@@ -1,163 +0,0 @@
1
- require 'photocopier/ftp'
2
- require 'shared_examples_for_adapter'
3
-
4
- describe Photocopier::FTP do
5
- it_behaves_like "a Photocopier adapter"
6
-
7
- let(:ftp) { Photocopier::FTP.new(options) }
8
- let(:options) do { host: "host", user: "user", password: "password" } end
9
-
10
- context "#session" do
11
- it "retrieves an FTP session" do
12
- Net::FTP.should_receive(:open).with("host", "user", "password")
13
- ftp.session
14
- end
15
-
16
- context "passive mode" do
17
- let(:options) do { host: "host", passive: true } end
18
- let(:ftp) { double('ftp').as_null_object }
19
-
20
- it "should enable passive mode" do
21
- Net::FTP.stub(:open).and_return(ftp)
22
- ftp.session.should be_passive
23
- end
24
- end
25
- end
26
-
27
- context "#remote_ftp_url" do
28
- let(:options) do { host: "host" } end
29
-
30
- it "should build an ftp url" do
31
- ftp.send(:remote_ftp_url).should == "ftp://host"
32
- end
33
-
34
- context "given an username" do
35
- let(:options) do { host: "host", user: "user" } end
36
-
37
- it "should add it to the url" do
38
- ftp.send(:remote_ftp_url).should == "ftp://user@host"
39
- end
40
-
41
- context "given a password" do
42
- let(:options) do { host: "host", user: "user", password: "password" } end
43
-
44
- it "should add it to the url" do
45
- ftp.send(:remote_ftp_url).should == "ftp://user:password@host"
46
- end
47
- end
48
- end
49
- end
50
-
51
- context "#lftp_mirror_arguments" do
52
- let(:lftp_arguments) do
53
- %w(
54
- mirror
55
- --delete
56
- --use-cache
57
- --verbose
58
- --allow-chown
59
- --allow-suid
60
- --no-umask
61
- --parallel=2
62
- )
63
- end
64
-
65
- it "should build arguments for lftp" do
66
- ftp.send(:lftp_mirror_arguments, false, []).should == lftp_arguments.join(" ")
67
- end
68
-
69
- it "should build args for reverse mirroring" do
70
- lftp_arguments << "--reverse"
71
- ftp.send(:lftp_mirror_arguments, true, []).should == lftp_arguments.join(" ")
72
- end
73
-
74
- it "should exclude files" do
75
- lftp_arguments << "--exclude-glob .git"
76
- ftp.send(:lftp_mirror_arguments, false, [".git"]).should == lftp_arguments.join(" ")
77
- end
78
- end
79
-
80
- context "#lftp" do
81
-
82
- let(:remote) { "remote" }
83
- let(:local) { "local" }
84
-
85
- before(:each) do
86
- ftp.stub(:remote_ftp_url).and_return("remote_ftp_url")
87
- ftp.stub(:lftp_mirror_arguments).and_return("lftp_mirror_arguments")
88
- end
89
-
90
- let(:lftp_command) do
91
- [
92
- "lftp",
93
- "-c",
94
- [
95
- "set ftp:list-options -a",
96
- "open remote_ftp_url",
97
- "mkdir -p #{remote}",
98
- "cd #{remote}",
99
- "lcd #{local}",
100
- "lftp_mirror_arguments"
101
- ].join("; ")
102
- ]
103
- end
104
-
105
- it "should build a lftp command" do
106
- ftp.should_receive(:run).with(*lftp_command)
107
- ftp.send(:lftp, local, remote, false, [])
108
- end
109
- end
110
-
111
- context "adapter interface" do
112
-
113
- let(:remote_path) { double }
114
- let(:local_path) { double }
115
- let(:file_path) { double }
116
- let(:session) { double }
117
-
118
- before(:each) do
119
- ftp.stub(:session).and_return(session)
120
- end
121
-
122
- context "#get" do
123
- it "should get a remote path" do
124
- session.should_receive(:get).with(remote_path, file_path)
125
- ftp.get(remote_path, file_path)
126
- end
127
- end
128
-
129
- context "#put_file" do
130
- it "should send a file to remote" do
131
- session.should_receive(:put).with(file_path, remote_path)
132
- ftp.put_file(file_path, remote_path)
133
- end
134
- end
135
-
136
- context "#delete" do
137
- it "should delete a remote path" do
138
- session.should_receive(:delete).with(remote_path)
139
- ftp.delete(remote_path)
140
- end
141
- end
142
-
143
- context "directories management" do
144
- let(:remote_path) { "remote_path" }
145
- let(:exclude_list) { [] }
146
-
147
- context "#get_directory" do
148
- it "should get a remote directory" do
149
- FileUtils.should_receive(:mkdir_p).with(local_path)
150
- ftp.should_receive(:lftp).with(local_path, remote_path, false, exclude_list)
151
- ftp.get_directory(remote_path, local_path, exclude_list)
152
- end
153
- end
154
-
155
- context "#put_directory" do
156
- it "should send a directory to remote" do
157
- ftp.should_receive(:lftp).with(local_path, remote_path, true, exclude_list)
158
- ftp.put_directory(local_path, remote_path, exclude_list)
159
- end
160
- end
161
- end
162
- end
163
- end
@@ -1,71 +0,0 @@
1
- require 'photocopier/adapter'
2
-
3
- shared_examples_for "a Photocopier adapter" do
4
- let(:adapter) { described_class.new }
5
-
6
- context "adapter interface" do
7
- it "should expose all adapter methods" do
8
- [
9
- :put,
10
- :put_file,
11
- :put_directory,
12
- :get,
13
- :get_directory,
14
- :delete
15
- ].each do |sym|
16
- adapter.should respond_to(sym)
17
- end
18
- end
19
- end
20
-
21
- context "#put" do
22
- let(:file_path) { Tempfile.new("tmp").path }
23
- let(:remote_path) { double }
24
-
25
- context "given a real file path" do
26
- it "should put a file" do
27
- adapter.should_receive(:put_file).with(file_path, remote_path)
28
- adapter.put(file_path, remote_path)
29
- end
30
- end
31
-
32
- context "given a string" do
33
- let(:string) { "foobar" }
34
- let(:file) { double(path: "path") }
35
-
36
- it "should write it to file, put it and remove the file" do
37
- Tempfile.stub(:new).and_return(file)
38
-
39
- file.should_receive(:write).with(string)
40
- file.should_receive(:close)
41
- adapter.should_receive(:put_file).with("path", remote_path)
42
- file.should_receive(:unlink)
43
-
44
- adapter.put(string, remote_path)
45
- end
46
- end
47
-
48
- context "#run" do
49
- let(:arg) { double }
50
- let(:command) { double }
51
- before(:each) {
52
- Escape.stub(:shell_command).with([arg]).and_return(command)
53
- }
54
-
55
- it "should delegate to Kernel system" do
56
- adapter.should_receive(:system).with(command)
57
- adapter.send(:run, arg)
58
- end
59
-
60
- context "given a logger" do
61
- let(:logger) { double }
62
-
63
- it "should send the command to the logger" do
64
- adapter.logger = logger
65
- logger.should_receive(:info).with(command)
66
- adapter.send(:run, arg)
67
- end
68
- end
69
- end
70
- end
71
- end
data/spec/ssh_spec.rb DELETED
@@ -1,161 +0,0 @@
1
- require 'photocopier/ssh'
2
- require 'shared_examples_for_adapter'
3
-
4
- describe Photocopier::SSH do
5
- it_behaves_like "a Photocopier adapter"
6
-
7
- let(:ssh) { Photocopier::SSH.new(options) }
8
- let(:options) do { host: "host", user: "user" } end
9
- let(:gateway_config) do { host: "gate_host", user: "gate_user" } end
10
- let(:options_with_gateway) do
11
- {
12
- host: "host",
13
- user: "user",
14
- gateway: gateway_config
15
- }
16
- end
17
-
18
- context "#session" do
19
- it "retrieves an SSH session" do
20
- Net::SSH.should_receive(:start).with("host", "user", {})
21
- ssh.session
22
- end
23
-
24
- context "given a gateway " do
25
- let(:options) { options_with_gateway }
26
- let(:gateway) { double }
27
-
28
- it "goes through it to retrieve a session" do
29
- Net::SSH::Gateway.stub(:new).with("gate_host", "gate_user", {}).and_return(gateway)
30
- gateway.should_receive(:ssh).with("host", "user", {})
31
- ssh.session
32
- end
33
- end
34
- end
35
-
36
- context "#ssh_command" do
37
- let(:options) do { host: "host" } end
38
-
39
- it "should build an ssh command" do
40
- ssh.ssh_command(options).should == "ssh host"
41
- end
42
-
43
- context "given a port" do
44
- let(:options) do { host: "host", port: "port" } end
45
- it "should be added to the command" do
46
- ssh.ssh_command(options).should == "ssh -p port host"
47
- end
48
- end
49
-
50
- context "given a user" do
51
- let(:options) do { host: "host", user: "user" } end
52
- it "should be added to the command" do
53
- ssh.ssh_command(options).should == "ssh user@host"
54
- end
55
- end
56
-
57
- context "given a password" do
58
- let(:options) do { host: "host", password: "password" } end
59
-
60
- it "sshpass should be added to the command" do
61
- ssh.ssh_command(options).should == "sshpass -p password ssh host"
62
- end
63
- end
64
- end
65
-
66
- context "#rsh_arguments" do
67
- it "should build arguments for rsync" do
68
- ssh.should_receive(:ssh_command).with(options)
69
- ssh.rsh_arguments
70
- end
71
-
72
- context "given a gateway" do
73
- let(:options) { options_with_gateway }
74
-
75
- it "should include gateway options" do
76
- ssh.should_receive(:ssh_command).with(gateway_config)
77
- ssh.should_receive(:ssh_command).with(options)
78
- ssh.rsh_arguments
79
- end
80
- end
81
- end
82
-
83
- context "#rsync" do
84
- before(:each) do
85
- ssh.stub(:rsh_arguments).and_return("rsh_arguments")
86
- ssh.stub(:rsync_options).and_return("rsync_options")
87
- end
88
-
89
- let(:rsync_command) { ssh.rsync_command }
90
-
91
- it "should build an rsync command" do
92
- rsync_command << "source/" << "destination"
93
- ssh.should_receive(:run).with(*rsync_command)
94
- ssh.rsync("source", "destination")
95
- end
96
-
97
- context "given an exclude list" do
98
- it "should skip excluded paths" do
99
- rsync_command << "--exclude" << ".git"
100
- rsync_command << "source/" << "destination"
101
- ssh.should_receive(:run).with(*rsync_command)
102
- ssh.rsync("source", "destination", [".git"])
103
- end
104
- end
105
- end
106
-
107
- context "adapter interface" do
108
-
109
- let(:remote_path) { double }
110
- let(:local_path) { double }
111
- let(:file_path) { double }
112
- let(:scp) { double }
113
- let(:session) { double(scp: scp) }
114
-
115
- before(:each) do
116
- ssh.stub(:session).and_return(session)
117
- end
118
-
119
- context "#get" do
120
- it "should get a remote path" do
121
- scp.should_receive(:download!).with(remote_path, file_path)
122
- ssh.get(remote_path, file_path)
123
- end
124
- end
125
-
126
- context "#put_file" do
127
- it "should send a file to remote" do
128
- scp.should_receive(:upload!).with(file_path, remote_path)
129
- ssh.put_file(file_path, remote_path)
130
- end
131
- end
132
-
133
- context "#delete" do
134
- it "should delete a remote path" do
135
- ssh.should_receive(:exec!).with("rm -rf foo")
136
- ssh.delete("foo")
137
- end
138
- end
139
-
140
- context "directories management" do
141
- let(:remote_path) { "remote_path" }
142
- let(:exclude_list) { [] }
143
-
144
- context "#get_directory" do
145
- it "should get a remote directory" do
146
- FileUtils.should_receive(:mkdir_p).with(local_path)
147
- ssh.should_receive(:rsync).with(":remote_path", local_path, exclude_list)
148
- ssh.get_directory(remote_path, local_path, exclude_list)
149
- end
150
- end
151
-
152
- context "#put_directory" do
153
- it "should send a directory to remote" do
154
- ssh.should_receive(:rsync).with(local_path, ":remote_path", exclude_list)
155
- ssh.put_directory(local_path, remote_path, exclude_list)
156
- end
157
- end
158
- end
159
- end
160
-
161
- end