ruby-deb 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.
Files changed (3) hide show
  1. data/README.md +48 -0
  2. data/lib/ruby-deb.rb +77 -0
  3. metadata +63 -0
@@ -0,0 +1,48 @@
1
+ ## Pure ruby deb reader
2
+
3
+ Not the fastest one, for sure
4
+
5
+ ```ruby
6
+ require "deb"
7
+
8
+ # the ;0 avoids the file payload to garbage your term
9
+ a = Deb.new("your.deb");0
10
+
11
+ # see control_files
12
+ a.control_files
13
+ => ["md5sums", "control", "postrm", "postinst"]
14
+
15
+ # extract data
16
+ >> x.archive.dump("data.tar.xz")
17
+ => 2885028
18
+
19
+ # see control data
20
+ >> x.control
21
+ => {"Package"=>"eog", "Version"=>"3.12.0-1", "Architecture"=>"i386", "Maintainer"=>"Debian GNOME Maintainers <pkg-gnome-maintainers@lists.alioth.debian.org>", "Installed-Size"=>"9547", "Depends"=>"libatk1.0-0 (>= 1.32.0-2~), libc6 (>= 2.11), libcairo-gobject2 (>= 1.10.0), libcairo2 (>= 1.10.0), libexempi3 (>= 2.2.0), libexif12, libgdk-pixbuf2.0-0 (>= 2.22.0), libgirepository-1.0-1 (>= 0.9.3), libglib2.0-0 (>= 2.38.0), libgnome-desktop-3-7 (>= 3.2.0), libgtk-3-0 (>= 3.10.6), libjpeg8 (>= 8c), liblcms2-2 (>= 2.2+git20110628), libpango-1.0-0 (>= 1.14.0), libpangocairo-1.0-0 (>= 1.14.0), libpeas-1.0-0 (>= 1.0.0), librsvg2-2 (>= 2.36.2), libx11-6, libxml2 (>= 2.7.4), zlib1g (>= 1:1.1.4), dconf-gsettings-backend | gsettings-backend, gir1.2-gtk-3.0, gnome-icon-theme (>= 2.19.1), shared-mime-info (>= 0.20), gsettings-desktop-schemas (>= 2.91.92), gir1.2-peas-1.0", "Recommends"=>"librsvg2-common, yelp", "Conflicts"=>"gir1.2-eog-3.0", "Breaks"=>"eog-plugins (<< 2.91)", "Replaces"=>"gir1.2-eog-3.0", "Section"=>"gnome", "Priority"=>"optional", "Homepage"=>"http://projects.gnome.org/eog", "Description"=>"Eye of GNOME graphics viewer programeog or the Eye of GNOME is a simple graphics viewer for the GNOMEdesktop which uses the gdk-pixbuf library. It can deal with largeimages, and zoom and scroll with constant memory usage. Its goals aresimplicity and standards compliance."}
22
+ ```
23
+
24
+ You can also get the file as a string with ```Ar#get_payload```, for usage with ```StringIO``` for example
25
+
26
+ ## License
27
+
28
+ The MIT License (MIT)
29
+
30
+ Copyright (c) 2014 Nicolas Szalay <nico@rottenbytes.info>
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy
33
+ of this software and associated documentation files (the "Software"), to deal
34
+ in the Software without restriction, including without limitation the rights
35
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
+ copies of the Software, and to permit persons to whom the Software is
37
+ furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in
40
+ all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
48
+ THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ require "ar"
2
+ require "zlib"
3
+ require "stringio"
4
+ require "rubygems/package"
5
+
6
+ class Deb
7
+ VERSION="0.1"
8
+
9
+ attr_reader :archive
10
+ def initialize(filename, options = {})
11
+ @sourcefile = filename
12
+ @archive = Ar.new(filename)
13
+ @archive.load
14
+ @control_archive = nil
15
+
16
+ nil
17
+ end
18
+
19
+ def control
20
+ control = Hash.new
21
+ if @control_archive.nil?
22
+ get_control_archive()
23
+ end
24
+
25
+ lastfield = nil
26
+ @control_archive["control"].lines.each do |l|
27
+ m = l.match(/(?<field>\w+-*\w*):\ (?<value>.*)/)
28
+ # standard "key: value"
29
+ if m
30
+ control[m["field"]] = m["value"].strip
31
+ lastfield = m["field"]
32
+ else # previous field was multilined, aggregate
33
+ control[lastfield] += l.strip
34
+ end
35
+ end
36
+
37
+ control
38
+ end
39
+
40
+ def control_files
41
+ if @control_archive.nil?
42
+ get_control_archive()
43
+ end
44
+
45
+ @control_archive.keys
46
+ end
47
+
48
+ # allow to access any file in control_archive
49
+ def method_missing(m)
50
+ if @control_archive.nil?
51
+ get_control_archive()
52
+ end
53
+
54
+ if control_files.include?(m.to_s)
55
+ @control_archive[m.to_s]
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def get_control_archive()
62
+ entries = Hash.new
63
+ ca_payload = @archive.get_payload("control.tar.gz")
64
+ gz = Zlib::GzipReader.new(StringIO.new(ca_payload))
65
+ Gem::Package::TarReader.new(StringIO.new(gz.read)) do |tar|
66
+ tar.each do |tarfile|
67
+ filename = tarfile.full_name
68
+ filename.gsub!(/^\.\//, "")
69
+ entries[filename] = tarfile.read
70
+ end
71
+ end
72
+
73
+ entries.delete("")
74
+ @control_archive = entries
75
+ end
76
+
77
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-deb
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nicolas Szalay
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ar
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ description: Deb package manipulation
31
+ email:
32
+ - nico@rottenbytes.info
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - README.md
38
+ - lib/ruby-deb.rb
39
+ homepage: https://github.com/rottenbytes/ruby-deb
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.25
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Deb package manipulator
63
+ test_files: []