vagrant-remove-old-box-versions 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59ab5f82dba1fbe29fc7dac1c30d334774d1dffe
4
+ data.tar.gz: b17024a631e7b2143a7aa08bf5e5e3441d91b0a1
5
+ SHA512:
6
+ metadata.gz: c357088629dc72b708ea8af6e7d2ec34f4a91940d17cf2e99c059599bab8b716dba7fde0c8343e8ae9880212ce83306461104cf219e629f422b13170749e1f68
7
+ data.tar.gz: 461110200f05f83d9f967f0831d7852b47364706969d6ad2ff55f40d96599e2e90a2257a1274e30a0a1570aa242d8e28a08092411425b8f75a5f4e11ba26f00e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
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"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-remove-old-box-versions", path: "."
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Bjorn Brala
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Vagrant remove old box versions plugin
2
+
3
+ This plugin enables you to automaticly remove old vagrant boxes from you host. Just run ``vagrant remove-old-versions`` and it will check your downloades boxes and remove every box that is not the lastest downloaded version.
4
+
5
+
6
+ ## Installation
7
+
8
+
9
+ ```
10
+ vagrant install plugin vagrant-remove-old-box-versions
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ Usage: vagrant remove-old-versions [options]
17
+
18
+ Options:
19
+
20
+ -p, --provider PROVIDER The specific provider type for the boxes to destroy.
21
+ -f, --force Destroy without confirmation even when box is in use.
22
+ ```
23
+
24
+ ## Contributing
25
+
26
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrant-remove-old-box-versions.
27
+
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
32
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vagrant-remove-old-box-versions/versions"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
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
@@ -0,0 +1,23 @@
1
+ require "pathname"
2
+
3
+ begin
4
+ require 'vagrant'
5
+ rescue LoadError
6
+ Bundler.require(:default, :development)
7
+ end
8
+ require "vagrant-remove-old-box-versions/plugin"
9
+ require "vagrant-remove-old-box-versions/command"
10
+
11
+
12
+ module VagrantPlugins
13
+ module RemoveOldBoxVersions
14
+ lib_path = Pathname.new(File.expand_path("../vagrant-remove-old-box-versions", __FILE__))
15
+
16
+ # This returns the path to the source of this plugin.
17
+ #
18
+ # @return [Pathname]
19
+ def self.source_root
20
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,117 @@
1
+ require 'optparse'
2
+
3
+ module VagrantPlugins
4
+ module RemoveOldVersions
5
+ class Command < Vagrant.plugin("2", :command)
6
+ def self.synopsis
7
+ "stops and deletes all traces of the vagrant machine"
8
+ end
9
+
10
+ def execute
11
+ options = {}
12
+ options[:force] = false
13
+
14
+ opts = OptionParser.new do |o|
15
+ o.banner = "Usage: vagrant remove-old-versions [options]"
16
+ o.separator ""
17
+ o.separator "Options:"
18
+ o.separator ""
19
+
20
+ o.on("-p PROVIDER", "--provider PROVIDER", String, "The specific provider type for the boxes to destroy.") do |p|
21
+ options[:provider] = p
22
+ end
23
+
24
+ o.on("-f", "--force", "Destroy without confirmation even when box is in use.") do |f|
25
+ options[:force] = f
26
+ end
27
+ end
28
+
29
+ # Parse the options
30
+ argv = parse_options(opts)
31
+ return if !argv
32
+
33
+ boxes = @env.boxes.all.sort
34
+ if boxes.empty?
35
+ return @env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), prefix: false)
36
+ end
37
+
38
+ delete_oldest_boxes(boxes, options[:provider], options[:force])
39
+
40
+ # Success, exit status 0
41
+ 0
42
+ end
43
+
44
+ private
45
+
46
+ def delete_oldest_boxes(boxes, only_provider, skip_confirm)
47
+ # Find the longest box name
48
+ longest_box = boxes.max_by { |x| x[0].length }
49
+ longest_box_length = longest_box[0].length
50
+
51
+ # Hash map to keep track of newest versions
52
+ newest_boxes = Hash.new
53
+
54
+ # First find the newest version for every installed box
55
+ boxes.each do |name, version, provider|
56
+ next if only_provider and only_provider != provider.to_s
57
+
58
+ # Nested to make sure it works for boxes with different providers
59
+ if newest_boxes.has_key?(name)
60
+ if newest_boxes[name].has_key?(provider)
61
+ saved = Gem::Version.new(newest_boxes[name][provider])
62
+ current = Gem::Version.new(version)
63
+ if current > saved
64
+ newest_boxes[name][provider] = version
65
+ end
66
+ else
67
+ newest_boxes[name][provider] = version
68
+ end
69
+ else
70
+ newest_boxes[name] = Hash.new
71
+ newest_boxes[name][provider] = version
72
+ end
73
+ end
74
+
75
+ @env.ui.info("The following boxes will be kept...");
76
+ newest_boxes.each do |name, providers|
77
+ providers.each do |provider, version|
78
+ @env.ui.info("#{name.ljust(longest_box_length)} (#{provider}, #{version})")
79
+
80
+ @env.ui.machine("box-name", name)
81
+ @env.ui.machine("box-provider", provider)
82
+ @env.ui.machine("box-version", version)
83
+ end
84
+ end
85
+
86
+ @env.ui.info("", prefix: false)
87
+ @env.ui.info("Checking for older boxes...");
88
+
89
+ # Track if we removed anything so the user can be informed
90
+ removed_any_box = false
91
+ boxes.each do |name, version, provider|
92
+ next if !newest_boxes.has_key?(name) or !newest_boxes[name].has_key?(provider)
93
+
94
+ current = Gem::Version.new(version)
95
+ saved = Gem::Version.new(newest_boxes[name][provider])
96
+ if current < saved
97
+ removed_any_box = true
98
+
99
+ # Use the remove box action
100
+ @env.action_runner.run(Vagrant::Action.action_box_remove, {
101
+ box_name: name,
102
+ box_provider: provider,
103
+ box_version: version,
104
+ force_confirm_box_remove: skip_confirm,
105
+ box_remove_all_versions: false,
106
+ })
107
+
108
+ end
109
+ end
110
+
111
+ if !removed_any_box
112
+ @env.ui.info("No old versions of boxes to remove...");
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,18 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module RemoveOldVersions
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "remove-old-versions"
7
+ description <<-DESC
8
+ This plugin enables you top remove all but the latest installed boxes.
9
+ DESC
10
+
11
+ command("remove-old-versions") do
12
+ require_relative 'command'
13
+ Command
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module RemoveOldVersions
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require lib + '/vagrant-remove-old-box-versions/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "vagrant-remove-old-box-versions"
9
+ spec.version = VagrantPlugins::RemoveOldVersions::VERSION
10
+ spec.authors = ["Bjorn Brala"]
11
+ spec.email = ["bjorn@swis.nl"]
12
+ spec.platform = Gem::Platform::RUBY
13
+
14
+ spec.summary = "This plugin enables you to remove all but the latest installed boxes."
15
+ spec.description = "This plugin enables you to remove all but the latest installed boxes."
16
+ spec.homepage = "https://github.com/bbrala/vagrant-remove-old-box-versions"
17
+ spec.license = "MIT"
18
+
19
+
20
+ # The following block of code determines the files that should be included
21
+ # in the gem. It does this by reading all the files in the directory where
22
+ # this gemspec is, and parsing out the ignored files from the gitignore.
23
+ # Note that the entire gitignore(5) syntax is not supported, specifically
24
+ # the "!" syntax, but it should mostly work correctly.
25
+ root_path = File.dirname(__FILE__)
26
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
27
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
28
+ gitignore_path = File.join(root_path, ".gitignore")
29
+ gitignore = File.readlines(gitignore_path)
30
+ gitignore.map! { |line| line.chomp.strip }
31
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
32
+
33
+ unignored_files = all_files.reject do |file|
34
+ # Ignore any directories, the gemspec only cares about files
35
+ next true if File.directory?(file)
36
+
37
+ # Ignore any paths that match anything in the gitignore. We do
38
+ # two tests here:
39
+ #
40
+ # - First, test to see if the entire path matches the gitignore.
41
+ # - Second, match if the basename does, this makes it so that things
42
+ # like '.DS_Store' will match sub-directories too (same behavior
43
+ # as git).
44
+ #
45
+ gitignore.any? do |ignore|
46
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
47
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
48
+ end
49
+ end
50
+
51
+ spec.files = unignored_files
52
+ spec.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
53
+
54
+ spec.require_paths = ["lib"]
55
+
56
+ spec.add_development_dependency "bundler", "~> 1.10"
57
+ spec.add_development_dependency "rake", "~> 10.0"
58
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-remove-old-box-versions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bjorn Brala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This plugin enables you to remove all but the latest installed boxes.
42
+ email:
43
+ - bjorn@swis.nl
44
+ executables:
45
+ - console
46
+ - setup
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/vagrant-remove-old-box-versions.rb
60
+ - lib/vagrant-remove-old-box-versions/command.rb
61
+ - lib/vagrant-remove-old-box-versions/plugin.rb
62
+ - lib/vagrant-remove-old-box-versions/version.rb
63
+ - vagrant-remove-old-box-versions.gemspec
64
+ homepage: https://github.com/bbrala/vagrant-remove-old-box-versions
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: This plugin enables you to remove all but the latest installed boxes.
88
+ test_files: []