gem2arch 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e32dd8f2bac8f19b6227864c729a0b6a8b98f991
4
- data.tar.gz: f1efc05452e0af571b36bfded69f171c0f5dbb29
3
+ metadata.gz: 6f622d0ec90306633e9c1ebc8e91bd1217bc2cf8
4
+ data.tar.gz: dbe0ffcc01b60f36797f942ee9ef68e70e20caa5
5
5
  SHA512:
6
- metadata.gz: 2a6cab8a3bc4ce424f53526a7b3564c136a54d1aac826a1d43252bb281096d8844880aaf889dc8e2907794e9d8f3f33fc5810c8c0335011a3420b38e890b7057
7
- data.tar.gz: b8287908ceef0c7329c5aaf1320f315ed50654675ac8e219cdec96f6297d36f3c90247d85ae1b0b088589fdee14361314b03c64680f9304e6a2111abd746ebbc
6
+ metadata.gz: 7ca94327573f69480379992b1008e23ba4c3714c77d75e43eca507ffb911faa1145f4f445c40e64ed5ad4178979c67b9e5d1d1f426a6a68d858b35338aaaac29
7
+ data.tar.gz: 501704362656ed52ec76fb997bde662d687f1bfa0a461c88793698b78b2915301d15154826e26e19c000d49522e3c0770d6ab5272925052acfba45d701a505a8
data/gem2arch.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  # Variables:
5
5
  s.name = "gem2arch"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
7
7
  s.description = "A version of gem2arch by crabtw that creates an ArchLinux PKGBUILD from a ruby gem"
8
8
  s.summary = "Creates an ArchLinux PKGBUILD from a ruby gem"
9
9
  s.authors = ["Ari Mizrahi"]
@@ -0,0 +1,121 @@
1
+ require 'digest/md5'
2
+ require 'digest/sha1'
3
+
4
+ module Gem2arch
5
+
6
+ class Core
7
+
8
+ # Download the gem and return specification information
9
+ # @params [String] gemname is the name of the gem to download
10
+ # @params [String] gemver is the version of the gem to download - default nil
11
+ # @return [Gem::Specification] gem specification object
12
+ def download( gemname, gemver=nil )
13
+ # If gem version is not passed set it
14
+ # to any version greater than 0
15
+ version = gemver || ">=0"
16
+ # Get gem requirement object
17
+ requirement = Gem::Requirement.default
18
+ # Get gem dependency object
19
+ depends = Gem::Dependency.new( gemname, version )
20
+ # Fetch gem specification
21
+ spec_and_source = Gem::SpecFetcher.fetcher.spec_for_dependency( depends, requirement )
22
+ # Get gem specification info
23
+ spec = spec_and_source[0][0][0]
24
+ # Get source URI
25
+ source_uri = spec_and_source[0][0][1]
26
+ # Quit if we don't have a spec, we can't continue without it
27
+ # it probably means the gem doesn't exist in rubygems.org
28
+ exit if spec.nil?
29
+ # Download the .gem file
30
+ system( "gem fetch #{gemname}" )
31
+
32
+ return spec
33
+ end
34
+
35
+ # Hash a file and return it's MD5 or SHA1 value
36
+ # @params [String] file is spec filename
37
+ # @params [Symbol] type is :MD5 or :SHA1
38
+ # @return [String] hash value of passed file parameter
39
+ def digest( file, type )
40
+ # Get MD5 || SHA1 object depending on [type]
41
+ hashv = Digest::MD5.new if type == :MD5
42
+ hashv = Digest::SHA1.new if type == :SHA1
43
+ # Open the file and generate hash
44
+ # in 1024 bit chunks
45
+ File.open( file ) do |chunks|
46
+ while buffer = chunks.read(1024)
47
+ hashv << buffer
48
+ end
49
+ end
50
+
51
+ return hashv.to_s
52
+ end
53
+
54
+ # Build the PKGBUILD file using the downloaded specification
55
+ # @params [Gem::Specification] spec is gem specification object
56
+ def build( spec, archdepends=[] )
57
+ # Set arch=() value of PKGBUILD
58
+ spec.extensions.empty? ? arch = "'any'" : arch = "'i686' 'x86_64'"
59
+ # Calculate digest
60
+ md5sum = digest( "#{spec.full_name}.gem", :MD5 )
61
+ # Get gem dependencies
62
+ depends = spec.runtime_dependencies
63
+ # Modify [Array] depends if it is not empty
64
+ unless depends.empty?
65
+ # Break [Array] depends to modify each element
66
+ depends.map do |dep|
67
+ # For each dependency we need to modify the comparison
68
+ # symbol used to be compatible with PKGBUILD
69
+ dep.requirement.requirements.map do |compare, version|
70
+ # Modify the comparision symbol for PKGBUILD
71
+ compare = '>=' if compare == '~>'
72
+ # Replace the entire string for PKGBUILD
73
+ archdepends << "'ruby-#{dep.name}#{compare}#{version}'"
74
+ end
75
+ end
76
+ end
77
+
78
+ # Build the gem parameters hash
79
+ params = {
80
+ name: spec.name,
81
+ version: spec.version,
82
+ website: spec.homepage,
83
+ description: spec.summary,
84
+ license: spec.license,
85
+ arch: arch,
86
+ md5sum: md5sum,
87
+ depends: archdepends.join(" ")
88
+ }
89
+
90
+ pkgbuild( params )
91
+ end
92
+
93
+ private
94
+
95
+ # Generate the PKGBUILD file
96
+ # @params [Hash] gem contains all parameters required to generate the PKGBUILD file
97
+ def pkgbuild( gem )
98
+ File.open( 'PKGBUILD', 'w' ) do |line|
99
+ line.puts "pkgname=ruby-#{gem[:name]}"
100
+ line.puts "_gemname=#{gem[:name]}"
101
+ line.puts "pkgver=#{gem[:version]}"
102
+ line.puts "pkgrel=0"
103
+ line.puts "pkgdesc=\"#{gem[:description]}\""
104
+ line.puts "arch=(#{gem[:arch]})"
105
+ line.puts "license=('#{gem[:license]}')"
106
+ line.puts "makedepends=('ruby')"
107
+ line.puts "depends=(#{gem[:depends]})"
108
+ line.puts "url='#{gem[:website]}'"
109
+ line.puts "source=('http://rubygems.org/downloads/#{gem[:name]}-#{gem[:version]}.gem')"
110
+ line.puts "md5sums=('#{gem[:md5sum]}')"
111
+ line.puts "noextract=(#{gem[:name]}-#{gem[:version]}.gem)"
112
+
113
+ line.puts "package() {"
114
+ line.puts "\tcd \"$srcdir\""
115
+ line.puts "\tlocal _gemdir=\"$(ruby -e 'puts Gem.default_dir')"
116
+ line.puts "\tgem install --ignore-dependencies --no-user-install -i \"$pkgdir$_gemdir\" -n \"$pkgdir/usr/bin\" $_gemname-$pkgver.gem"
117
+ line.puts "}"
118
+ end
119
+ end
120
+ end
121
+ end
data/lib/gem2arch.rb CHANGED
@@ -1,115 +1,51 @@
1
- require 'digest/md5'
2
- require 'digest/sha1'
1
+ require 'gem2arch/core'
2
+ require 'optparse'
3
+ require 'fileutils'
4
+ require 'tmpdir'
3
5
 
