73 lines
1.7 KiB
Ruby
73 lines
1.7 KiB
Ruby
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
# frozen_string_literal: true
|
|
|
|
class Package
|
|
attr_reader :path, :version, :homepage, :requires
|
|
|
|
def initialize(path, version:, homepage:, requires: [])
|
|
@path = path
|
|
@version = version
|
|
@homepage = homepage
|
|
@requires = requires
|
|
end
|
|
|
|
def name
|
|
File.basename @path
|
|
end
|
|
end
|
|
|
|
class Download
|
|
attr_reader :download, :md5sum
|
|
|
|
def initialize(download, md5sum, is64: false)
|
|
@download = download
|
|
@md5sum = md5sum
|
|
@is64 = is64
|
|
end
|
|
|
|
def is64?
|
|
@is64
|
|
end
|
|
end
|
|
|
|
def info_template(package, downloads)
|
|
downloads64, downloads32 = downloads.partition(&:is64?)
|
|
download32, md5sum32, download64, md5sum64 = download_entries downloads64, downloads32
|
|
|
|
<<~INFO_FILE
|
|
PRGNAM="#{package.name}"
|
|
VERSION="#{package.version}"
|
|
HOMEPAGE="#{package.homepage}"
|
|
DOWNLOAD="#{download32}"
|
|
MD5SUM="#{md5sum32}"
|
|
DOWNLOAD_x86_64="#{download64}"
|
|
MD5SUM_x86_64="#{md5sum64}"
|
|
REQUIRES="#{requires_entry package.requires}"
|
|
MAINTAINER="Eugene Wissner"
|
|
EMAIL="belka@caraus.de"
|
|
INFO_FILE
|
|
end
|
|
|
|
private
|
|
|
|
def requires_entry(requires)
|
|
requires.empty? ? '%README%' : requires * ' '
|
|
end
|
|
|
|
def download_entries(downloads64, downloads32)
|
|
download32 =
|
|
if downloads32.empty? && !downloads64.empty?
|
|
'UNSUPPORTED'
|
|
else
|
|
downloads32.map(&:download) * " \\\n "
|
|
end
|
|
md5sum32 = downloads32.map(&:md5sum) * " \\\n "
|
|
download64 = downloads64.map(&:download) * " \\\n "
|
|
md5sum64 = downloads64.map(&:md5sum) * " \\\n "
|
|
|
|
[download32, md5sum32, download64, md5sum64]
|
|
end
|