guard-flopbox 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/guard-flopbox.gemspec +19 -0
- data/lib/guard/guard-flopbox.rb +93 -0
- data/lib/guard/guard-flopbox/templates/Guardfile +16 -0
- metadata +63 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# guard-flopbox
|
2
|
+
|
3
|
+
Flopbox is a simple guard library that syncs local and remote directories via SFTP as files are changed.
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
This is a sample guardfile
|
8
|
+
|
9
|
+
opts = {
|
10
|
+
:hostname => "postercloud.com", # remote host
|
11
|
+
:user => "capuser", # remote user
|
12
|
+
:sftp_opts => {}, # options passed to Net::SFTP
|
13
|
+
:remote => "/home/capuser/test", # remote directory
|
14
|
+
:debug => true, # output debug information
|
15
|
+
:growl => true, # growl on completion
|
16
|
+
:growl_image => "/path/to/image" # image to use for growl
|
17
|
+
}
|
18
|
+
|
19
|
+
group 'flopbox' do
|
20
|
+
guard 'flopbox', opts do
|
21
|
+
watch(/.*/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Dependencies
|
26
|
+
|
27
|
+
- guard
|
28
|
+
- Net::SFTP
|
29
|
+
- growl
|
30
|
+
|
31
|
+
# Author
|
32
|
+
|
33
|
+
Flopbox was written by Vincent Chu (vincentchu [at] gmail [dot] com) and is used at Posterous.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "guard-flopbox"
|
6
|
+
s.version = 1.0
|
7
|
+
s.authors = ["Vincent Chu"]
|
8
|
+
s.email = ["vincentchu at gmail dot com"]
|
9
|
+
s.homepage = "http://github.com/vincentchu/guard-flopbox"
|
10
|
+
s.summary = %q{A simple guard library for syncing local and remote directories via SFTP}
|
11
|
+
s.description = %q{A simple guard library for syncing local and remote directories via SFTP}
|
12
|
+
|
13
|
+
s.rubyforge_project = "guard-flopbox"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
require 'growl'
|
3
|
+
require 'guard'
|
4
|
+
require 'guard/guard'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Flopbox < Guard
|
8
|
+
|
9
|
+
attr_reader :sftp_session, :remote, :pwd, :growl_image
|
10
|
+
|
11
|
+
def initialize(watchers = [], options = {})
|
12
|
+
@sftp_session = Net::SFTP.start(options[:hostname], options[:user], options[:sftp_opts])
|
13
|
+
@remote = options[:remote]
|
14
|
+
@debug = options[:debug]
|
15
|
+
@growl = options[:growl]
|
16
|
+
@growl_image = options[:growl_image]
|
17
|
+
@pwd = Dir.pwd
|
18
|
+
|
19
|
+
log "Initialized with watchers = #{watchers.inspect}"
|
20
|
+
log "Initialized with options = #{options.inspect}"
|
21
|
+
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_on_change(paths)
|
26
|
+
paths.each do |path|
|
27
|
+
local_file = File.join(pwd, path)
|
28
|
+
remote_file = File.join(remote, path)
|
29
|
+
|
30
|
+
attempts = 0
|
31
|
+
begin
|
32
|
+
log "Upload #{local_file} => #{remote_file}"
|
33
|
+
sftp_session.upload!(local_file, remote_file)
|
34
|
+
|
35
|
+
rescue Net::SFTP::StatusException => ex
|
36
|
+
log "Exception on upload #{path} - directory likely doesn't exist"
|
37
|
+
|
38
|
+
attempts += 1
|
39
|
+
remote_dir = File.dirname(remote_file)
|
40
|
+
recursively_create_dirs( remote_dir )
|
41
|
+
|
42
|
+
retry if (attempts < 3)
|
43
|
+
log "Exceeded 3 attempts to upload #{path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
growl("Synced:\n#{paths.join("\n")}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def growl?
|
53
|
+
@growl || false
|
54
|
+
end
|
55
|
+
|
56
|
+
def debug?
|
57
|
+
@debug || false
|
58
|
+
end
|
59
|
+
|
60
|
+
def growl(mesg)
|
61
|
+
return unless growl?
|
62
|
+
|
63
|
+
growl_opts = {
|
64
|
+
:name => "flopbox",
|
65
|
+
:title => "Flopbox: #{File.basename(pwd)}",
|
66
|
+
:message => mesg
|
67
|
+
:image => growl_image
|
68
|
+
}
|
69
|
+
|
70
|
+
Growl::Base.new(growl_opts).run
|
71
|
+
end
|
72
|
+
|
73
|
+
def log(mesg)
|
74
|
+
return unless debug?
|
75
|
+
|
76
|
+
puts "[#{Time.now}] #{mesg}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def recursively_create_dirs(remote_dir)
|
80
|
+
new_dir = remote
|
81
|
+
remote_dir.gsub(remote, "").split("/").each do |dir|
|
82
|
+
|
83
|
+
new_dir = File.join(new_dir, dir)
|
84
|
+
|
85
|
+
begin
|
86
|
+
log "Creating #{new_dir}"
|
87
|
+
sftp_session.mkdir!(new_dir)
|
88
|
+
rescue Net::SFTP::StatusException => ex
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
# Configuration Options for guard-flopbox
|
3
|
+
opts = {
|
4
|
+
:hostname => "postercloud.com", # remote host
|
5
|
+
:user => "capuser", # remote user
|
6
|
+
:sftp_opts => {}, # options passed to Net::SFTP
|
7
|
+
:remote => "/home/capuser/test", # remote directory
|
8
|
+
:debug => true, # output debug information
|
9
|
+
:growl => true # growl on completion
|
10
|
+
}
|
11
|
+
|
12
|
+
group 'flopbox' do
|
13
|
+
guard 'flopbox', opts do
|
14
|
+
watch(/.*/)
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-flopbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "1.0"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vincent Chu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-01 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: A simple guard library for syncing local and remote directories via SFTP
|
18
|
+
email:
|
19
|
+
- vincentchu at gmail dot com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- guard-flopbox.gemspec
|
32
|
+
- lib/guard/guard-flopbox.rb
|
33
|
+
- lib/guard/guard-flopbox/templates/Guardfile
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/vincentchu/guard-flopbox
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: guard-flopbox
|
58
|
+
rubygems_version: 1.6.2
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: A simple guard library for syncing local and remote directories via SFTP
|
62
|
+
test_files: []
|
63
|
+
|