vagrant-tools 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 223938120159ab83c8dcbd85f7b159cf985cd966
4
- data.tar.gz: 116911824dbf2fe3b9b9290da10f9e73ff8b02d4
3
+ metadata.gz: b5ed01a07ce8a97adc20e1e6fb20e30d8f1334cc
4
+ data.tar.gz: f57c0f59cb1f0307610a21c6d2807144118fe792
5
5
  SHA512:
6
- metadata.gz: f12b48fad246a5c6bfe7ddefb1d989ecaa49d4a228f0b6bfe44f8af2745d49f8e9723fb9eab143eb09acc5f2d735b01046a035fbf4ae1c70636e86e327e47f70
7
- data.tar.gz: 4efa91af35cb46613d1e4aad748b47f44728b73983f89a0c1895c992d0db6d117ef3aa04af481aef14196f181bf56e5cdd65eca7d73effec5aa8907b80b9f75c
6
+ metadata.gz: a107c36cc992c367db116b2a6f560419453a8cb3dc13e449a0866cf317107399b82e048d903ca982d5f42ee60cab2eca3b3eddf4d497ad30dd15ec898d3badc7
7
+ data.tar.gz: aed44e14e4f3d9a64cb028ac3fbfaeaf8a6c77f2ee699bbaf964d07f0dbd6bebd3d4a83c2518e3b5288087cbff5be63873d702ecc63796e7dc4fc3cdb87a5818
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+ - ruby-head
6
+ before_install:
7
+ - gem update --system
8
+ - gem --version
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Vagrant cli configuration management tool. The missing tool for vagrant that allows you to control all your vagrant instances. Use cli command: `vgls` to list all vagrant configs (all Vagrantfiles), and `vgctl [target] [vgcmd]` to control configurations from outside the Vagrantfile dir.
4
4
 
