2011-08-31 15:38:32 +02:00
|
|
|
import re
|
|
|
|
import portage
|
|
|
|
import json
|
|
|
|
import urllib2
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
from euscan import helpers, output
|
|
|
|
|
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-07-24 08:56:00 +02:00
|
|
|
def can_handle(pkg, url):
|
2011-08-31 15:38:32 +02:00
|
|
|
return url.startswith('mirror://rubygems/')
|
|
|
|
|
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-07-24 08:56:00 +02:00
|
|
|
def scan(pkg, url):
|
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)
|
|
|
|
|
|
|
|
ret = []
|
|
|
|
for url, pv in scan_remote(pkg, [gem]):
|
|
|
|
ret.append(url, pv, HANDLER_NAME, CONFIDENCE)
|
|
|
|
return ret
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-07-26 17:46:53 +02:00
|
|
|
|
|
|
|
def scan_remote(pkg, remote_data):
|
|
|
|
gem = remote_data[0]
|
|
|
|
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)
|
2011-08-31 15:38:32 +02:00
|
|
|
except urllib2.URLError:
|
|
|
|
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']
|
|
|
|
pv = helpers.gentoo_mangle_version(up_pv)
|
|
|
|
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-07-26 17:46:53 +02:00
|
|
|
ret.append((url, pv))
|
2011-08-31 15:38:32 +02:00
|
|
|
return ret
|