package_manager 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,13 +5,15 @@ Unifies the command interface for using yum and apt on Linux, Fink and MacPorts
5
5
  = Commands
6
6
 
7
7
  The following commands are provided:
8
- * pkg-find-available
9
- * pkg-find-installed
10
- * pkg-install
11
- * pkg-install-file
12
- * pkg-list-contents
8
+ * pkg-find-available - list matching packages that are available for installation
9
+ * pkg-find-installed - list matching packages that are installed
10
+ * pkg-install - install the named package
11
+ * pkg-install-file - install a package from a file
12
+ * pkg-list-contents - list the files contained in an installed packages
13
+ * pkg-provides - which pakage installed the given file?
14
+ * pkg-uninstall - remove the named pakage from the system
13
15
 
14
- = Package Management Systems[http://en.wikipedia.org/wiki/Package_management_system]
16
+ = {Package Management Systems}[http://en.wikipedia.org/wiki/Package_management_system]
15
17
 
16
18
  * Fink
17
19
  * Mac Ports
data/Rakefile CHANGED
@@ -17,31 +17,32 @@ RDOC_OPTS = [ '--quiet', '--main', 'README.rdoc', '--inline-source' ]
17
17
  EXECUTABLE_FILENAMES = EXECUTABLES.collect { | file | file.gsub( %r(^bin/), '' ) }
18
18
 
19
19
  spec = Gem::Specification.new do |s|
20
- s.name = 'package_manager'
21
- s.summary = TITLE
22
- s.description = 'Unifies the command interface for using yum and apt on Linux, Fink and MacPorts on OS X'
23
- s.version = PackageManager::VERSION::STRING
24
-
25
- s.homepage = 'http://github.com/joeyates/package_manager'
26
- s.author = 'Joe Yates'
27
- s.email = 'joe.g.yates@gmail.com'
28
-
29
- s.files = ADMIN_FILES +
30
- EXECUTABLES +
31
- SOURCE_FILES
32
- s.executables += EXECUTABLE_FILENAMES
33
- s.require_paths = [ 'lib' ]
20
+ s.name = 'package_manager'
21
+ s.summary = TITLE
22
+ s.description = 'Unifies the command interface for using yum and apt on Linux, Fink and MacPorts on OS X'
23
+ s.version = PackageManager::VERSION::STRING
24
+
25
+ s.homepage = 'http://github.com/joeyates/package_manager'
26
+ s.author = 'Joe Yates'
27
+ s.email = 'joe.g.yates@gmail.com'
28
+ s.rubyforge_project = "nowarning"
29
+
30
+
31
+ s.files = ADMIN_FILES +
32
+ EXECUTABLES +
33
+ SOURCE_FILES
34
+ s.executables += EXECUTABLE_FILENAMES
35
+ s.require_paths = [ 'lib' ]
34
36
  s.add_dependency( 'rake', '>= 0.8.7' )
35
37
 
36
- s.has_rdoc = true
37
- s.rdoc_options += RDOC_OPTS
38
- s.extra_rdoc_files = RDOC_FILES
38
+ s.has_rdoc = true
39
+ s.rdoc_options += RDOC_OPTS
40
+ s.extra_rdoc_files = RDOC_FILES
39
41
 
40
- s.test_files = SPEC_FILES
42
+ s.test_files = SPEC_FILES
41
43
  end
42
44
 
43
- Rake::GemPackageTask.new( spec ) do |pkg|
44
- end
45
+ Rake::GemPackageTask.new( spec ) {}
45
46
 
46
47
  Spec::Rake::SpecTask.new do |t|
47
48
  t.spec_files = FileList[ 'spec/**/*_spec.rb' ]
data/bin/pkg-provides CHANGED
@@ -17,4 +17,4 @@ if ARGV.size < 1
17
17
  end
18
18
 
19
19
  pkg = PackageManager::Base.load
20
- puts pkg.provides( ARGV )
20
+ puts pkg.provides( ARGV[ 0 ] )
@@ -6,7 +6,7 @@ module PackageManager
6
6
  module VERSION #:nodoc:
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 3
9
+ TINY = 4
10
10
 
11
11
  STRING = [ MAJOR, MINOR, TINY ].join('.')
12
12
  end
@@ -53,7 +53,7 @@ module PackageManager
53
53
 
54
54
  # Returns true if the package installed successfully
55
55
  def install_file( file )
56
- raise 'The file '#{ file }' does not exist' if ! File.exist?( file )
56
+ raise "The file '#{ file }' does not exist" if ! File.exist?( file )
57
57
  run_command( install_file_command, file )
58
58
  $?.exitstatus == 0
59
59
  end
@@ -66,7 +66,7 @@ module PackageManager
66
66
 
67
67
  # Returns the package name if found, or an empty string
68
68
  def provides( file )
69
- raise 'The file '#{ file }' does not exist' if ! File.exist?( file )
69
+ raise "The file '#{ file }' does not exist" if ! File.exist?( file )
70
70
  run_command( provides_command, file )
71
71
  end
72
72
 
@@ -77,21 +77,22 @@ module PackageManager
77
77
  end
78
78
 
79
79
  def self.guess_package_manager
80
- case operating_system
80
+ os = operating_system
81
+ case os
81
82
  when 'linux'
82
83
  linux_package_manager
83
84
  when 'darwin'
84
85
  darwin_package_manager
85
86
  else
86
- raise 'Unhandled operating system'
87
+ raise "Unhandled operating system: '#{ os }'"
87
88
  end
88
89
  end
89
90
 
90
91
  def self.operating_system
91
92
  platforms = Gem.platforms
92
- raise 'Unexpected response from Gem.platforms' unless platforms.respond_to?( :size )
93
- raise 'Expected Array of 2 values' unless platforms.size == 2
94
- raise 'Unexpected value returned by Gem.platforms' unless platforms[ 1 ].respond_to?( :os )
93
+ raise 'Unexpected response from Gem.platforms' unless platforms.respond_to?( :size )
94
+ raise 'Expected Array of 2 values' unless platforms.size == 2
95
+ raise 'Unexpected operating system object returned by Gem.platforms' unless platforms[ 1 ].respond_to?( :os )
95
96
  platforms[ 1 ].os
96
97
  end
97
98
 
@@ -17,6 +17,22 @@ module PackageManager
17
17
  "port installed | sed -E -e 's/ +([^ ]+).*/\\1/' | grep "
18
18
  end
19
19
 
20
+ def install_command
21
+ 'port install'
22
+ end
23
+
24
+ def uninstall_command
25
+ 'port uninstall'
26
+ end
27
+
28
+ def provides_command
29
+ 'port provides'
30
+ end
31
+
32
+ def contents_command
33
+ 'port contents'
34
+ end
35
+
20
36
  end
21
37
 
22
38
  end
@@ -0,0 +1,144 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'spec'
3
+
4
+ SPEC_PATH = File.expand_path( File.dirname( __FILE__ ) )
5
+ ROOT_PATH = File.dirname( SPEC_PATH )
6
+ require File.join( ROOT_PATH, 'lib', 'package_manager' )
7
+
8
+ describe 'operating system sensing' do
9
+
10
+ it "should throw an error if Gem.platforms doesn't return an Array" do
11
+ Gem.stub!( :platforms ).and_return( nil )
12
+ lambda do
13
+ pkg = PackageManager::Base.load
14
+ end.should raise_error( StandardError, /Unexpected.*?response/ )
15
+ end
16
+
17
+ it "should throw an error if Gem.platforms doesn't return two values" do
18
+ Gem.stub!( :platforms ).and_return( [] )
19
+ lambda do
20
+ pkg = PackageManager::Base.load
21
+ end.should raise_error( StandardError, /Expected.*?Array.*?2/ )
22
+ end
23
+
24
+ it "should throw an error if Gem.platforms doesn't return two values" do
25
+ Gem.stub!( :platforms ).and_return( [] )
26
+ lambda do
27
+ pkg = PackageManager::Base.load
28
+ end.should raise_error( StandardError, /Expected.*?Array.*?2/ )
29
+ end
30
+
31
+ it "should throw an error if Gem.platforms doesn't return an Object which yields an os" do
32
+ Gem.stub!( :platforms ).and_return( [ nil, nil ] )
33
+ lambda do
34
+ pkg = PackageManager::Base.load
35
+ end.should raise_error( StandardError, /Unexpected operating system object/ )
36
+ end
37
+
38
+ it "should use the os value returned by Gem.platforms" do
39
+ operating_system = stub( 'thing', :os => 'my os' )
40
+ Gem.stub!( :platforms ).and_return( [ nil, operating_system ] )
41
+ lambda do
42
+ pkg = PackageManager::Base.load
43
+ end.should raise_error( StandardError, /my os/ )
44
+ end
45
+
46
+ it 'should throw an error on unknown operating systems' do
47
+ PackageManager::Base.stub!( :operating_system ).and_return( 'foo' )
48
+ lambda do
49
+ pkg = PackageManager::Base.load
50
+ end.should raise_error( StandardError, /Unhandled+.*?operating.*?system/ )
51
+ end
52
+
53
+ end
54
+
55
+ describe 'system interactions' do
56
+
57
+ it 'should use shell calls to determine what is installed' do
58
+ PackageManager::Base.stub!( :operating_system ).and_return( 'linux' )
59
+ `ls` # Force $? is 0
60
+ PackageManager::Base.should_receive( '`'.intern ).with( "which 'apt-get'" ).and_return( '/path/to/apt-get' )
61
+ pkg = PackageManager::Base.load
62
+ pkg.name.should == 'apt'
63
+ end
64
+
65
+ end
66
+
67
+ describe 'Linux package manager guessing' do
68
+
69
+ before( :each ) do
70
+ PackageManager::Base.stub!( :operating_system ).and_return( 'linux' )
71
+ end
72
+
73
+ it 'should always return a PackageManager::Base subclass' do
74
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( true )
75
+ pkg = PackageManager::Base.load
76
+ pkg.should_not be_nil
77
+ end
78
+
79
+ it 'with apt-get available, should return a PackageManager::Apt' do
80
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( true )
81
+ pkg = PackageManager::Base.load
82
+ pkg.class.should == PackageManager::Apt
83
+ end
84
+
85
+ it 'with yum available, should return a PackageManager::Yum' do
86
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( false )
87
+ PackageManager::Base.stub!( :program_installed? ).with( 'yum' ).and_return( true )
88
+ pkg = PackageManager::Base.load
89
+ pkg.class.should == PackageManager::Yum
90
+ end
91
+
92
+ it 'with rpm available, should return a PackageManager::Rpm' do
93
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( false )
94
+ PackageManager::Base.stub!( :program_installed? ).with( 'yum' ).and_return( false )
95
+ PackageManager::Base.stub!( :program_installed? ).with( 'rpm' ).and_return( true )
96
+ pkg = PackageManager::Base.load
97
+ pkg.class.should == PackageManager::Rpm
98
+ end
99
+
100
+ it 'with no known package manager available, should raise an error' do
101
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( false )
102
+ PackageManager::Base.stub!( :program_installed? ).with( 'yum' ).and_return( false )
103
+ PackageManager::Base.stub!( :program_installed? ).with( 'rpm' ).and_return( false )
104
+ lambda do
105
+ pkg = PackageManager::Base.load
106
+ end.should raise_error( StandardError, /Unknown+.*?package.*?manager/ )
107
+ end
108
+
109
+ end
110
+
111
+ describe 'OS X package manager guessing' do
112
+
113
+ before( :each ) do
114
+ PackageManager::Base.stub!( :operating_system ).and_return( 'darwin' )
115
+ end
116
+
117
+ it 'should return a PackageManager::Base subclass' do
118
+ PackageManager::Base.stub!( :program_installed? ).with( 'port' ).and_return( true )
119
+ pkg = PackageManager::Base.load
120
+ pkg.should_not be_nil
121
+ end
122
+
123
+ it 'with port available, should return a PackageManager::Port' do
124
+ PackageManager::Base.stub!( :program_installed? ).with( 'port' ).and_return( true )
125
+ pkg = PackageManager::Base.load
126
+ pkg.class.should == PackageManager::Port
127
+ end
128
+
129
+ it 'with port available, should return a PackageManager::Fink' do
130
+ PackageManager::Base.stub!( :program_installed? ).with( 'port' ).and_return( false )
131
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( true )
132
+ pkg = PackageManager::Base.load
133
+ pkg.class.should == PackageManager::Fink
134
+ end
135
+
136
+ it 'with no known package manager available, should raise an error' do
137
+ PackageManager::Base.stub!( :program_installed? ).with( 'port' ).and_return( false )
138
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( false )
139
+ lambda do
140
+ pkg = PackageManager::Base.load
141
+ end.should raise_error( StandardError, /Unknown+.*?package.*?manager/ )
142
+ end
143
+
144
+ end
@@ -0,0 +1,77 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'spec'
3
+
4
+ SPEC_PATH = File.expand_path( File.dirname( __FILE__ ) )
5
+ ROOT_PATH = File.dirname( SPEC_PATH )
6
+ require File.join( ROOT_PATH, 'lib', 'package_manager' )
7
+
8
+ describe 'script methods' do
9
+
10
+ before( :all ) do
11
+ PackageManager::Base.stub!( :operating_system ).and_return( 'linux' )
12
+ PackageManager::Base.stub!( :program_installed? ).with( 'apt-get' ).and_return( true )
13
+ @pkg = PackageManager::Base.load
14
+ end
15
+
16
+ it "should run commands through a subprocess" do
17
+ @pkg.should_receive( '`'.intern ).and_return( "foo\n" )
18
+ @pkg.find_available( 'pkg' )
19
+ end
20
+
21
+ it "#find_available should return an Array of matching packages" do
22
+ @pkg.stub!( :run_command ).and_return( "pkg1\npkg2" )
23
+ @pkg.find_available( 'pkg' ).should be_a( Array )
24
+ end
25
+
26
+ it "#find_installed should return an Array of matching packages" do
27
+ @pkg.stub!( :run_command ).and_return( "pkg1\npkg2" )
28
+ @pkg.find_installed( 'pkg' ).should be_a( Array )
29
+ end
30
+
31
+ it "#list_contents should return an Array of files" do
32
+ @pkg.stub!( :run_command ).and_return( "/path/to/file1\n/path/to/file2" )
33
+ @pkg.list_contents( 'pkg' ).should be_a( Array )
34
+ end
35
+
36
+ it "#install should return true or false" do
37
+ `ls`
38
+ @pkg.stub!( :run_command )
39
+ @pkg.install( 'pkg' ).should be_true
40
+ end
41
+
42
+ it "#install_file should return true or false" do
43
+ `ls` # Force $?.exitstatus to be 0
44
+ @pkg.stub!( :run_command )
45
+ File.stub!( :exist? ).and_return( true )
46
+ @pkg.install_file( 'my_pkg' ).should be_true
47
+ end
48
+
49
+ it "#install_file should throw an error if the file does not exist" do
50
+ @pkg.stub!( :run_command )
51
+ File.stub!( :exist? ).and_return( false )
52
+ lambda do
53
+ @pkg.install_file( 'my_pkg' )
54
+ end.should raise_error( StandardError, /does not exist/ )
55
+ end
56
+
57
+ it "#uninstall should return true or false" do
58
+ `ls`
59
+ @pkg.stub!( :run_command )
60
+ @pkg.uninstall( 'pkg' ).should be_true
61
+ end
62
+
63
+ it "#provides should return a String" do
64
+ @pkg.stub!( :run_command ).and_return( 'my_pkg' )
65
+ File.stub!( :exist? ).and_return( true )
66
+ @pkg.provides( '/file/from/package' ).should == 'my_pkg'
67
+ end
68
+
69
+ it "#provides should throw an error if the file does not exist" do
70
+ @pkg.stub!( :run_command ).and_return( 'my_pkg' )
71
+ File.stub!( :exist? ).and_return( false )
72
+ lambda do
73
+ @pkg.provides( '/file/from/package' )
74
+ end.should raise_error( StandardError, /does not exist/ )
75
+ end
76
+
77
+ end
@@ -0,0 +1,34 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'spec'
3
+
4
+ SPEC_PATH = File.expand_path( File.dirname( __FILE__ ) )
5
+ ROOT_PATH = File.dirname( SPEC_PATH )
6
+ require File.join( ROOT_PATH, 'lib', 'package_manager' )
7
+
8
+ describe 'subclasses' do
9
+
10
+ it "PackageManager::Apt#name should return 'apt'" do
11
+ PackageManager::Apt.new.name.should == 'apt'
12
+ end
13
+
14
+ it "PackageManager::Dpkg#name should return 'dpkg'" do
15
+ PackageManager::Dpkg.new.name.should == 'dpkg'
16
+ end
17
+
18
+ it "PackageManager::Fink#name should return 'fink'" do
19
+ PackageManager::Fink.new.name.should == 'fink'
20
+ end
21
+
22
+ it "PackageManager::Port#name should return 'port'" do
23
+ PackageManager::Port.new.name.should == 'port'
24
+ end
25
+
26
+ it "PackageManager::Rpm#name should return 'rpm'" do
27
+ PackageManager::Rpm.new.name.should == 'rpm'
28
+ end
29
+
30
+ it "PackageManager::Yum#name should return 'yum'" do
31
+ PackageManager::Yum.new.name.should == 'yum'
32
+ end
33
+
34
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'spec'
3
+
4
+ SPEC_PATH = File.expand_path( File.dirname( __FILE__ ) )
5
+ ROOT_PATH = File.dirname( SPEC_PATH )
6
+ require File.join( ROOT_PATH, 'lib', 'package_manager' )
7
+
8
+ describe 'the package' do
9
+
10
+ it 'has a VERSION' do
11
+ PackageManager::VERSION::MAJOR.should_not be_nil
12
+ PackageManager::VERSION::MINOR.should_not be_nil
13
+ PackageManager::VERSION::TINY.should_not be_nil
14
+ PackageManager::VERSION::STRING.should_not be_nil
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: package_manager
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Yates
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-10 00:00:00 +01:00
18
+ date: 2010-09-11 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,10 @@ files:
81
81
  - lib/package_manager/rpm.rb
82
82
  - lib/package_manager/yum.rb
83
83
  - lib/package_manager.rb
84
+ - spec/platform_spec.rb
85
+ - spec/script_methods_spec.rb
86
+ - spec/subclasses_spec.rb
87
+ - spec/version_spec.rb
84
88
  has_rdoc: true
85
89
  homepage: http://github.com/joeyates/package_manager
86
90
  licenses: []
@@ -113,10 +117,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
117
  version: "0"
114
118
  requirements: []
115
119
 
116
- rubyforge_project:
120
+ rubyforge_project: nowarning
117
121
  rubygems_version: 1.3.7
118
122
  signing_key:
119
123
  specification_version: 3
120
124
  summary: A package manager abstraction
121
- test_files: []
122
-
125
+ test_files:
126
+ - spec/platform_spec.rb
127
+ - spec/script_methods_spec.rb
128
+ - spec/subclasses_spec.rb
129
+ - spec/version_spec.rb