-
Notifications
You must be signed in to change notification settings - Fork 30
Add mechanism to lookup specific package information #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# LinuxAdmin Deb Representation | ||
# | ||
# Copyright (C) 2013 Red Hat Inc. | ||
# Licensed under the MIT License | ||
|
||
class LinuxAdmin | ||
class Deb < Package | ||
APT_CACHE_CMD = '/usr/bin/apt-cache' | ||
|
||
def self.from_line(apt_cache_line, in_description=false) | ||
tag,value = apt_cache_line.split(':') | ||
tag = tag.strip.downcase | ||
[tag, value] | ||
end | ||
|
||
def self.from_string(apt_cache_string) | ||
in_description = false | ||
apt_cache_string.split("\n").each.with_object({}) do |line,deb| | ||
tag,value = self.from_line(line) | ||
if tag == 'description-en' | ||
in_description = true | ||
elsif tag == 'homepage' | ||
in_description = false | ||
end | ||
|
||
if in_description && tag != 'description-en' | ||
deb['description-en'] << line | ||
else | ||
deb[tag] = value.strip | ||
end | ||
end | ||
end | ||
|
||
def self.info(pkg) | ||
self.from_string(run!(APT_CACHE_CMD, :params => ["show", pkg]).output) | ||
end | ||
|
||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# LinuxAdmin Abstract Package Representation | ||
# | ||
# Copyright (C) 2013 Red Hat Inc. | ||
# Licensed under the MIT License | ||
|
||
class LinuxAdmin | ||
class Package < LinuxAdmin | ||
def self.info(pkg) | ||
if Distro.local == Distros.redhat | ||
return Rpm.info(pkg) | ||
elsif Distro.local == Distros.ubuntu | ||
return Deb.info(pkg) | ||
end | ||
|
||
nil | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin::Deb do | ||
describe "#info" do | ||
it "returns package metadata" do | ||
# as output w/ apt-cache show ruby on ubuntu 13.04 | ||
data = <<EOS | ||
Package: ruby | ||
Priority: optional | ||
Section: interpreters | ||
Installed-Size: 31 | ||
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | ||
Original-Maintainer: akira yamada <akira@debian.org> | ||
Architecture: all | ||
Source: ruby-defaults | ||
Version: 4.9 | ||
Replaces: irb, rdoc | ||
Provides: irb, rdoc | ||
Depends: ruby1.9.1 (>= 1.9.3.194-1) | ||
Suggests: ri, ruby-dev | ||
Conflicts: irb, rdoc | ||
Filename: pool/main/r/ruby-defaults/ruby_4.9_all.deb | ||
Size: 4896 | ||
MD5sum: b1991f2e0eafb04f5930ed242cfe1476 | ||
SHA1: a7c55fbb83dd8382631ea771b5555d989351f840 | ||
SHA256: 84d042e0273bd2f0082dd9e7dda0246267791fd09607041a35485bfff92f38d9 | ||
Description-en: Interpreter of object-oriented scripting language Ruby (default version) | ||
Ruby is the interpreted scripting language for quick and easy | ||
object-oriented programming. It has many features to process text | ||
files and to do system management tasks (as in perl). It is simple, | ||
straight-forward, and extensible. | ||
. | ||
This package is a dependency package, which depends on Debian's default Ruby | ||
version (currently v1.9.3). | ||
Homepage: http://www.ruby-lang.org/ | ||
Description-md5: da2991b37e3991230d79ba70f9c01682 | ||
Bugs: https://bugs.launchpad.net/ubuntu/+filebug | ||
Origin: Ubuntu | ||
Supported: 9m | ||
Task: kubuntu-desktop, kubuntu-full, kubuntu-active, kubuntu-active-desktop, kubuntu-active-full, kubuntu-active, edubuntu-desktop-gnome, ubuntustudio-font-meta | ||
EOS | ||
described_class.should_receive(:run). | ||
with(described_class::APT_CACHE_CMD, :params => ["show", "ruby"]). | ||
and_return(CommandResult.new(data, "", 0)) | ||
metadata = described_class.info("ruby") | ||
metadata['package'].should == 'ruby' | ||
metadata['priority'].should == 'optional' | ||
metadata['section'].should == 'interpreters' | ||
metadata['architecture'].should == 'all' | ||
metadata['version'].should == '4.9' | ||
metadata['origin'].should == 'Ubuntu' | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin::Package do | ||
describe "#info" do | ||
it "dispatches to redhat lookup mechanism" do | ||
LinuxAdmin::Distro.should_receive(:local).and_return(LinuxAdmin::Distros.redhat) | ||
LinuxAdmin::Rpm.should_receive(:info).with('ruby') | ||
described_class.info 'ruby' | ||
end | ||
|
||
it "dispatches to ubuntu lookup mechanism" do | ||
LinuxAdmin::Distro.should_receive(:local).twice.and_return(LinuxAdmin::Distros.ubuntu) | ||
LinuxAdmin::Deb.should_receive(:info).with('ruby') | ||
described_class.info 'ruby' | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @Fryguy has a suggestion on this one. Maybe Package should delegate the messages to a a singleton of a package manager based on the distro.
Perhaps get_info should be query... Rpm.query(pkg) seems more clear to me.
Finally, should it be PackageManager vs. Package, seems like we get package information from the package manager?
Also, what is the right package manager classes where we have rpm and deb classes here? It seems to me that deb is a package formats and not the tool we use to query for package information, so I would suggest Rpm and Maybe Apt as PackageManager classes. What are you thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so my thoughts are.