Class: Gembuild::Pkgbuild
- Inherits:
-
Object
- Object
- Gembuild::Pkgbuild
- Defined in:
- lib/gembuild/pkgbuild.rb
Overview
Class used to create a PKGBUILD file for a rubygem.
Instance Attribute Summary collapse
-
#arch ⇒ Array
The supported architectures.
-
#checksum ⇒ String
The sha256 sum of the gemfile.
-
#checksum_type ⇒ String
The type of checksum (will always be sha256).
-
#contributor ⇒ Array
An array of the contributors to the pkgbuild.
-
#depends ⇒ Array
An array of the package’s dependencies (always ruby plus any other gems listed as dependencies).
-
#description ⇒ String
The package description.
-
#epoch ⇒ Fixnum
The package’s epoch value.
-
#gemname ⇒ String
The ruby gem for which to generate a PKGBUILD.
-
#license ⇒ Array
An array of licenses for the gem.
-
#maintainer ⇒ String
The package’s maintainer.
-
#makedepends ⇒ Array
A list of the dependencies needed to build the package (normally just the package rubygems).
-
#noextract ⇒ Array
A list of sources not to extract with bsdtar (namely, the gemfile).
-
#options ⇒ Array
A list of options to pass to makepkg.
-
#pkgname ⇒ String
The name of the package (usually ruby-gem).
-
#pkgrel ⇒ Fixnum
The release number of the package.
-
#pkgver ⇒ Gem::Version
The version of the gem.
-
#source ⇒ Array
A list of sources.
-
#url ⇒ String
The URL of the homepage of the gem.
Class Method Summary collapse
-
.create(gemname, existing_pkgbuild = nil) ⇒ Gembuild::Pkgbuild
Create a new Pkgbuild instance with all information from the scraped sources assigned.
Instance Method Summary collapse
-
#assign_aur_details(details) ⇒ void
Assign version information based on the information gathered from the AUR.
-
#assign_gem_details(details) ⇒ void
Add the data scraped from rubygems.org to the pkgbuild.
-
#fetch_maintainer ⇒ String
Set the correct maintainer for the PKGBUILD.
-
#format_contact_information(contact_information) ⇒ String
Obfuscate the maintainer/contributors’ email addresses to (help to) prevent spam.
-
#initialize(gemname, existing_pkgbuild = nil) ⇒ Gembuild::Pkgbuild
constructor
Create a new Pkgbuild instance.
-
#parse_existing_pkgbuild(pkgbuild) ⇒ Hash
Parse the old pkgbuild (if it exists) to get information about old maintainers or contributors or about other dependencies that have been added but that can not be scraped from rubygems.org.
-
#render ⇒ String
Generate a PKGBUILD from the class using the pkgbuild erb template.
-
#template ⇒ String
Get the PKGBUILD erb template.
-
#write(path = '') ⇒ Fixnum
Write the PKGBUILD to disk.
Constructor Details
#initialize(gemname, existing_pkgbuild = nil) ⇒ Gembuild::Pkgbuild
Create a new Pkgbuild instance.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gembuild/pkgbuild.rb', line 93 def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end |
Instance Attribute Details
#arch ⇒ Array
Returns the supported architectures.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#checksum ⇒ String
Returns the sha256 sum of the gemfile.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#checksum_type ⇒ String
Returns the type of checksum (will always be sha256).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#contributor ⇒ Array
Returns an array of the contributors to the pkgbuild.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#depends ⇒ Array
Returns an array of the package’s dependencies (always ruby plus any other gems listed as dependencies).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#description ⇒ String
Returns the package description.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#epoch ⇒ Fixnum
Returns the package’s epoch value.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#gemname ⇒ String
Returns the ruby gem for which to generate a PKGBUILD.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#license ⇒ Array
Returns an array of licenses for the gem.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#maintainer ⇒ String
Returns the package’s maintainer.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#makedepends ⇒ Array
Returns a list of the dependencies needed to build the package (normally just the package rubygems).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#noextract ⇒ Array
Returns a list of sources not to extract with bsdtar (namely, the gemfile).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#options ⇒ Array
Returns a list of options to pass to makepkg.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#pkgname ⇒ String
Returns the name of the package (usually ruby-gem).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#pkgrel ⇒ Fixnum
Returns the release number of the package.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#pkgver ⇒ Gem::Version
Returns the version of the gem.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#source ⇒ Array
Returns a list of sources.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
#url ⇒ String
Returns the URL of the homepage of the gem.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gembuild/pkgbuild.rb', line 78 class Pkgbuild attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends, :description, :epoch, :gemname, :license, :maintainer, :makedepends, :noextract, :options, :pkgname, :pkgrel, :pkgver, :source, :url # Create a new Pkgbuild instance. # # @raise [Gembuild::InvalidPkgbuildError] if something other than a # string or nil is passed as the existing pkgbuild # # @param gemname [String] The rubygem for which to create a PKGBUILD. # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be # parsed for maintainer and contributor information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def initialize(gemname, existing_pkgbuild = nil) unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String) fail Gembuild::InvalidPkgbuildError end @gemname = gemname @pkgname = "ruby-#{@gemname}" set_package_defaults no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty? parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild end # Parse the old pkgbuild (if it exists) to get information about old # maintainers or contributors or about other dependencies that have been # added but that can not be scraped from rubygems.org. # # @param pkgbuild [String] The old PKGBUILD to parse. # @return [Hash] a hash containing the values scraped from the PKGBUILD def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end # Create a new Pkgbuild instance with all information from the scraped # sources assigned. # # @param gemname [String] The rubygem for which to create a Pkgbuild. # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be # parsed for maintainer information. # @return [Gembuild::Pkgbuild] a new Pkgbuild instance def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end # Generate a PKGBUILD from the class using the pkgbuild erb template. # # @return [String] the PKGBUILD def render ERB.new(template, 0, '-').result(binding) end # Get the PKGBUILD erb template. # # @return [String] the pkgbuild erb template def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end # Write the PKGBUILD to disk. # # @param path [String] The directory to write the PKGBUILD. # @return [Fixnum] the number of bytes written def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end # Obfuscate the maintainer/contributors' email addresses to (help to) # prevent spam. # # @param contact_information [String] The maintainer or contributor # byline. # @return [String] the information with the @s and .s exchanged def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end # Set the correct maintainer for the PKGBUILD. # # If the current maintainer is nil (no old pkgbuild was passed), then do # nothing. If there is a maintainer then compare it to the configured # maintainer and if they are different then make the old maintainer a # contributor before setting the correct maintainer. If the maintainer is # nil then just set the confgured maintainer. # # @return [String] the pkgbuild maintainer def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end # Add the data scraped from rubygems.org to the pkgbuild. # # @param details [Hash] The results from GemScraper scrape. # @return [void] def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end # Assign version information based on the information gathered from the # AUR. # # @param details [Hash, nil] The results from AurScraper scrape or nil if # the package does not yet exist on the AUR. # @return [void] def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end private # Set the static variables of a new pkgbuild. # # @return [nil] def set_package_defaults @checksum_type = 'sha256' @arch = ['any'] @makedepends = ['rubygems'] @depends = ['ruby'] @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem'] @noextract = ['$_gemname-$pkgver.gem'] = ['!emptydirs'] @contributor = [] nil end # Scrape dependencies from an existing pkgbuild. # # @param pkgbuild [String] The PKGBUILD to search. # @return [Array] all existing dependencies that are not ruby or gems def parse_existing_dependencies(pkgbuild) match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1] # First step is to remove the leading and trailing quotes. Then convert # all whitespace (newlines, tabs, multiple spaces, etc.) to single # spaces. Then, make sure that strings are quoted with ' not ". # Finally, split the packages into an array. deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '") deps.reject { |e| e.match(/^ruby/) } rescue [] end # Assign the correct pkgrel and epoch depending on the current pkgver on # the AUR and the version of the gem from rubygems.org. # # @param details [Hash] The results from AurScraper scrape # @return [void] def perform_version_reconciliation(details) @epoch = details.fetch(:epoch) @pkgrel = 1 if pkgver < details.fetch(:pkgver) @epoch += 1 elsif @pkgver == details.fetch(:pkgver) @pkgrel = details.fetch(:pkgrel) + 1 end end end |
Class Method Details
.create(gemname, existing_pkgbuild = nil) ⇒ Gembuild::Pkgbuild
Create a new Pkgbuild instance with all information from the scraped sources assigned.
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/gembuild/pkgbuild.rb', line 133 def self.create(gemname, existing_pkgbuild = nil) pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild) pkgbuild.fetch_maintainer gem_details = Gembuild::GemScraper.new(gemname).scrape! aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape! pkgbuild.assign_gem_details(gem_details) pkgbuild.assign_aur_details(aur_details) pkgbuild end |
Instance Method Details
#assign_aur_details(details) ⇒ void
This method returns an undefined value.
Assign version information based on the information gathered from the AUR.
222 223 224 225 226 227 228 229 |
# File 'lib/gembuild/pkgbuild.rb', line 222 def assign_aur_details(details) if details.nil? @epoch = 0 @pkgrel = 1 else perform_version_reconciliation(details) end end |
#assign_gem_details(details) ⇒ void
This method returns an undefined value.
Add the data scraped from rubygems.org to the pkgbuild.
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/gembuild/pkgbuild.rb', line 204 def assign_gem_details(details) @pkgver = details.fetch(:version) @description = details.fetch(:description) @checksum = details.fetch(:checksum) @license = details.fetch(:license) @url = details.fetch(:homepage) details.fetch(:dependencies).each do |dependency| @depends << "ruby-#{dependency}" end end |
#fetch_maintainer ⇒ String
Set the correct maintainer for the PKGBUILD.
If the current maintainer is nil (no old pkgbuild was passed), then do nothing. If there is a maintainer then compare it to the configured maintainer and if they are different then make the old maintainer a contributor before setting the correct maintainer. If the maintainer is nil then just set the confgured maintainer.
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/gembuild/pkgbuild.rb', line 188 def fetch_maintainer configured_maintainer = Gembuild.configure m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>" new_maintainer = format_contact_information(m) unless maintainer.nil? || new_maintainer == maintainer @contributor.unshift(maintainer) end @maintainer = new_maintainer end |
#format_contact_information(contact_information) ⇒ String
Obfuscate the maintainer/contributors’ email addresses to (help to) prevent spam.
175 176 177 |
# File 'lib/gembuild/pkgbuild.rb', line 175 def format_contact_information(contact_information) contact_information.gsub('@', ' at ').gsub('.', ' dot ') end |
#parse_existing_pkgbuild(pkgbuild) ⇒ Hash
Parse the old pkgbuild (if it exists) to get information about old maintainers or contributors or about other dependencies that have been added but that can not be scraped from rubygems.org.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/gembuild/pkgbuild.rb', line 113 def parse_existing_pkgbuild(pkgbuild) pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] } @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten deps = parse_existing_dependencies(pkgbuild) deps.each do |dep| @depends << dep end { maintainer: maintainer, contributor: contributor, depends: deps } end |
#render ⇒ String
Generate a PKGBUILD from the class using the pkgbuild erb template.
150 151 152 |
# File 'lib/gembuild/pkgbuild.rb', line 150 def render ERB.new(template, 0, '-').result(binding) end |
#template ⇒ String
Get the PKGBUILD erb template.
157 158 159 |
# File 'lib/gembuild/pkgbuild.rb', line 157 def template File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb')) end |
#write(path = '') ⇒ Fixnum
Write the PKGBUILD to disk.
165 166 167 |
# File 'lib/gembuild/pkgbuild.rb', line 165 def write(path = '') File.write(File.join(File.(path), 'PKGBUILD'), render) end |