5
+ [![Build Status](https://travis-ci.org/dblommesteijn/vagrant-tools.svg?branch=master)](https://travis-ci.org/dblommesteijn/vagrant-tools) [![Code Climate](https://codeclimate.com/github/dblommesteijn/vagrant-tools.png)](https://codeclimate.com/github/dblommesteijn/vagrant-tools) [![Dependency Status](https://gemnasium.com/dblommesteijn/vagrant-tools.svg)](https://gemnasium.com/dblommesteijn/vagrant-tools)
6
+
5
7
  **Example**
6
8
 
7
9
  ```bash
@@ -47,7 +49,9 @@ $ vgctl some-project destroy testing
47
49
 
48
50
  * Current/ Master
49
51
 
50
- * stub
52
+ * Fix indexing new Vagrantfile configuration [#1](https://github.com/dblommesteijn/vagrant-tools/issues/1)
53
+ * Fix VERSION variable warning
54
+ * Fix skip empty process cmdline
51
55
 
52
56
 
53
57
  ## Installation
@@ -93,8 +97,8 @@ vgctl
93
97
  Verbose, this will output operations to STDOUT
94
98
 
95
99
  ```bash
96
- vgls -v
97
- vgctl -v
100
+ vgls -V
101
+ vgctl -V
98
102
  ```
99
103
 
100
104
  Change target configuration (find operation), base from where .vagrant configs are discovered:
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/unit/*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: [:build, :install]
data/bin/vgctl CHANGED
@@ -18,10 +18,11 @@ def main()
18
18
  begin
19
19
  opts = GetoptLong.new(
20
20
  ['--prefix', '-p', GetoptLong::REQUIRED_ARGUMENT],
21
- ['--verbose', '-v', GetoptLong::NO_ARGUMENT],
21
+ ['--verbose', '-V', GetoptLong::NO_ARGUMENT],
22
22
  ['--refresh-cache', '-x', GetoptLong::NO_ARGUMENT],
23
23
  ['--only-active', '-a', GetoptLong::NO_ARGUMENT],
24
24
  ['--help', '-h', GetoptLong::NO_ARGUMENT],
25
+ ['--version', '-v', GetoptLong::NO_ARGUMENT],
25
26
  )
26
27
  opts.each do |opt, arg|
27
28
  case opt
@@ -48,6 +49,9 @@ usage: vgctl [-pvxhc] [TARGET [COMMAND | shell]]
48
49
  h : show this help message
49
50
  EOF
50
51
  exit
52
+ when '--version'
53
+ print "vagrant-tools: %s\r\n" % Vagrant::Tools::VERSION
54
+ exit
51
55
  else
52
56
  puts "extra: " + opt + "|" + arg
53
57
  end
data/bin/vgls CHANGED
@@ -19,12 +19,13 @@ def main()
19
19
  begin
20
20
  opts = GetoptLong.new(
21
21
  ['--prefix', '-p', GetoptLong::REQUIRED_ARGUMENT],
22
- ['--verbose', '-v', GetoptLong::NO_ARGUMENT],
22
+ ['--verbose', '-V', GetoptLong::NO_ARGUMENT],
23
23
  ['--refresh-cache', '-x', GetoptLong::NO_ARGUMENT],
24
24
  ['--only-active', '-a', GetoptLong::NO_ARGUMENT],
25
25
  ['--zombies', '-z', GetoptLong::NO_ARGUMENT],
26
- ['--vagrantfile', '-V', GetoptLong::NO_ARGUMENT],
26
+ ['--vagrantfile', '-F', GetoptLong::NO_ARGUMENT],
27
27
  ['--help', '-h', GetoptLong::NO_ARGUMENT],
28
+ ['--version', '-v', GetoptLong::NO_ARGUMENT],
28
29
  )
29
30
  opts.each do |opt, arg|
30
31
  case opt
@@ -46,7 +47,7 @@ def main()
46
47
  vgls, version: #{Vagrant::Tools::VERSION}
47
48
 
48
49
  usage: vgls [-pvxh] [TARGET]
49
-
50
+
50
51
  p : set lookup prefix (default $HOME)
51
52
  v : verbose output
52
53
  x : refresh cached results (.vagrant lookup)
@@ -58,6 +59,9 @@ usage: vgls [-pvxh] [TARGET]
58
59
  h : show this help message
59
60
  EOF
60
61
  exit
62
+ when '--version'
63
+ print "vagrant-tools: %s\r\n" % Vagrant::Tools::VERSION
64
+ exit
61
65
  end
62
66
  end
63
67
  rescue GetoptLong::InvalidOption => e
@@ -165,10 +169,10 @@ usage: vgls [-pvxh] [TARGET]
165
169
  output.append("-- Vagrantfile (#{node.vagrantfile}): ---------------------")
166
170
  output.append(node.vagrantfile_contents)
167
171
  end
168
- else
172
+ else
169
173
  # print all nodes
170
174
  if node.is_a?(Vagrant::Tools::Orm::Config)
171
- output.append(node)
175
+ output.append(node) if !node.hidden
172
176
  elsif node.is_a?(Vagrant::Tools::Orm::Machine)
173
177
  output.append("- #{node.name} ", :nonewline)
174
178
  elsif node.is_a?(Vagrant::Tools::Orm::Provider)
@@ -178,7 +182,7 @@ usage: vgls [-pvxh] [TARGET]
178
182
  end
179
183
 
180
184
  # append cache status
181
- if root.cache.cache_old?
185
+ if root.cache.cache_old? && !cfg.refresh_cache
182
186
  a = root.cache.cache_time_a
183
187
  output.append("cache is %dd, %dh, %dm, and %ds old (consider refreshing -x)" % a)
184
188
  elsif cfg.verbose
data/lib/vagrant/tools.rb CHANGED
@@ -1,7 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/tools/version")
1
2
  require File.expand_path(File.dirname(__FILE__) + "/tools/config")
2
3
  require File.expand_path(File.dirname(__FILE__) + "/tools/cache")
3
4
  require File.expand_path(File.dirname(__FILE__) + "/tools/root")
4
- require File.expand_path(File.dirname(__FILE__) + "/tools/version")
5
5
  require File.expand_path(File.dirname(__FILE__) + "/tools/output")
6
6
  require File.expand_path(File.dirname(__FILE__) + "/tools/helper")
7
7
  require File.expand_path(File.dirname(__FILE__) + "/tools/orm/config")
@@ -3,14 +3,17 @@ module Vagrant
3
3
 
4
4
  class Cache
5
5
 
6
+ CACHE_VERSION = "#{Vagrant::Tools::VERSION}a"
7
+
6
8
  # attr_accessor :prefix, :verbose, :output, :options, :target, :cmd
7
9
  PATH = "#{ENV["HOME"]}/.vagrant-tools"
8
10
 
9
- def initialize(path = PATH)
11
+ def initialize(output, path = PATH)
12
+ @output = output
10
13
  @path = path
11
14
  @cfg = Vagrant::Tools.get_config
12
15
  unless File.exists?(@path)
13
- puts "creating `#{path}`" if @cfg.verbose
16
+ @output.append("creating `#{path}`", :verbose)
14
17
  FileUtils.mkpath(@path)
15
18
  end
16
19
  @filename = "#{@path}/settings.json"
@@ -20,24 +23,33 @@ module Vagrant
20
23
  def get_config
21
24
  return {} unless File.exists?(@filename)
22
25
  begin
23
- puts "reading cache file: `#{@filename}`" if @cfg.verbose
26
+ @output.append("reading cache file: `#{@filename}`", :verbose)
24
27
  json = JSON.parse(File.read(@filename), {symbolize_names: true})
28
+ if json.include?(:version)
29
+ raise "old config version" if json[:version] != CACHE_VERSION
30
+ else
31
+ raise "old config version"
32
+ end
25
33
  c_time = Time.at(json[:configs_date])
26
- puts "cache time: `#{c_time}`" if @cfg.verbose
34
+ @output.append("cache time: `#{c_time}`", :verbose)
27
35
  @delta = Cache.time_delta(c_time) #if json.include?(:configs_date)
28
36
  return json[:configs]
29
37
  rescue Exception => e
30
- puts e.message
31
- puts e
38
+ @output.append(e.message)
39
+ @output.append(e)
40
+ @output.flush()
32
41
  return {}
33
42
  end
34
43
  end
35
44
 
36
45
  def set_config(dirs)
37
- puts "writing to `#{@filename}`" if @cfg.verbose
38
- config_paths = { configs_date: Time.now.to_i, configs: dirs.flat_map{|k,v| v.map(&:config_path)} }
46
+ @output.append("writing to `#{@filename}`", :verbose)
47
+ config_paths = {}
48
+ config_paths[:version] = CACHE_VERSION
49
+ config_paths[:configs_date] = Time.now.to_i
50
+ config_paths[:configs] = dirs.flat_map{|k,v| v.map(&:config_path)}
39
51
  flat_json = JSON.pretty_generate(config_paths)
40
- puts flat_json if @cfg.verbose
52
+ @output.append(flat_json, :verbose)
41
53
  File.open(@filename,"w") do |f|
42
54
  f.write(flat_json)
43
55
  end
@@ -48,8 +60,8 @@ module Vagrant
48
60
  end
49
61
 
50
62
  def cache_time_a
51
- mm, ss = @delta.divmod(60)
52
- hh, mm = mm.divmod(60)
63
+ mm, ss = @delta.divmod(60)
64
+ hh, mm = mm.divmod(60)
53
65
  dd, hh = hh.divmod(24)
54
66
  [dd, hh, mm, ss]
55
67
  end
@@ -8,19 +8,17 @@ module Vagrant
8
8
 
9
9
  ENV_SHELL = ENV["SHELL"]
10
10
 
11
- attr_accessor :name, :project_root, :offset, :config_path, :vagrantfile, :parent
11
+ attr_accessor :name, :project_root, :offset, :config_path, :vagrantfile, :parent, :hidden
12
12
 
13
13
  def initialize(cfg, output, parent, config_path)
14
14
  @cfg = cfg
15
15
  @output = output
16
16
  self.parent = parent
17
17
  self.config_path = config_path
18
+ self.hidden = self.hidden_path?(config_path)
18
19
  self.project_root = File.absolute_path("#{config_path}/../")
19
20
  self.vagrantfile = File.absolute_path("#{self.project_root}/Vagrantfile")
20
- @machines = Dir["#{self.config_path}/machines/*"].flat_map{|t| Machine.new(@cfg, @output, self, t)}
21
- self.name = File.basename(File.absolute_path("#{config_path}/../"))
22
- self.offset = 0
23
- @output.append("found config: `#{self.config_path}`", :verbose)
21
+ self.populate_machine_list
24
22
  end
25
23
 
26
24
  def project_root_name
@@ -32,7 +30,9 @@ module Vagrant
32
30
  "#{self.project_root_name}#{o}"
33
31
  end
34
32
 
35
- def exec_vagrant_command(command)
33
+ def exec_vagrant_command(command, options=[])
34
+ options = [options] unless options.is_a?(Array)
35
+ silent = options.include?(:silent) ? " > /dev/null" : ""
36
36
  # TODO: add some cmd check?
37
37
  cmd = ""
38
38
  case command
@@ -40,7 +40,7 @@ module Vagrant
40
40
  raise "no shell found (in $SHELL)" if ENV_SHELL.nil? || ENV_SHELL == ""
41
41
  cmd = "(cd #{self.project_root} && #{ENV_SHELL})"
42
42
  else
43
- cmd = "(cd #{self.project_root} && vagrant #{command})"
43
+ cmd = "(cd #{self.project_root} && vagrant #{command}#{silent})"
44
44
  end
45
45
  @output.append(cmd, :verbose)
46
46
  # system call to command
@@ -68,6 +68,12 @@ module Vagrant
68
68
  "#{self.project_root_name_with_offset} (#{@project_root})"
69
69
  end
70
70
 
71
+ def hidden_path?(config_path)
72
+ @output.append("check hidden path? `#{config_path}`", :verbose)
73
+ @output.flush()
74
+ !config_path.match(/\/\.[\w]+/).nil?
75
+ end
76
+
71
77
  def to_outputs
72
78
  machines = @machines.map(&:to_outputs).join("")
73
79
  if !@cfg.output[:only_active]
@@ -88,6 +94,28 @@ module Vagrant
88
94
 
89
95
  protected
90
96
 
97
+ def get_machine_paths()
98
+ target = "#{self.project_root}/.vagrant/machines"
99
+ return [] if !File.exists?(target)
100
+ Dir["#{target}/*"]
101
+ end
102
+
103
+ def populate_machine_list
104
+ machine_paths = self.get_machine_paths()
105
+ @output.append("machine dirs found: #{machine_paths.size}", :verbose)
106
+ # lookup if machines path is created (else run vagrant status)
107
+ if !self.hidden && @cfg.refresh_cache
108
+ @output.append("reloading machine paths `vagrant status`", :verbose)
109
+ # create machines path
110
+ self.exec_vagrant_command("status", :silent)
111
+ machine_paths = self.get_machine_paths()
112
+ end
113
+ @machines = machine_paths.flat_map{|t| Machine.new(@cfg, @output, self, t)}
114
+ self.name = File.basename(File.absolute_path("#{config_path}/../"))
115
+ self.offset = 0
116
+ @output.append("found config: `#{self.config_path}`", :verbose)
117
+ end
118
+
91
119
  end
92
120
 
93
121
  end
@@ -31,6 +31,7 @@ module Vagrant
31
31
  def process
32
32
  return @process if !@process.nil? || self.id.nil?
33
33
  Helper.iterate_processes do |p|
34
+ next if p.cmdline.nil?
34
35
  @process = p if p.cmdline.include?(self.id)
35
36
  end
36
37
  @process
@@ -31,6 +31,11 @@ module Vagrant
31
31
  end
32
32
  end
33
33
 
34
+ def flush()
35
+ self.render()
36
+ @buffer = []
37
+ end
38
+
34
39
  end
35
40
  end
36
41
  end
@@ -8,20 +8,16 @@ module Vagrant
8
8
 
9
9
  attr_accessor :cache
10
10
 
11
- LOOKUP_DIR = ".vagrant"
11
+ LOOKUP_DIR = "Vagrantfile"
12
12
 
13
13
  def initialize(cfg, output)
14
14
  @cfg = cfg
15
15
  @output = output
16
16
  @dirs = {}
17
- self.cache = Cache.new
17
+ self.cache = Cache.new(@output)
18
18
  self.find_vagrant_configs
19
19
  end
20
20
 
21
- # def find_by_project_root(project_root_name)
22
- # self.get_config_without_offset(project_root_name)
23
- # end
24
-
25
21
  def find_vagrant_configs
26
22
  unless @dirs.empty?
27
23
  @output.append("config already loaded (use -x to force reload)", :verbose)
@@ -36,46 +32,12 @@ module Vagrant
36
32
  # create new config instance
37
33
  self.add_config_dirs(config)
38
34
  end
39
- return self
35
+ return self
40
36
  end
41
- # findin configs via find
42
- cmd = "find \"#{prefix}\" -type d -name \"#{LOOKUP_DIR}\""
43
- @output.append("finding vagrant configs: `#{cmd}`...", :verbose)
44
- Open3.popen3(cmd) do |stdin, stdout, stderr|
45
- stdin.close_write
46
- stdout.read.split("\n").each do |config_file|
47
- # create new config instance
48
- self.add_config_dirs(config_file)
49
- end
50
- stderr.close_read
51
- end
52
- self.cache.set_config(@dirs)
37
+ self.find_configs(prefix)
53
38
  self
54
39
  end
55
40
 
56
- # def to_outputs
57
- # ret = []
58
- # if @cfg.target.nil?
59
- # # print all
60
- # ret << @dirs.flat_map{|k,t| t.map(&:to_outputs)}
61
- # else
62
- # ret << self.get_config_without_offset(@cfg.target).to_outputs
63
- # end
64
- # ret.join
65
- # end
66
-
67
- # if @cfg.target.nil?
68
- # configs = @dirs.flat_map{|k,t| t}
69
- # else
70
- # configs = [self.get_config_without_offset(@cfg.target)]
71
- # end
72
-
73
- # # filter `target`
74
- # elsif !cfg.target.nil?
75
- # if node.is_a?(Vagrant::Tools::Orm::Root)
76
- # nodes << node
77
- # end
78
-
79
41
  def visit(&block)
80
42
  configs = @dirs.flat_map{|k,t| t}
81
43
  block.call(self)
@@ -96,8 +58,6 @@ module Vagrant
96
58
  false
97
59
  end
98
60
 
99
-
100
-
101
61
  protected
102
62
 
103
63
  def add_config_dirs(config)
@@ -109,6 +69,22 @@ module Vagrant
109
69
  nil
110
70
  end
111
71
 
72
+ def find_configs(prefix)
73
+ # findin configs via find
74
+ cmd = "find \"#{prefix}\" -type f -name \"#{LOOKUP_DIR}\""
75
+ @output.append("finding vagrant configs: `#{cmd}`...", :verbose)
76
+ @output.flush()
77
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
78
+ stdin.close_write
79
+ stdout.read.split("\n").each do |config_file|
80
+ # create new config instance
81
+ self.add_config_dirs(config_file)
82
+ end
83
+ stderr.close_read
84
+ end
85
+ self.cache.set_config(@dirs)
86
+ end
87
+
112
88
  end
113
89
  end
114
90
  end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Tools
3
- VERSION = "0.1.1"
3
+ VERSION ||= "0.1.2"
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'coveralls'
4
+ Coveralls.wear!
@@ -0,0 +1,11 @@
1
+
2
+ require 'test_helper'
3
+
4
+ class Defaults < Test::Unit::TestCase
5
+
6
+ def test_me
7
+ assert true, "always true!"
8
+ end
9
+
10
+ end
11
+
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Blommesteijn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-proctable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>'
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>'
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Vagrant CLI configuration management tool for Unix
@@ -61,7 +61,8 @@ executables:
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
64
+ - ".gitignore"
65
+ - ".travis.yml"
65
66
  - Gemfile
66
67
  - LICENSE.txt
67
68
  - README.md
@@ -78,6 +79,8 @@ files:
78
79
  - lib/vagrant/tools/output.rb
79
80
  - lib/vagrant/tools/root.rb
80
81
  - lib/vagrant/tools/version.rb
82
+ - test/test_helper.rb
83
+ - test/unit/defaults.rb
81
84
  - vagrant-tools.gemspec
82
85
  homepage: https://github.com/dblommesteijn/vagrant-tools
83
86
  licenses:
@@ -89,18 +92,20 @@ require_paths:
89
92
  - lib
90
93
  required_ruby_version: !ruby/object:Gem::Requirement
91
94
  requirements:
92
- - - '>='
95
+ - - ">="
93
96
  - !ruby/object:Gem::Version
94
97
  version: '0'
95
98
  required_rubygems_version: !ruby/object:Gem::Requirement
96
99
  requirements:
97
- - - '>='
100
+ - - ">="
98
101
  - !ruby/object:Gem::Version
99
102
  version: '0'
100
103
  requirements: []
101
104
  rubyforge_project:
102
- rubygems_version: 2.2.2
105
+ rubygems_version: 2.4.5.1
103
106
  signing_key:
104
107
  specification_version: 4
105
108
  summary: Vagrant CLI configuration management tool for Unix
106
- test_files: []
109
+ test_files:
110
+ - test/test_helper.rb
111
+ - test/unit/defaults.rb