2023-11-15 21:31:08 +01:00
|
|
|
# Copyright 2011 Corentin Chary <corentin.chary@gmail.com>
|
|
|
|
# Copyright 2020-2023 src_prepare group
|
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
import json
|
|
|
|
import re
|
2019-12-05 17:46:19 +01:00
|
|
|
import urllib.error
|
|
|
|
import urllib.parse
|
|
|
|
import urllib.request
|
2023-11-14 22:04:18 +01:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
import portage
|
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
from euscan import helpers, mangling, output
|
2012-05-23 16:30:43 +02:00
|
|
|
|
2012-07-26 17:46:53 +02:00
|
|
|
HANDLER_NAME = "rubygems"
|
2012-07-27 11:26:54 +02:00
|
|
|
CONFIDENCE = 100
|
2012-07-24 15:02:36 +02:00
|
|
|
PRIORITY = 90
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def can_handle(pkg, url=None):
|
|
|
|
return url and url.startswith("mirror://rubygems/")
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
def guess_gem(cpv, url):
|
|
|
|
match = re.search("mirror://rubygems/(.*).gem", url)
|
|
|
|
if match:
|
|
|
|
cpv = "fake/%s" % match.group(1)
|
|
|
|
|
2012-03-02 13:54:23 +01:00
|
|
|
ret = portage.pkgsplit(cpv)
|
|
|
|
if not ret:
|
|
|
|
return None
|
|
|
|
|
|
|
|
cp, ver, rev = ret
|
2011-08-31 15:38:32 +02:00
|
|
|
cat, pkg = cp.split("/")
|
|
|
|
|
|
|
|
return pkg
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def scan_url(pkg, url, options):
|
2011-08-31 15:38:32 +02:00
|
|
|
"http://guides.rubygems.org/rubygems-org-api/#gemversion"
|
|
|
|
|
2012-07-24 08:56:00 +02:00
|
|
|
gem = guess_gem(pkg.cpv, url)
|
2012-07-26 17:46:53 +02:00
|
|
|
|
2012-03-02 13:54:23 +01:00
|
|
|
if not gem:
|
2023-11-16 04:56:40 +01:00
|
|
|
output.eerror(f"Can't guess gem name using {pkg.cpv} and {url}")
|
2012-03-02 13:54:23 +01:00
|
|
|
return []
|
|
|
|
|
2012-07-26 17:46:53 +02:00
|
|
|
output.einfo("Using RubyGem API: %s" % gem)
|
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
return scan_pkg(pkg, {"data": gem})
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-07-26 17:46:53 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def scan_pkg(pkg, options):
|
|
|
|
gem = options["data"]
|
2012-07-26 17:46:53 +02:00
|
|
|
url = "http://rubygems.org/api/v1/versions/%s.json" % gem
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
try:
|
2011-09-06 09:17:08 +02:00
|
|
|
fp = helpers.urlopen(url)
|
2019-12-05 17:46:19 +01:00
|
|
|
except urllib.error.URLError:
|
2011-08-31 15:38:32 +02:00
|
|
|
return []
|
2023-11-16 05:15:48 +01:00
|
|
|
except OSError:
|
2011-08-31 15:38:32 +02:00
|
|
|
return []
|
|
|
|
|
2011-09-06 16:32:29 +02:00
|
|
|
if not fp:
|
|
|
|
return []
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
data = fp.read()
|
|
|
|
versions = json.loads(data)
|
|
|
|
|
2012-07-24 08:56:00 +02:00
|
|
|
cp, ver, rev = portage.pkgsplit(pkg.cpv)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
ret = []
|
|
|
|
for version in versions:
|
2012-04-19 15:36:44 +02:00
|
|
|
up_pv = version["number"]
|
2012-08-03 21:50:54 +02:00
|
|
|
pv = mangling.mangle_version(up_pv, options)
|
2012-04-19 15:36:44 +02:00
|
|
|
if helpers.version_filtered(cp, ver, pv):
|
2011-08-31 15:38:32 +02:00
|
|
|
continue
|
2023-11-16 04:56:40 +01:00
|
|
|
url = f"http://rubygems.org/gems/{gem}-{up_pv}.gem"
|
2012-08-03 21:50:54 +02:00
|
|
|
url = mangling.mangle_url(url, options)
|
|
|
|
ret.append((url, pv, HANDLER_NAME, CONFIDENCE))
|
2011-08-31 15:38:32 +02:00
|
|
|
return ret
|