stefan pushed a commit to branch master.

http://git.enlightenment.org/admin/release-management.git/commit/?id=ea9e68c45502cf197cd4730714912cf82275bade

commit ea9e68c45502cf197cd4730714912cf82275bade
Author: Stefan Schmidt <s.schm...@samsung.com>
Date:   Mon Apr 13 14:12:59 2015 +0200

    distributions: Add script from Leif to fetch versions from distros
    
    This is the script Leif posted on https://phab.enlightenment.org/P115 to 
show
    how we could automatically fetch the versions from distro page.
    
    I will try to extend it to cover more distros and automatically generate the
    table as output.
---
 distributions_versions_fetch_script.py | 47 ++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/distributions_versions_fetch_script.py 
b/distributions_versions_fetch_script.py
new file mode 100755
index 0000000..d0217d2
--- /dev/null
+++ b/distributions_versions_fetch_script.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python2
+
+import re
+from lxml import html
+import requests
+
+def grep_version_string(repo_listing, pkg_name_prefix):
+       regex = pkg_name_prefix + "[0-9.]+"
+       p = re.compile(regex)
+       match = re.search(p, repo_listing)
+       if match is None:
+               return None
+       first_match = match.group(0)
+       if first_match is not None:
+               #remove the first package name prefix
+               return first_match.strip(pkg_name_prefix)
+       return None
+
+def scrap_page(url, xpath, pkg_name_prefix):
+       html_page = requests.get(url)
+       tree = html.fromstring(html_page.text)
+       html_text = tree.xpath(xpath)[0] # use first node
+       pkgversion = grep_version_string(html_text, pkg_name_prefix)
+       if pkgversion != None:
+               return pkgversion
+       return None
+
+def main():
+       distributions_data  = [
+                                                       ("arch", 
"https://www.archlinux.org/packages/extra/x86_64/efl/";, 
"/html/body/div[@id=\"content\"]/div[@id=\"pkgdetails\"]/h2/text()", "efl "),
+                                                       ("ubuntu", 
"https://launchpad.net/ubuntu/vivid/amd64/libecore-con1/1.8.6-2.1ubuntu1";, 
"//*[@id=\"portlet-details\"]/div/dl[1]/dd/text()", ""),
+                                                       ("debian", 
"https://tracker.debian.org/pkg/efl";, 
"//*[@id=\"dtracker-package-left\"]/div[1]/div[2]/ul/li[2]/div[2]/text()", ""),
+                                                       ("fedora", 
"https://apps.fedoraproject.org/packages/efl";, 
"//*[@id=\"package-info-bar\"]/div[1]/div[2]/text()", ""),
+                                                       ("elive", 
"http://repository.elivecd.org/pool/efl/libe/libefl/";, 
"/html/body/pre/a/text()[starts-with(.,'libefl1_')]", "libefl1_"),
+                                                       ("openSuSE 13.2", 
"http://download.opensuse.org/ports/update/13.2/aarch64/";, 
"/html/body/pre/a/text()[starts-with(., 'efl-')]", "efl-"),
+                                                       ("gentoo", 
"https://packages.gentoo.org/package/dev-libs/efl";, 
"//td[@class=\"ebuild\"][2]/text()", ""),
+                                                       ("Tizen (Common)", 
"https://build.tizen.org/package/binaries?package=efl&project=Tizen%3ACommon&repository=x86_64-x11";,
 "//*[@id=\"content\"]/div/ul//li/a/text()[starts-with(., 'efl-')]", "efl-")
+                                                       ]
+       for param_set in distributions_data:
+               distri = param_set[0]
+               url = param_set[1]
+               xpath = param_set[2]
+               pkg_name_prefix = param_set[3]
+               print "%s: %s" % (distri, scrap_page(url, xpath, 
pkg_name_prefix))
+
+if __name__ == '__main__':
+       main()

-- 


Reply via email to