4
- # Download the gem and return specification information
5
- # @params [String] gemname is the name of the gem to download
6
- # @params [String] gemver is the version of the gem to download - default nil
7
- # @return [Gem::Specification] gem specification object
8
- def download( gemname, gemver=nil )
9
- # If gem version is not passed set it
10
- # to any version greater than 0
11
- version = gemver || ">=0"
12
- # Get gem requirement object
13
- requirement = Gem::Requirement.default
14
- # Get gem dependency object
15
- depends = Gem::Dependency.new( gemname, version )
16
- # Fetch gem specification
17
- spec_and_source = Gem::SpecFetcher.fetcher.spec_for_dependency( depends, requirement )
18
- # Get gem specification info
19
- spec = spec_and_source[0][0][0]
20
- # Get source URI
21
- source_uri = spec_and_source[0][0][1]
22
- # Quit if we don't have a spec, we can't continue without it
23
- # it probably means the gem doesn't exist in rubygems.org
24
- exit if spec.nil?
25
- # Download the .gem file
26
- system( "gem fetch #{gemname}" )
27
-
28
- return spec
29
- end
6
+ module Gem2arch
30
7
 
31
- # Hash a file and return it's MD5 or SHA1 value
32
- # @params [String] file is spec filename
33
- # @params [Symbol] type is :MD5 or :SHA1
34
- # @return [String] hash value of passed file parameter
35
- def digest( file, type )
36
- # Get MD5 || SHA1 object depending on [type]
37
- hashv = Digest::MD5.new if type == :MD5
38
- hashv = Digest::SHA1.new if type == :SHA1
39
- # Open the file and generate hash
40
- # in 1024 bit chunks
41
- File.open( file ) do |chunks|
42
- while buffer = chunks.read(1024)
43
- hashv << buffer
44
- end
45
- end
8
+ def self.start
9
+ options = {
10
+ gem: nil,
11
+ version: nil
12
+ }
46
13
 
