slapp 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c2e1e4b13aaa7a722803ce25f793aa835888d94
4
+ data.tar.gz: c76cbf58fd793bcf8be0b305e05fb20489ebf833
5
+ SHA512:
6
+ metadata.gz: 846bfd583b31bef3bfde3201a8d19fe018f42854cd74dfae8ed38d64b92ee037a87fab0a8ba37da3c3ad7192e0de4af2a460e07e121a6814d9edefeb15235fac
7
+ data.tar.gz: c8b936669f98432cc7a3d071d9b251f30627bc4bf133864777e6c6b762d590f26c78d9856c063a5dbdae027394640ea91280b2542da9faa0de9399c8f875ec15
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/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require spec_helper.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.3)
7
+ diff-lcs (1.2.5)
8
+ faraday (0.9.0)
9
+ multipart-post (>= 1.2, < 3)
10
+ git (1.2.6)
11
+ github_api (0.11.1)
12
+ addressable (~> 2.3)
13
+ descendants_tracker (~> 0.0.1)
14
+ faraday (~> 0.8, < 0.10)
15
+ hashie (>= 1.2)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ nokogiri (~> 1.6.0)
18
+ oauth2
19
+ hashie (2.0.5)
20
+ highline (1.6.20)
21
+ jeweler (2.0.0)
22
+ builder
23
+ bundler (>= 1.0)
24
+ git (>= 1.2.5)
25
+ github_api
26
+ highline (>= 1.6.15)
27
+ nokogiri (>= 1.5.10)
28
+ rake
29
+ rdoc
30
+ json (1.8.1)
31
+ jwt (0.1.10)
32
+ multi_json (>= 1.5)
33
+ mini_portile (0.5.2)
34
+ multi_json (1.8.4)
35
+ multi_xml (0.5.5)
36
+ multipart-post (2.0.0)
37
+ nokogiri (1.6.1)
38
+ mini_portile (~> 0.5.0)
39
+ oauth2 (0.9.3)
40
+ faraday (>= 0.8, < 0.10)
41
+ jwt (~> 0.1.8)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ rack (1.5.2)
46
+ rake (10.1.1)
47
+ rdoc (4.1.1)
48
+ json (~> 1.4)
49
+ rspec (2.14.1)
50
+ rspec-core (~> 2.14.0)
51
+ rspec-expectations (~> 2.14.0)
52
+ rspec-mocks (~> 2.14.0)
53
+ rspec-core (2.14.7)
54
+ rspec-expectations (2.14.4)
55
+ diff-lcs (>= 1.1.3, < 2.0)
56
+ rspec-mocks (2.14.4)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ jeweler
63
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nic Aitch
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,30 @@
1
+ # Slapp
2
+
3
+ SLAckware Package Parser
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'slapp'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install slapp
18
+
19
+ ## Usage
20
+
21
+ parser = Slapp::Parser.new('path/to/PACKAGES.TXT')
22
+ parser.packages # Like JSON
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ module Slapp
2
+ module Helpers
3
+ def convert_to_bytes(string)
4
+ units = {
5
+ :'K' => 1024,
6
+ :'MB' => 1024 * 1024
7
+ }
8
+
9
+ formula = units.map {|u| u.last if string.include? u.first.to_s }.compact
10
+ string.to_i * formula.first
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,115 @@
1
+ class Slapp::Package
2
+ include Slapp::Helpers
3
+
4
+ attr_accessor :data
5
+
6
+ def initialize(data)
7
+ @data = data
8
+
9
+ @name_match = regex('name').match(data)
10
+ @location_match = regex('location').match(data)
11
+ @size_match = data.scan regex('size')
12
+ @description_match = regex('description').match(data)
13
+ end
14
+
15
+ def name
16
+ @name_match[2]
17
+ end
18
+
19
+ def filename
20
+ @name_match[1]
21
+ end
22
+
23
+ def version
24
+ @name_match[3]
25
+ end
26
+
27
+ def arch
28
+ @name_match[4]
29
+ end
30
+
31
+ def location
32
+ @location_match[1]
33
+ end
34
+
35
+ def path
36
+ File.join location, filename
37
+ end
38
+
39
+ def build
40
+ @name_match[5]
41
+ end
42
+
43
+ def size_uncompressed
44
+ convert_to_bytes @size_match.flatten.last
45
+ end
46
+
47
+ def size_compressed
48
+ convert_to_bytes @size_match.flatten.first
49
+ end
50
+
51
+ def description
52
+ original_description
53
+ .gsub(/(\S)\n(\S)/, '\1 \2')
54
+ .gsub(/\n\n\s/, "\n\n")
55
+ .strip
56
+ end
57
+
58
+ def original_description
59
+ if name == 'aalib'
60
+ parsed_description.split("\n").map { |line|
61
+ line[0..34].strip
62
+ }.join("\n").strip
63
+ else
64
+ parsed_description
65
+ .gsub(/\n\n /, "\n\n")
66
+ .gsub(/\n /, "\n")
67
+ .strip
68
+ end
69
+ end
70
+
71
+ def summary
72
+ parsed_description
73
+ .slice(/^(.+)\n/)
74
+ .strip
75
+ end
76
+
77
+ def to_hash
78
+ {
79
+ filename: filename,
80
+ name: name,
81
+ version: version,
82
+ arch: arch,
83
+ build: build,
84
+ size: {
85
+ compressed: size_compressed,
86
+ uncompressed: size_uncompressed
87
+ },
88
+ location: location,
89
+ path: path,
90
+ description: description,
91
+ original_description: original_description,
92
+ summary: summary
93
+ }
94
+ end
95
+
96
+ private
97
+
98
+ def parsed_description
99
+ @description_match[1].gsub(/^#{name}:/, "")
100
+ end
101
+
102
+ def regex(type)
103
+ regexes[type.to_sym]
104
+ end
105
+
106
+ def regexes
107
+ {
108
+ name: /PACKAGE NAME:\s+((.+)-(.+)-(.+)-(.+)\.t\wz)/,
109
+ location: /PACKAGE LOCATION:\s+\.([\S]+)/,
110
+ size: /PACKAGE SIZE\s+\(\w+\):\s+(.+)/,
111
+ description: /PACKAGE DESCRIPTION:\s+(.+)/m
112
+ }
113
+ end
114
+
115
+ end
@@ -0,0 +1,44 @@
1
+ class Slapp::Parser
2
+ include Slapp::Helpers
3
+
4
+ attr_accessor :lines, :contents
5
+
6
+ def initialize(path)
7
+ @lines = File.readlines(path)
8
+ @contents = @lines.join('')
9
+ end
10
+
11
+ def total_size_uncompressed
12
+ line = lines.select { |line| line =~ total_size_regex('uncompressed') }
13
+ match = total_size_regex('uncompressed').match(line.first)
14
+ convert_to_bytes match[1]
15
+ end
16
+
17
+ def total_size_compressed
18
+ line = lines.select { |line| line =~ total_size_regex('compressed') }
19
+ match = total_size_regex('compressed').match(line.first)
20
+ convert_to_bytes match[1]
21
+ end
22
+
23
+ def packages
24
+ raw_packages.map { |pkg|
25
+ package = Slapp::Package.new pkg.first
26
+ package.to_hash
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def raw_packages
33
+ contents.scan(package_regex)
34
+ end
35
+
36
+ def package_regex
37
+ /(PACKAGE NAME.+?)\n\n/m
38
+ end
39
+
40
+ def total_size_regex(type)
41
+ /Total size.+\(#{type}\):\s+(.+)$/
42
+ end
43
+
44
+ end
@@ -0,0 +1,3 @@
1
+ module Slapp
2
+ VERSION = "0.1.0"
3
+ end
data/lib/slapp.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'version'
2
+
3
+ require 'slapp/helpers'
4
+ require 'slapp/package'
5
+ require 'slapp/parser'
data/slapp.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slapp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slapp"
8
+ spec.version = Slapp::VERSION
9
+ spec.authors = ["Nic Aitch"]
10
+ spec.email = ["nic@nicinabox.com"]
11
+ spec.description = %q{Parse Slackware PACKAGES.TXT with ease}
12
+ spec.summary = %q{Parse Slackware PACKAGES.TXT with ease}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,118 @@
1
+ require 'slapp/parser'
2
+
3
+ describe Slapp::Parser do
4
+ before do
5
+ @parser = Slapp::Parser.new('spec/support/PACKAGES.TXT')
6
+ end
7
+
8
+ it "parses the total size (uncompressed)" do
9
+ @parser.total_size_uncompressed.should == 5942280192
10
+ end
11
+
12
+ it "parses the total size (compressed)" do
13
+ @parser.total_size_compressed.should == 1701838848
14
+ end
15
+
16
+ describe '.read' do
17
+ it 'reads the file' do
18
+ @parser.lines.should_not be_empty
19
+ end
20
+ end
21
+
22
+ describe '#packages' do
23
+ before do
24
+ @package = @parser.packages.first
25
+ end
26
+
27
+ it "parses the filename" do
28
+ @package[:filename].should == 'ConsoleKit-0.4.3-i486-1.txz'
29
+ end
30
+
31
+ it "parses the name" do
32
+ @package[:name].should == 'ConsoleKit'
33
+ end
34
+
35
+ it "parses the version" do
36
+ @package[:version].should == '0.4.3'
37
+ end
38
+
39
+ it "parses the location" do
40
+ @package[:location].should == '/slackware/l'
41
+ end
42
+
43
+ it "parses the path" do
44
+ @package[:path].should == '/slackware/l/ConsoleKit-0.4.3-i486-1.txz'
45
+ end
46
+
47
+ it "parses the size" do
48
+ @package[:size].should == {
49
+ :compressed => 131072,
50
+ :uncompressed => 624640
51
+ }
52
+ end
53
+
54
+ it "parses the description" do
55
+ desc = <<-desc
56
+ ConsoleKit (user, login, and seat tracking framework)
57
+
58
+ ConsoleKit is a framework for defining and tracking users, login sessions, and seats.
59
+
60
+ Homepage: http://freedesktop.org/wiki/Software/ConsoleKit
61
+ desc
62
+
63
+ @package[:description].should == desc.strip
64
+ end
65
+
66
+ it "parses the original description" do
67
+ desc = <<-desc
68
+ ConsoleKit (user, login, and seat tracking framework)
69
+
70
+ ConsoleKit is a framework for defining and tracking users, login
71
+ sessions, and seats.
72
+
73
+ Homepage: http://freedesktop.org/wiki/Software/ConsoleKit
74
+ desc
75
+
76
+ @package[:original_description].should == desc.strip
77
+ end
78
+
79
+ it "parses the summary" do
80
+ @package[:summary].should == "ConsoleKit (user, login, and seat tracking framework)"
81
+ end
82
+ end
83
+
84
+ describe 'aalib' do
85
+ before do
86
+ @aalib = @parser.packages.select { |pkg| pkg[:name] == 'aalib' }.first
87
+ end
88
+
89
+ it "parses the original description" do
90
+ original_desc = <<-desc
91
+ aalib (ASCII Art library)
92
+
93
+ AA-lib is an ASCII art graphics
94
+ library. Internally, the AA-lib
95
+ API is similar to other graphics
96
+ libraries, but it renders the
97
+ the output into ASCII art (like
98
+ the example to the right :^)
99
+ The developers of AA-lib are
100
+ Jan Hubicka, Thomas A. K. Kjaer,
101
+ Tim Newsome, and Kamil Toman.
102
+ desc
103
+
104
+ @aalib[:original_description].should == original_desc.strip
105
+ end
106
+
107
+ it 'parses the description' do
108
+ desc = <<-desc
109
+ aalib (ASCII Art library)
110
+
111
+ AA-lib is an ASCII art graphics library. Internally, the AA-lib API is similar to other graphics libraries, but it renders the the output into ASCII art (like the example to the right :^) The developers of AA-lib are Jan Hubicka, Thomas A. K. Kjaer, Tim Newsome, and Kamil Toman.
112
+ desc
113
+
114
+ @aalib[:description].should == desc.strip
115
+ end
116
+ end
117
+
118
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'slapp'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end