2011-08-31 15:38:32 +02:00
|
|
|
import re
|
|
|
|
import portage
|
|
|
|
import json
|
2019-12-05 17:46:19 +01:00
|
|
|
import urllib.request, urllib.error, urllib.parse
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
from euscan import helpers, output, mangling
|
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:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.eerror("Can't guess gem name using %s and %s" % \
|
2012-07-24 08:56:00 +02:00
|
|
|
(pkg.cpv, 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 []
|
|
|
|
except IOError:
|
|
|
|
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
|
2012-04-19 15:36:44 +02:00
|
|
|
url = 'http://rubygems.org/gems/%s-%s.gem' % (gem, up_pv)
|
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
|