euscan: add kde handler and fix some regex issues

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary 2011-12-30 11:34:39 +01:00
parent d673c00e12
commit b78e73038d
4 changed files with 50 additions and 7 deletions

View File

@ -1,9 +1,6 @@
from euscan.handlers import generic from euscan.handlers import generic, php, pypi, rubygem, kde
from euscan.handlers import php
from euscan.handlers import pypi
from euscan.handlers import rubygem
handlers = [ php, pypi, rubygem, generic ] handlers = [ kde, php, pypi, rubygem, generic ]
def find_best_handler(cpv, url): def find_best_handler(cpv, url):
for handler in handlers: for handler in handlers:

View File

@ -18,6 +18,7 @@ def scan_html(data, url, pattern):
href = link.get("href") href = link.get("href")
if not href: if not href:
continue continue
if href.startswith(url): if href.startswith(url):
href = href.replace(url, "", 1) href = href.replace(url, "", 1)

View File

@ -0,0 +1,34 @@
from euscan.handlers import generic
def can_handle(cpv, url):
if url.startswith('mirror://kde/'):
return True
return False
def clean_results(results):
ret = []
for path, version in results:
if version == '5SUMS':
continue
ret.append((path, version))
return ret
def scan(cpv, url):
results = generic.scan(cpv, url)
if url.startswith('mirror://kde/unstable/'):
url = url.replace('mirror://kde/unstable/', 'mirror://kde/stable/')
results += generic.scan(cpv, url)
return clean_results(results)
def brute_force(cpv, url):
results = generic.brute_force(cpv, url)
if url.startswith('mirror://kde/unstable/'):
url = url.replace('mirror://kde/unstable/', 'mirror://kde/stable/')
results += generic.brute_force(cpv, url)
return clean_results(results)

View File

@ -334,16 +334,26 @@ def tryurl(fileurl, template):
return result return result
def regex_from_template(template): def regex_from_template(template):
# Escape
template = re.escape(template) template = re.escape(template)
# Unescape specific stuff
template = template.replace('\$\{', '${') template = template.replace('\$\{', '${')
template = template.replace('\}', '}') template = template.replace('\}', '}')
template = template.replace('}\.$', '}.$') template = template.replace('}\.$', '}.$')
template = template.replace('${1}', r'([\d]+?)')
template = re.sub(r'(\$\{\d+\}\.?)+', r'([\w]+?)', template) # Replace ${\d+}
#template = template.replace('${0}', r'([\d]+?)')
template = re.sub(r'(\$\{\d+\}(\.?))+', r'([\w\.]+?)', template)
#template = re.sub(r'(\$\{\d+\}\.?)+', r'([\w]+?)', template) #template = re.sub(r'(\$\{\d+\}\.?)+', r'([\w]+?)', template)
#template = re.sub(r'(\$\{\d+\}\.+)+', '(.+?)\.', template) #template = re.sub(r'(\$\{\d+\}\.+)+', '(.+?)\.', template)
#template = re.sub(r'(\$\{\d+\})+', '(.+?)', template) #template = re.sub(r'(\$\{\d+\})+', '(.+?)', template)
# Full version
template = template.replace('${PV}', _v) template = template.replace('${PV}', _v)
# End
template = template + r'/?$' template = template + r'/?$'
return template return template
@ -372,6 +382,7 @@ def generate_scan_paths(url):
else: else:
path += "/" path += "/"
path += chunk path += chunk
return steps return steps
def parse_mirror(uri): def parse_mirror(uri):