vagrant-remove-old-box-versions 1.1.0 → 1.2.0
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 +4 -4
- data/.gitignore +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +52 -46
- data/Rakefile +0 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/lib/vagrant-remove-old-box-versions.rb +0 -0
- data/lib/vagrant-remove-old-box-versions/command.rb +152 -130
- data/lib/vagrant-remove-old-box-versions/plugin.rb +0 -0
- data/lib/vagrant-remove-old-box-versions/version.rb +1 -1
- data/vagrant-remove-old-box-versions.gemspec +0 -0
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d557df95662f148d0aa48bb4e2c59e49d5a6e2
|
4
|
+
data.tar.gz: 42066707f08dfe2818f59782b09e2d0b0131327d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d48150cabceb04b58f736e6a33bfa5b24a2449efce85d8c1d1d8eed230188786f48b6b25c0893387ce4c7744f8902e0d97e2f9a0a2fb713d238d55b20c81331
|
7
|
+
data.tar.gz: 9fd7a3746c9aef86d8c3a5970864f3b2f6b1ae1a9382e53947f4ec7a243393c051d1a0486280395304cf82a0473ae42fefda3abfcb4e31fe94f88a069e099378
|
data/.gitignore
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,46 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
```
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
1
|
+
**The code for this plugin has been merged into Vagrant and is released in `1.9.0`. The command is ``vagrant box prune``. See the [pull request](https://github.com/mitchellh/vagrant/pull/7978).**
|
2
|
+
|
3
|
+
# Vagrant remove old box versions plugin
|
4
|
+
|
5
|
+
This plugin enables you to automatically remove old vagrant boxes from you host. Just run ``vagrant remove-old-versions`` and it will check your downloaded boxes and remove every box that is not the lastest downloaded version.
|
6
|
+
|
7
|
+
Internally it uses ```vagrant box list``` to get a list of boxes, and ```vagrant box remove --box-version xxx --provider xxx``` so it still has all safeguards you expect from vagrant.
|
8
|
+
|
9
|
+
[](https://badge.fury.io/rb/vagrant-remove-old-box-versions) [](https://rubygems.org/gems/vagrant-remove-old-box-versions)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```
|
14
|
+
vagrant plugin install vagrant-remove-old-box-versions
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```
|
20
|
+
Usage: vagrant remove-old-versions [options]
|
21
|
+
|
22
|
+
Options:
|
23
|
+
|
24
|
+
-p, --provider PROVIDER The specific provider type for the boxes to destroy.
|
25
|
+
-n, --dry-run Only print the boxes that would be removed.
|
26
|
+
--name NAME The specific box name to destroy.
|
27
|
+
-f, --force Destroy without confirmation even when box is in use.
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
This plugin is built and maintained by [Björn Brala](https://www.swis.nl/over-ons/bjorn-brala)
|
33
|
+
Bug reports and pull requests are welcome on GitHub at [swisnl/vagrant-remove-old-box-versions](https://github.com/swisnl/vagrant-remove-old-box-versions).
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
40
|
+
## Changelog
|
41
|
+
|
42
|
+
### [1.2.0] 2016-12-09
|
43
|
+
|
44
|
+
* This plugin was merged into Vagrant. Added deprecation message.
|
45
|
+
|
46
|
+
### [1.1.0] 2016-03-16
|
47
|
+
|
48
|
+
* `---dry-run` and `--name` option added by @danielpanteleit
|
49
|
+
|
50
|
+
### [1.0.0] 2016-01-13
|
51
|
+
|
52
|
+
* Initial release.
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
File without changes
|
@@ -1,130 +1,152 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
boxes
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module RemoveOldVersions
|
6
|
+
class Command < Vagrant.plugin("2", :command)
|
7
|
+
def self.synopsis
|
8
|
+
'remove all but the latest installed boxes'
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
|
13
|
+
vagrant_version = Gem::Version.new(Vagrant::VERSION)
|
14
|
+
unless Gem::Requirement.new('< 1.9.0').satisfied_by?(vagrant_version)
|
15
|
+
@env.ui.warn('This plugin has been merged into Vagrant 1.9.0, please use the command: ');
|
16
|
+
puts
|
17
|
+
@env.ui.warn("'vagrant box prune'");
|
18
|
+
puts
|
19
|
+
|
20
|
+
# Ask the user if we should do this
|
21
|
+
stack = Vagrant::Action::Builder.new.tap do |b|
|
22
|
+
b.use Vagrant::Action::Builtin::Confirm, 'Are you sure you want to use this deprecated method? [yN] ', false
|
23
|
+
end
|
24
|
+
|
25
|
+
result = @env.action_runner.run(stack)
|
26
|
+
if !result[:result]
|
27
|
+
@env.ui.info('Command aborted.');
|
28
|
+
return
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
options = {}
|
34
|
+
options[:force] = false
|
35
|
+
options[:dry_run] = false
|
36
|
+
|
37
|
+
opts = OptionParser.new do |o|
|
38
|
+
o.banner = "Usage: vagrant remove-old-versions [options]"
|
39
|
+
o.separator ""
|
40
|
+
o.separator "Options:"
|
41
|
+
o.separator ""
|
42
|
+
|
43
|
+
o.on("-p PROVIDER", "--provider PROVIDER", String, "The specific provider type for the boxes to destroy.") do |p|
|
44
|
+
options[:provider] = p
|
45
|
+
end
|
46
|
+
|
47
|
+
o.on("-n", "--dry-run", "Only print the boxes that would be removed.") do |f|
|
48
|
+
options[:dry_run] = f
|
49
|
+
end
|
50
|
+
|
51
|
+
o.on("--name NAME", String, "The specific box name to destroy.") do |name|
|
52
|
+
options[:name] = name
|
53
|
+
end
|
54
|
+
|
55
|
+
o.on("-f", "--force", "Destroy without confirmation even when box is in use.") do |f|
|
56
|
+
options[:force] = f
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Parse the options
|
61
|
+
argv = parse_options(opts)
|
62
|
+
return if !argv
|
63
|
+
|
64
|
+
boxes = @env.boxes.all.sort
|
65
|
+
if boxes.empty?
|
66
|
+
return @env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), prefix: false)
|
67
|
+
end
|
68
|
+
|
69
|
+
delete_oldest_boxes(boxes, options[:provider], options[:force], options[:name], options[:dry_run])
|
70
|
+
|
71
|
+
# Success, exit status 0
|
72
|
+
0
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def delete_oldest_boxes(boxes, only_provider, skip_confirm, only_name, dry_run)
|
78
|
+
# Find the longest box name
|
79
|
+
longest_box = boxes.max_by { |x| x[0].length }
|
80
|
+
longest_box_length = longest_box[0].length
|
81
|
+
|
82
|
+
# Hash map to keep track of newest versions
|
83
|
+
newest_boxes = Hash.new
|
84
|
+
|
85
|
+
# First find the newest version for every installed box
|
86
|
+
boxes.each do |name, version, provider|
|
87
|
+
next if only_provider and only_provider != provider.to_s
|
88
|
+
next if only_name and only_name != name
|
89
|
+
|
90
|
+
# Nested to make sure it works for boxes with different providers
|
91
|
+
if newest_boxes.has_key?(name)
|
92
|
+
if newest_boxes[name].has_key?(provider)
|
93
|
+
saved = Gem::Version.new(newest_boxes[name][provider])
|
94
|
+
current = Gem::Version.new(version)
|
95
|
+
if current > saved
|
96
|
+
newest_boxes[name][provider] = version
|
97
|
+
end
|
98
|
+
else
|
99
|
+
newest_boxes[name][provider] = version
|
100
|
+
end
|
101
|
+
else
|
102
|
+
newest_boxes[name] = Hash.new
|
103
|
+
newest_boxes[name][provider] = version
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
@env.ui.info("The following boxes will be kept...");
|
108
|
+
newest_boxes.each do |name, providers|
|
109
|
+
providers.each do |provider, version|
|
110
|
+
@env.ui.info("#{name.ljust(longest_box_length)} (#{provider}, #{version})")
|
111
|
+
|
112
|
+
@env.ui.machine("box-name", name)
|
113
|
+
@env.ui.machine("box-provider", provider)
|
114
|
+
@env.ui.machine("box-version", version)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
@env.ui.info("", prefix: false)
|
119
|
+
@env.ui.info("Checking for older boxes...");
|
120
|
+
|
121
|
+
# Track if we removed anything so the user can be informed
|
122
|
+
removed_any_box = false
|
123
|
+
boxes.each do |name, version, provider|
|
124
|
+
next if !newest_boxes.has_key?(name) or !newest_boxes[name].has_key?(provider)
|
125
|
+
|
126
|
+
current = Gem::Version.new(version)
|
127
|
+
saved = Gem::Version.new(newest_boxes[name][provider])
|
128
|
+
if current < saved
|
129
|
+
removed_any_box = true
|
130
|
+
|
131
|
+
# Use the remove box action
|
132
|
+
if dry_run
|
133
|
+
@env.ui.info("would remove #{name} #{provider} #{version}")
|
134
|
+
else
|
135
|
+
@env.action_runner.run(Vagrant::Action.action_box_remove, {
|
136
|
+
box_name: name,
|
137
|
+
box_provider: provider,
|
138
|
+
box_version: version,
|
139
|
+
force_confirm_box_remove: skip_confirm,
|
140
|
+
box_remove_all_versions: false,
|
141
|
+
})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if !removed_any_box
|
147
|
+
@env.ui.info("No old versions of boxes to remove...");
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-remove-old-box-versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bjorn Brala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,9 +61,7 @@ files:
|
|
61
61
|
- lib/vagrant-remove-old-box-versions/command.rb
|
62
62
|
- lib/vagrant-remove-old-box-versions/plugin.rb
|
63
63
|
- lib/vagrant-remove-old-box-versions/version.rb
|
64
|
-
- pkg/vagrant-remove-old-box-versions-
|
65
|
-
- pkg/vagrant-remove-old-box-versions-0.0.2.gem
|
66
|
-
- pkg/vagrant-remove-old-box-versions-1.0.0.gem
|
64
|
+
- pkg/vagrant-remove-old-box-versions-1.2.0.gem
|
67
65
|
- vagrant-remove-old-box-versions.gemspec
|
68
66
|
homepage: https://github.com/swisnl/vagrant-remove-old-box-versions
|
69
67
|
licenses:
|
@@ -85,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
83
|
version: '0'
|
86
84
|
requirements: []
|
87
85
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.4.
|
86
|
+
rubygems_version: 2.4.5.2
|
89
87
|
signing_key:
|
90
88
|
specification_version: 4
|
91
89
|
summary: This plugin enables you to remove all but the latest installed boxes.
|