vagrant-fsnotify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb3aa01722396ea81758b1750ff4dbfd180bb715
4
+ data.tar.gz: e8317e0b2cd4c3e768049aad6305616aec5700d4
5
+ SHA512:
6
+ metadata.gz: b383e054ac0f94f5ca4147ba9fdd32a6d297db96217aec24df2d0fc74881b41d8803c5d3b7331e0c984a37186d21c564ed4492563eecafe6980421437f146b45
7
+ data.tar.gz: 350387bb4b28057ca4190784167f06945a82575dbdc28da02574469d1998269236da9a841213aaa19c0e7cd9ebc9fa03b796b878c0b0fd6b23922f16a3c9ad75
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ .vagrant/
17
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", ref: 'v1.6.3'
5
+ end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Adrien Kohlbecker
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ vagrant-fsnotify
2
+ ================
3
+
4
+ Forward filesystem change notifications to your Vagrant VM
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,122 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ # All Vagrant configuration is done here. The most common configuration
9
+ # options are documented and commented below. For a complete reference,
10
+ # please see the online documentation at vagrantup.com.
11
+
12
+ # Every Vagrant virtual environment requires a box to build off of.
13
+ config.vm.box = "ubuntu/trusty64"
14
+
15
+ # Disable automatic box update checking. If you disable this, then
16
+ # boxes will only be checked for updates when the user runs
17
+ # `vagrant box outdated`. This is not recommended.
18
+ # config.vm.box_check_update = false
19
+
20
+ # Create a forwarded port mapping which allows access to a specific port
21
+ # within the machine from a port on the host machine. In the example below,
22
+ # accessing "localhost:8080" will access port 80 on the guest machine.
23
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
24
+
25
+ # Create a private network, which allows host-only access to the machine
26
+ # using a specific IP.
27
+ config.vm.network "private_network", ip: "192.168.33.10"
28
+
29
+ # Create a public network, which generally matched to bridged network.
30
+ # Bridged networks make the machine appear as another physical device on
31
+ # your network.
32
+ # config.vm.network "public_network"
33
+
34
+ # If true, then any SSH connections made will enable agent forwarding.
35
+ # Default value: false
36
+ # config.ssh.forward_agent = true
37
+
38
+ # Share an additional folder to the guest VM. The first argument is
39
+ # the path on the host to the actual folder. The second argument is
40
+ # the path on the guest to mount the folder. And the optional third
41
+ # argument is a set of non-required options.
42
+ config.vm.synced_folder ".", "/vagrant", fsnotify: true
43
+
44
+ # Provider-specific configuration so you can fine-tune various
45
+ # backing providers for Vagrant. These expose provider-specific options.
46
+ # Example for VirtualBox:
47
+ #
48
+ # config.vm.provider "virtualbox" do |vb|
49
+ # # Don't boot with headless mode
50
+ # vb.gui = true
51
+ #
52
+ # # Use VBoxManage to customize the VM. For example to change memory:
53
+ # vb.customize ["modifyvm", :id, "--memory", "1024"]
54
+ # end
55
+ #
56
+ # View the documentation for the provider you're using for more
57
+ # information on available options.
58
+
59
+ # Enable provisioning with CFEngine. CFEngine Community packages are
60
+ # automatically installed. For example, configure the host as a
61
+ # policy server and optionally a policy file to run:
62
+ #
63
+ # config.vm.provision "cfengine" do |cf|
64
+ # cf.am_policy_hub = true
65
+ # # cf.run_file = "motd.cf"
66
+ # end
67
+ #
68
+ # You can also configure and bootstrap a client to an existing
69
+ # policy server:
70
+ #
71
+ # config.vm.provision "cfengine" do |cf|
72
+ # cf.policy_server_address = "10.0.2.15"
73
+ # end
74
+
75
+ # Enable provisioning with Puppet stand alone. Puppet manifests
76
+ # are contained in a directory path relative to this Vagrantfile.
77
+ # You will need to create the manifests directory and a manifest in
78
+ # the file default.pp in the manifests_path directory.
79
+ #
80
+ # config.vm.provision "puppet" do |puppet|
81
+ # puppet.manifests_path = "manifests"
82
+ # puppet.manifest_file = "site.pp"
83
+ # end
84
+
85
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
86
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
87
+ # some recipes and/or roles.
88
+ #
89
+ # config.vm.provision "chef_solo" do |chef|
90
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
91
+ # chef.roles_path = "../my-recipes/roles"
92
+ # chef.data_bags_path = "../my-recipes/data_bags"
93
+ # chef.add_recipe "mysql"
94
+ # chef.add_role "web"
95
+ #
96
+ # # You may also specify custom JSON attributes:
97
+ # chef.json = { mysql_password: "foo" }
98
+ # end
99
+
100
+ # Enable provisioning with chef server, specifying the chef server URL,
101
+ # and the path to the validation key (relative to this Vagrantfile).
102
+ #
103
+ # The Opscode Platform uses HTTPS. Substitute your organization for
104
+ # ORGNAME in the URL and validation key.
105
+ #
106
+ # If you have your own Chef Server, use the appropriate URL, which may be
107
+ # HTTP instead of HTTPS depending on your configuration. Also change the
108
+ # validation key to validation.pem.
109
+ #
110
+ # config.vm.provision "chef_client" do |chef|
111
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
112
+ # chef.validation_key_path = "ORGNAME-validator.pem"
113
+ # end
114
+ #
115
+ # If you're using the Opscode platform, your validator client is
116
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
117
+ #
118
+ # If you have your own Chef Server, the default validation client name is
119
+ # chef-validator, unless you changed the configuration.
120
+ #
121
+ # chef.validation_client_name = "ORGNAME-validator"
122
+ end
@@ -0,0 +1,7 @@
1
+ require "vagrant-fsnotify/version"
2
+ require "vagrant-fsnotify/plugin"
3
+
4
+ module VagrantPlugins
5
+ module Fsnotify
6
+ end
7
+ end
@@ -0,0 +1,130 @@
1
+ require 'listen'
2
+
3
+ module VagrantPlugins::Fsnotify
4
+ class Command < Vagrant.plugin("2", :command)
5
+ include Vagrant::Action::Builtin::MixinSyncedFolders
6
+
7
+ def execute
8
+ @logger = Log4r::Logger.new("vagrant::commands::rsync-auto")
9
+
10
+ params = OptionParser.new do |o|
11
+ o.banner = "Usage: vagrant fsnotify [vm-name]"
12
+ o.separator ""
13
+ end
14
+
15
+ argv = parse_options(params)
16
+ return if !argv
17
+
18
+ paths = {}
19
+ @changes = {}
20
+
21
+ with_target_vms do |machine|
22
+ if !machine.communicate.ready?
23
+ machine.ui.error("Machine not ready, is it up?")
24
+ return 1
25
+ end
26
+
27
+ synced_folders(machine).each do |type, folder|
28
+
29
+ folder.each do |id, opts|
30
+
31
+ next if not opts[:fsnotify]
32
+
33
+ # Folder info
34
+ hostpath = opts[:hostpath]
35
+ hostpath = File.expand_path(hostpath, machine.env.root_path)
36
+ hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s
37
+
38
+ if Vagrant::Util::Platform.windows?
39
+ # rsync for Windows expects cygwin style paths, always.
40
+ hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)
41
+ end
42
+
43
+ # Make sure the host path ends with a "/" to avoid creating
44
+ # a nested directory...
45
+ if !hostpath.end_with?("/")
46
+ hostpath += "/"
47
+ end
48
+
49
+ machine.ui.info("fsnotify: Watching #{hostpath}")
50
+
51
+ paths[hostpath] = {
52
+ id: id,
53
+ machine: machine,
54
+ opts: opts
55
+ }
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ if paths.empty?
64
+ return 0
65
+ end
66
+
67
+ @logger.info("Listening via: #{Listen::Adapter.select.inspect}")
68
+ listener_callback = method(:callback).to_proc.curry[paths]
69
+ listener = Listen.to(*paths.keys, &listener_callback)
70
+
71
+ # Create the callback that lets us know when we've been interrupted
72
+ queue = Queue.new
73
+ callback = lambda do
74
+ # This needs to execute in another thread because Thread
75
+ # synchronization can't happen in a trap context.
76
+ Thread.new { queue << true }
77
+ end
78
+
79
+ # Run the listener in a busy block so that we can cleanly
80
+ # exit once we receive an interrupt.
81
+ Vagrant::Util::Busy.busy(callback) do
82
+ listener.start
83
+ queue.pop
84
+ listener.stop if listener.listen?
85
+ end
86
+
87
+ return 0
88
+ end
89
+
90
+ def callback(paths, modified, added, removed)
91
+
92
+ @logger.info("File change callback called!")
93
+ @logger.info(" - Modified: #{modified.inspect}")
94
+ @logger.info(" - Added: #{added.inspect}")
95
+ @logger.info(" - Removed: #{removed.inspect}")
96
+
97
+ @changes.each do |rel_path, time|
98
+ @changes.delete(rel_path) if time < Time.now.to_i - 1
99
+ end
100
+
101
+ paths.each do |hostpath, folder|
102
+
103
+ modified.each do |file|
104
+
105
+ if file.start_with?(hostpath)
106
+
107
+ rel_path = file.sub(hostpath, '')
108
+
109
+ if @changes[rel_path] && @changes[rel_path] > Time.now.to_i - 1
110
+ @logger.info("#{rel_path} was changed less than a second ago, skipping")
111
+ next
112
+ end
113
+
114
+ @changes[rel_path] = Time.now.to_i
115
+ folder[:machine].ui.info("fsnotify: Changed: #{rel_path}")
116
+
117
+ guestpath = File.join(folder[:opts][:guestpath], rel_path)
118
+ folder[:machine].communicate.execute("touch #{guestpath}")
119
+
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ rescue => e
127
+ @logger.error("#{e}: #{e.message}")
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,23 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The vagrant-fsnotify plugin must be run within Vagrant."
5
+ end
6
+
7
+ if Vagrant::VERSION < "1.5"
8
+ raise "The vagrant-fsnotify plugin is only compatible with Vagrant 1.5+"
9
+ end
10
+
11
+ module VagrantPlugins::Fsnotify
12
+
13
+ class Plugin < Vagrant.plugin("2")
14
+ name "vagrant-fsnotify"
15
+
16
+ command "fsnotify" do
17
+ require_relative "command-fsnotify"
18
+ Command
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Fsnotify
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-fsnotify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-fsnotify"
8
+ spec.version = VagrantPlugins::Fsnotify::VERSION
9
+ spec.authors = ["Adrien Kohlbecker"]
10
+ spec.email = ["adrien.kohlbecker@gmail.com"]
11
+ spec.summary = "Forward filesystem change notifications to your Vagrant VM"
12
+ spec.description = "Use vagrant-fsnotify to forward filesystem change notifications to your Vagrant VM"
13
+ spec.homepage = "https://github.com/adrienkohlbecker/vagrant-fsnotify"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "listen", "~> 2.7.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-fsnotify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Kohlbecker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: listen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Use vagrant-fsnotify to forward filesystem change notifications to your
56
+ Vagrant VM
57
+ email:
58
+ - adrien.kohlbecker@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - Vagrantfile
69
+ - lib/vagrant-fsnotify.rb
70
+ - lib/vagrant-fsnotify/command-fsnotify.rb
71
+ - lib/vagrant-fsnotify/plugin.rb
72
+ - lib/vagrant-fsnotify/version.rb
73
+ - vagrant-fsnotify.gemspec
74
+ homepage: https://github.com/adrienkohlbecker/vagrant-fsnotify
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Forward filesystem change notifications to your Vagrant VM
98
+ test_files: []