photocopier 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -104,6 +104,10 @@ have it via [`brew`](https://github.com/mxcl/homebrew):
104
104
  sudo brew install https://raw.github.com/gist/1513663/3e98bf9e03feb7e31eeddcd08f89ca86163a376d/sshpass.rb
105
105
  ```
106
106
 
107
+ **Please note that on Ubuntu 11.10 `sshpass` is at version 1.04, which has a
108
+ [bug](https://bugs.launchpad.net/ubuntu/+source/sshpass/+bug/774882) that prevents
109
+ it from working. Install version 1.03 or 1.05.**
110
+
107
111
  ## Contributing
108
112
 
109
113
  1. Fork it
@@ -23,13 +23,17 @@ module Photocopier
23
23
 
24
24
  def delete(remote_path); end
25
25
 
26
- def get_directory(remote_path, local_path); end
27
- def put_directory(local_path, remote_path); end
26
+ def get_directory(remote_path, local_path, exclude = []); end
27
+ def put_directory(local_path, remote_path, exclude = []); end
28
28
 
29
29
  protected
30
30
 
31
31
  def run(*args)
32
- system Escape.shell_command(args)
32
+ command = Escape.shell_command(args)
33
+ if logger.present?
34
+ logger.info command
35
+ end
36
+ system command
33
37
  end
34
38
  end
35
39
 
@@ -25,26 +25,26 @@ module Photocopier
25
25
  session.delete(remote_path)
26
26
  end
27
27
 
28
- def get_directory(remote_path, local_path)
28
+ def get_directory(remote_path, local_path, exclude = [])
29
29
  FileUtils.mkdir_p(local_path)
30
- lftp(local_path, remote_path, false)
30
+ lftp(local_path, remote_path, false, exclude)
31
31
  end
32
32
 
33
- def put_directory(local_path, remote_path)
34
- lftp(local_path, remote_path, true)
33
+ def put_directory(local_path, remote_path, exclude = [])
34
+ lftp(local_path, remote_path, true, exclude)
35
35
  end
36
36
 
37
37
  def session
38
- opts = options
39
- host = opts.delete(:host)
40
- user = opts.delete(:user)
41
- password = opts.delete(:password)
42
- @session ||= Net::FTP.open(host, user, password)
38
+ if @session.nil?
39
+ @session = Net::FTP.open(options[:host], options[:user], options[:password])
40
+ @session.passive = options[:passive] if options.has_key?(:passive)
41
+ end
42
+ @session
43
43
  end
44
44
 
45
45
  private
46
46
 
47
- def lftp(local, remote, reverse)
47
+ def lftp(local, remote, reverse, exclude)
48
48
  run "lftp",
49
49
  "-c",
50
50
  [
@@ -53,7 +53,7 @@ module Photocopier
53
53
  "mkdir -p #{remote}",
54
54
  "cd #{remote}",
55
55
  "lcd #{local}",
56
- lftp_mirror_arguments(reverse)
56
+ lftp_mirror_arguments(reverse, exclude)
57
57
  ].join("; ")
58
58
  end
59
59
 
@@ -68,9 +68,12 @@ module Photocopier
68
68
  url
69
69
  end
70
70
 
71
- def lftp_mirror_arguments(reverse)
71
+ def lftp_mirror_arguments(reverse, exclude = [])
72
72
  mirror = "mirror --delete --use-cache --verbose --allow-chown --allow-suid --no-umask --parallel=2"
73
73
  mirror << " --reverse" if reverse
74
+ exclude.each do |glob|
75
+ mirror << " --exclude-glob #{glob}"
76
+ end
74
77
  mirror
75
78
  end
76
79
 
@@ -28,13 +28,13 @@ module Photocopier
28
28
  session.exec!("rm -rf #{remote_path}")
29
29
  end
30
30
 
31
- def get_directory(remote_path, local_path)
31
+ def get_directory(remote_path, local_path, exclude = [])
32
32
  FileUtils.mkdir_p(local_path)
33
- rsync ":#{remote_path}", local_path
33
+ rsync ":#{remote_path}", local_path, exclude
34
34
  end
35
35
 
36
- def put_directory(local_path, remote_path)
37
- rsync local_path, ":#{remote_path}"
36
+ def put_directory(local_path, remote_path, exclude = [])
37
+ rsync local_path, ":#{remote_path}", exclude
38
38
  end
39
39
 
40
40
  def session
@@ -52,9 +52,21 @@ module Photocopier
52
52
 
53
53
  private
54
54
 
55
- def rsync(source, destination)
56
- run "rsync", "--progress", "-e", rsh_arguments, "--archive", "--compress",
57
- "--omit-dir-times", "--delete", "#{source}/", destination
55
+ def rsync(source, destination, exclude)
56
+ command = [
57
+ "rsync", "--progress", "-e", rsh_arguments, "--archive", "--compress",
58
+ "--omit-dir-times", "--delete"
59
+ ]
60
+
61
+ exclude.map do |glob|
62
+ command << "--exclude"
63
+ command << glob
64
+ end
65
+
66
+ command << "#{source}/"
67
+ command << destination
68
+
69
+ run *command
58
70
  end
59
71
 
60
72
  def rsh_arguments
@@ -1,3 +1,3 @@
1
1
  module Photocopier
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photocopier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport