remove_stale_gems 0.0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /pkg/
2
+ /*.gem
3
+
4
+ /doc/
5
+ /rdoc/
6
+ /.yardoc/
7
+ /coverage/
8
+
9
+ Makefile
10
+ *.o
11
+ *.bundle
12
+ /tmp/
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Ivan Kuchin
1
+ Copyright (c) 2010-2011 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -4,4 +4,4 @@ Remove gems for which last use time is too old
4
4
 
5
5
  ## Copyright
6
6
 
7
- Copyright (c) 2010 Ivan Kuchin. See LICENSE.txt for details.
7
+ Copyright (c) 2010-2011 Ivan Kuchin. See LICENSE.txt for details.
@@ -3,50 +3,67 @@ require 'rubygems/uninstaller'
3
3
  class Gem::Commands::RemoveStaleCommand < Gem::Command
4
4
  def initialize
5
5
  super 'remove_stale', 'Remove gems for which last use time is too old'
6
- end
7
6
 
8
- def abandoned?(spec, border_time)
9
- atime = nil
10
- Dir["#{spec.full_gem_path}/**/*.*"].each do |file|
11
- next if File.directory?(file)
12
- stat = File.stat(file)
13
- atime = stat.atime if !atime || atime < stat.atime
7
+ add_option('-y', '--yes', 'Don\'t ask for confirmation') do |value, options|
8
+ options[:yes] = true
9
+ end
10
+
11
+ add_option('-d', '--days DAYS', 'Consider stale after no access for this number of days (Default: 40)') do |value, options|
12
+ options[:days] = value.to_i
14
13
  end
15
- atime && atime < border_time
14
+ end
15
+
16
+ def gem_atime(spec)
17
+ Dir["#{spec.full_gem_path}/**/*.*"].reject do |path|
18
+ File.directory?(path)
19
+ end.map do |path|
20
+ File.stat(path).atime
21
+ end.max
22
+ end
23
+
24
+ def stale_gem?(spec, border_time)
25
+ (atime = gem_atime(spec)) && (atime < border_time)
16
26
  end
17
27
 
18
28
  def execute
19
- border_time = Time.now - 40 * (24 * 60 * 60)
29
+ days = options[:days] || 40
30
+ border_time = Time.now - days * (24 * 60 * 60)
20
31
 
21
- abandoned_gems = []
22
- Gem.source_index.each do |name, spec|
23
- if abandoned?(spec, border_time)
24
- abandoned_gems << spec
25
- end
32
+ stale_gems = Gem::Specification.select do |spec|
33
+ stale_gem?(spec, border_time)
26
34
  end
27
35
 
28
- to_uninstall = abandoned_gems.select do |spec|
36
+ to_uninstall = stale_gems.select do |spec|
29
37
  spec.dependent_gems.all? do |dependent, depency, satlist|
30
- abandoned_gems.include?(dependent) || (satlist - abandoned_gems).length > 0
38
+ stale_gems.include?(dependent) || (satlist - stale_gems).length > 0
31
39
  end
32
40
  end
33
41
 
34
- to_uninstall.each do |spec|
35
- say "Attempting to uninstall #{spec.full_name}"
36
-
37
- uninstall_options = {
38
- :executables => (Gem.source_index.find_name(spec.name) - to_uninstall).length == 0,
39
- :version => "= #{spec.version}",
40
- :ignore => true
41
- }
42
- uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
43
-
44
- begin
45
- uninstaller.uninstall
46
- rescue Gem::DependencyRemovalException, Gem::InstallError,
47
- Gem::GemNotInHomeException => e
48
- say "Unable to uninstall #{spec.full_name}:"
49
- say "\t#{e.class}: #{e.message}"
42
+ if to_uninstall.empty?
43
+ puts 'No stale gems found.'
44
+ else
45
+ puts 'Stale gems:'
46
+ to_uninstall.each do |spec|
47
+ puts " #{spec.full_name}"
48
+ end
49
+ if options[:yes] || ask_yes_no('Remove gems?')
50
+ to_uninstall.each do |spec|
51
+ say "Attempting to uninstall #{spec.full_name}"
52
+
53
+ uninstall_options = {
54
+ :executables => (Gem.source_index.find_name(spec.name) - to_uninstall).length == 0,
55
+ :version => "= #{spec.version}",
56
+ :ignore => true
57
+ }
58
+ uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
59
+
60
+ begin
61
+ uninstaller.uninstall
62
+ rescue Gem::DependencyRemovalException, Gem::InstallError, Gem::GemNotInHomeException => e
63
+ say "Unable to uninstall #{spec.full_name}:"
64
+ say " #{e.class}: #{e.message}"
65
+ end
66
+ end
50
67
  end
51
68
  end
52
69
  end
@@ -1,51 +1,18 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # encoding: UTF-8
5
2
 
6
3
  Gem::Specification.new do |s|
7
- s.name = %q{remove_stale_gems}
8
- s.version = "0.0.1.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ivan Kuchin"]
12
- s.date = %q{2010-12-15}
4
+ s.name = 'remove_stale_gems'
5
+ s.version = '1.0.0'
6
+ s.summary = %q{Remove unused gems}
13
7
  s.description = %q{Remove gems for which last use time is too old}
14
- s.extra_rdoc_files = [
15
- "LICENSE.txt",
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- ".tmignore",
20
- "LICENSE.txt",
21
- "README.markdown",
22
- "Rakefile",
23
- "VERSION",
24
- "lib/remove_stale_gems.rb",
25
- "lib/rubygems/commands/remove_stale_command.rb",
26
- "lib/rubygems_plugin.rb",
27
- "remove_stale_gems.gemspec"
28
- ]
29
- s.homepage = %q{http://github.com/toy/remove_stale_gems}
30
- s.licenses = ["MIT"]
31
- s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.7}
33
- s.summary = %q{Remove unused gems}
8
+ s.homepage = "http://github.com/toy/#{s.name}"
9
+ s.authors = ['Ivan Kuchin']
10
+ s.license = 'MIT'
34
11
 
35
- if s.respond_to? :specification_version then
36
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
- s.specification_version = 3
12
+ s.rubyforge_project = s.name
38
13
 
39
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
41
- s.add_development_dependency(%q<rake-gem-ghost>, [">= 0"])
42
- else
43
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
44
- s.add_dependency(%q<rake-gem-ghost>, [">= 0"])
45
- end
46
- else
47
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
48
- s.add_dependency(%q<rake-gem-ghost>, [">= 0"])
49
- end
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = %w[lib]
50
18
  end
51
-
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remove_stale_gems
3
3
  version: !ruby/object:Gem::Version
4
- hash: 77
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 1
10
- - 3
11
- version: 0.0.1.3
10
+ version: 1.0.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - Ivan Kuchin
@@ -16,59 +15,25 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-12-15 00:00:00 +03:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- name: jeweler
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 1
31
- segments:
32
- - 1
33
- - 5
34
- - 1
35
- version: 1.5.1
36
- type: :development
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: rake-gem-ghost
40
- prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
50
- type: :development
51
- version_requirements: *id002
18
+ date: 2011-12-16 00:00:00 Z
19
+ dependencies: []
20
+
52
21
  description: Remove gems for which last use time is too old
53
22
  email:
54
23
  executables: []
55
24
 
56
25
  extensions: []
57
26
 
58
- extra_rdoc_files:
59
- - LICENSE.txt
60
- - README.markdown
27
+ extra_rdoc_files: []
28
+
61
29
  files:
62
- - .tmignore
30
+ - .gitignore
63
31
  - LICENSE.txt
64
32
  - README.markdown
65
- - Rakefile
66
- - VERSION
67
33
  - lib/remove_stale_gems.rb
68
34
  - lib/rubygems/commands/remove_stale_command.rb
69
35
  - lib/rubygems_plugin.rb
70
36
  - remove_stale_gems.gemspec
71
- has_rdoc: true
72
37
  homepage: http://github.com/toy/remove_stale_gems
73
38
  licenses:
74
39
  - MIT
@@ -97,10 +62,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
62
  version: "0"
98
63
  requirements: []
99
64
 
100
- rubyforge_project:
101
- rubygems_version: 1.3.7
65
+ rubyforge_project: remove_stale_gems
66
+ rubygems_version: 1.8.12
102
67
  signing_key:
103
68
  specification_version: 3
104
69
  summary: Remove unused gems
105
70
  test_files: []
106
71
 
72
+ has_rdoc:
data/.tmignore DELETED
@@ -1 +0,0 @@
1
- /*.gemspec
data/Rakefile DELETED
@@ -1,18 +0,0 @@
1
- require 'rake'
2
- require 'jeweler'
3
- require 'rake/gem_ghost_task'
4
-
5
- name = 'remove_stale_gems'
6
-
7
- Jeweler::Tasks.new do |gem|
8
- gem.name = name
9
- gem.summary = %Q{Remove unused gems}
10
- gem.description = %Q{Remove gems for which last use time is too old}
11
- gem.homepage = "http://github.com/toy/#{name}"
12
- gem.license = 'MIT'
13
- gem.authors = ['Ivan Kuchin']
14
- gem.add_development_dependency 'jeweler', '~> 1.5.1'
15
- gem.add_development_dependency 'rake-gem-ghost'
16
- end
17
- Jeweler::RubygemsDotOrgTasks.new
18
- Rake::GemGhostTask.new
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1.3