47
- return hashv.to_s
48
- end
14
+ OptionParser.new do |opts|
15
+ opts.banner = "gem2arch 0.0.3 (https://www.github.com/codemunchies/gem2arch)"
16
+ opts.banner += "Usage: gem2arch [options]"
49
17
 
50
- # Build the PKGBUILD file using the downloaded specification
51
- # @params [Gem::Specification] spec is gem specification object
52
- def build( spec, archdepends=[] )
53
- # Set arch=() value of PKGBUILD
54
- spec.extensions.empty? ? arch = "'any'" : arch = "'i686' 'x86_64'"
55
- # Calculate digest
56
- md5sum = digest( "#{spec.full_name}.gem", :MD5 )
57
- # Get gem dependencies
58
- depends = spec.runtime_dependencies
59
- # Modify [Array] depends if it is not empty
60
- unless depends.empty?
61
- # Break [Array] depends to modify each element
62
- depends.map do |dep|
63
- # For each dependency we need to modify the comparison
64
- # symbol used to be compatible with PKGBUILD
65
- dep.requirement.requirements.map do |compare, version|
66
- # Modify the comparision symbol for PKGBUILD
67
- compare = '>=' if compare == '~>'
68
- # Replace the entire string for PKGBUILD
69
- archdepends << "'ruby-#{dep.name}#{compare}#{version}'"
18
+ opts.on("--build [STRING]", "Gem to download and generate PKGBUILD for") do |gem|
19
+ options[:gem] = gem
70
20
  end
71
- end
72
- end
73
-
74
- # Build the gem parameters hash
75
- params = {
76
- name: spec.name,
77
- version: spec.version,
78
- website: spec.homepage,
79
- description: spec.summary,
80
- license: spec.license,
81
- arch: arch,
82
- md5sum: md5sum,
83
- depends: archdepends.join(" ")
84
- }
85
21
 
86
- pkgbuild( params )
87
- end
88
-
89
- private
90
-
91
- # Generate the PKGBUILD file
92
- # @params [Hash] gem contains all parameters required to generate the PKGBUILD file
93
- def pkgbuild( gem )
94
- File.open( 'PKGBUILD', 'w' ) do |line|
95
- line.puts "pkgname=ruby-#{gem[:name]}"
96
- line.puts "_gemname=#{gem[:name]}"
97
- line.puts "pkgver=#{gem[:version]}"
98
- line.puts "pkgrel=0"
99
- line.puts "pkgdesc=\"#{gem[:description]}\""
100
- line.puts "arch=(#{gem[:arch]})"
101
- line.puts "license=('#{gem[:license]}')"
102
- line.puts "makedepends=('ruby')"
103
- line.puts "depends=(#{gem[:depends]})"
104
- line.puts "url='#{gem[:website]}'"
105
- line.puts "source=('http://rubygems.org/downloads/#{gem[:name]}-#{gem[:version]}.gem')"
106
- line.puts "md5sums=('#{gem[:md5sum]}')"
107
- line.puts "noextract=(#{gem[:name]}-#{gem[:version]}.gem)"
108
-
109
- line.puts "package() {"
110
- line.puts "\tcd \"$srcdir\""
111
- line.puts "\tlocal _gemdir=\"$(ruby -e 'puts Gem.default_dir')"
112
- line.puts "\tgem install --ignore-dependencies --no-user-install -i \"$pkgdir$_gemdir\" -n \"$pkgdir/usr/bin\" $_gemname-$pkgver.gem"
113
- line.puts "}"
22
+ opts.on("--version [STRING]", "OPTIONAL: target specific version") do |ver|
23
+ options[:version] = ver
24
+ end
25
+ end.parse!
26
+
27
+ if options[:gem]
28
+ # Store paths
29
+ tmpdir = Dir.mktmpdir
30
+ basedir = Dir.pwd
31
+
32
+ begin
33
+ # Get [Gem2arch] object
34
+ gem2arch = Gem2arch::Core.new
35
+ # Jump into tmpdir
36
+ Dir.chdir( "#{tmpdir}" )
37
+ # Download the gem and store spec information
38
+ gemspec = gem2arch.download( options[:gem], options[:version] )
39
+ # Generate the PKGBUILD
40
+ gem2arch.build( gemspec )
41
+ # Move the PKGBUILD from tmpdir
42
+ FileUtils.mv( 'PKGBUILD', "#{basedir}" )
43
+ ensure
44
+ # Clean up
45
+ FileUtils.remove_entry_secure tmpdir
46
+ end
47
+ else
48
+ # Something
114
49
  end
115
50
  end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem2arch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Mizrahi
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - lib/gem2arch.rb
22
+ - lib/gem2arch/core.rb
22
23
  - bin/gem2arch
23
24
  - gem2arch.gemspec
24
25
  - Gemfile