2011-08-31 15:38:32 +02:00
|
|
|
import re
|
|
|
|
import portage
|
2019-12-05 17:46:19 +01:00
|
|
|
import urllib.request, urllib.error, urllib.parse
|
2011-08-31 15:38:32 +02:00
|
|
|
import xml.dom.minidom
|
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
from euscan import helpers, output, mangling
|
2012-05-23 16:30:43 +02:00
|
|
|
|
|
|
|
HANDLER_NAME = "php"
|
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-08-03 21:50:54 +02:00
|
|
|
def can_handle(pkg, url=None):
|
2011-08-31 15:38:32 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
def guess_package_and_channel(cp, url):
|
2012-08-03 21:50:54 +02:00
|
|
|
match = re.search('http://(.*)\.php\.net/get/(.*)-(.*).tgz', url)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
if match:
|
|
|
|
host = match.group(1)
|
|
|
|
pkg = match.group(2)
|
|
|
|
else:
|
|
|
|
cat, pkg = cp.split("/")
|
|
|
|
|
|
|
|
return pkg, host
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def scan_url(pkg, url, options):
|
|
|
|
package, channel = guess_package_and_channel(pkg.cp, url)
|
|
|
|
return scan_pkg(pkg, {'type' : channel, 'data' : package })
|
|
|
|
|
|
|
|
def scan_pkg(pkg, options):
|
|
|
|
cp, ver, rev = pkg.cp, pkg.version, pkg.revision
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
package = options['data']
|
|
|
|
channel = options['type']
|
|
|
|
|
|
|
|
url = 'http://%s.php.net/rest/r/%s/allreleases.xml' % (channel, package.lower())
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
output.einfo("Using: " + url)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
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()
|
|
|
|
|
|
|
|
dom = xml.dom.minidom.parseString(data)
|
|
|
|
|
|
|
|
nodes = dom.getElementsByTagName("v")
|
|
|
|
ret = []
|
|
|
|
|
|
|
|
for node in nodes:
|
2012-04-19 15:36:44 +02:00
|
|
|
up_pv = node.childNodes[0].data
|
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-08-03 21:50:54 +02:00
|
|
|
url = 'http://%s.php.net/get/%s-%s.tgz' % (channel, package, up_pv)
|
|
|
|
url = mangling.mangle_url(url, options)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-23 16:44:44 +02:00
|
|
|
ret.append((url, pv, HANDLER_NAME, CONFIDENCE))
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
return ret
|