debeasy 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in debeasy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andy Sykes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Debeasy
2
+
3
+ A really easy way to read the properties of a Debian/Ubuntu (DEB format)
4
+ package file. In this way, it's the Debian/Ubuntu companion to
5
+ [jordansissel's arr-pm gem](https://github.com/jordansissel/ruby-arr-pm).
6
+
7
+ ## Usage
8
+
9
+ require 'debeasy'
10
+ pkg = Debeasy.read("/path/to/package.deb")
11
+ puts pkg.architecture
12
+ => x86_64
13
+
14
+ All the attributes are the same ones you'd get from `aptitude show`, except
15
+ for the purposes of access hyphens (`-`) get replaced with underscores (`_`),
16
+ and everything is lowercased.
17
+
18
+ To see the available fields on a package, do:
19
+
20
+ require 'debeasy'
21
+ pkg = Debeasy.read("/path/to/package.deb")
22
+ puts pkg.fields
23
+
24
+ You can also read the preinst, prerm, postinst, and postrm scripts
25
+ from the package:
26
+
27
+ pkg.preinst_contents
28
+ pkg.prerm_contents
29
+ pkg.postinst_contents
30
+ pkg.postrm_contents
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ gem 'debeasy'
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install debeasy
45
+
46
+ ## Installation on Mac OS X
47
+
48
+ You may (read: will) run into problems getting the `libarchive` gem to
49
+ install on Mac OS X. The way to fix this seems to be to tell `bundler` to
50
+ supply an option to the `libarchive` build process so it can find `libarchive.h`.
51
+
52
+ First install libarchive with brew:
53
+
54
+ brew install libarchive
55
+
56
+ Now configure `bundler`:
57
+
58
+ bundle config build.libarchive "--with-opt-dir=/usr/local/opt/libarchive"
59
+
60
+ Now do `bundle install` as normal.
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/debeasy.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'debeasy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "debeasy"
8
+ spec.version = Debeasy::VERSION
9
+ spec.authors = ["Andy Sykes"]
10
+ spec.email = ["github@tinycat.co.uk"]
11
+ spec.description = %q{Debeasy is a simple gem that allows you to
12
+ programmatically read Debian packages with very
13
+ little effort.}
14
+ spec.summary = %q{Read .deb (Debian/Ubuntu) packages with ease!}
15
+ spec.homepage = ""
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_dependency "libarchive"
26
+ end
data/lib/debeasy.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "debeasy/version"
2
+ require "debeasy/package"
3
+
4
+ module Debeasy
5
+ def self.read(path)
6
+ Debeasy::Package.new(path)
7
+ end
8
+ end
@@ -0,0 +1,59 @@
1
+ require 'libarchive'
2
+
3
+ module Debeasy
4
+ class Package
5
+
6
+ attr_reader :path, :package
7
+ attr_reader :control_file_contents
8
+ attr_reader :preinst_contents, :prerm_contents
9
+ attr_reader :postinst_contents, :postrm_contents
10
+
11
+ def initialize(path)
12
+ @path = path
13
+ @package = Archive.read_open_filename(path)
14
+ @fields = {}
15
+ extract_files
16
+ parse_control_file
17
+ end
18
+
19
+ def fields
20
+ @fields.keys
21
+ end
22
+
23
+ def method_missing(m, *args, &block)
24
+ @fields[m.to_s]
25
+ end
26
+
27
+ private
28
+
29
+ def extract_files
30
+ while file = @package.next_header
31
+ if file.pathname == "control.tar.gz"
32
+ control_tar_gz = Archive.read_open_memory(@package.read_data)
33
+ while control_entry = control_tar_gz.next_header
34
+ case control_entry.pathname
35
+ when "./control"
36
+ @control_file_contents = control_tar_gz.read_data
37
+ when "./preinst"
38
+ @preinst_contents = control_tar_gz.read_data
39
+ when "./prerm"
40
+ @prerm_contents = control_tar_gz.read_data
41
+ when "./postinst"
42
+ @postinst_contents = control_tar_gz.read_data
43
+ when "./postrm"
44
+ @postrm_contents = control_tar_gz.read_data
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def parse_control_file
52
+ @control_file_contents.scan(/^([\w-]+?): (.*?)\n(?! )/m).each do |entry|
53
+ field, value = entry
54
+ @fields[field.gsub("-", "_").downcase] = value
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Debeasy
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debeasy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andy Sykes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: libarchive
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! "Debeasy is a simple gem that allows you to\n programmatically
63
+ read Debian packages with very\n little effort."
64
+ email:
65
+ - github@tinycat.co.uk
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - debeasy.gemspec
76
+ - lib/debeasy.rb
77
+ - lib/debeasy/package.rb
78
+ - lib/debeasy/version.rb
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.25
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Read .deb (Debian/Ubuntu) packages with ease!
104
+ test_files: []