Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 69D6D9FB399 for ; Mon, 9 Apr 2007 20:35:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 74190-08 for ; Mon, 9 Apr 2007 20:35:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from h07.llord.com (unknown [195.140.142.194]) by postgresql.org (Postfix) with ESMTP id C45DF9FB2F5 for ; Mon, 9 Apr 2007 20:35:42 -0300 (ADT) Received: from par69-8-88-161-102-87.fbx.proxad.net ([88.161.102.87] helo=apollo13) by h07.llord.com with esmtpa (Exim 4.63) (envelope-from ) id 1Hb3Of-0008Ju-H7; Tue, 10 Apr 2007 01:35:42 +0200 Date: Tue, 10 Apr 2007 01:36:02 +0200 To: "Andrew Hammond" , "CAJ CAJ" Subject: Re: programmatic way to fetch latest release for a given major.minor version From: Listmail Cc: pgsql-general@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <1176155240.221125.319880@y80g2000hsf.googlegroups.com> <467669b30704091526v79ae044boe7217cc0777dce1f@mail.gmail.com> <5a0a9d6f0704091534i4e4af90co2dad0e9e0b60efee@mail.gmail.com> Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <5a0a9d6f0704091534i4e4af90co2dad0e9e0b60efee@mail.gmail.com> User-Agent: Opera Mail/9.10 (Linux) X-PopBeforeSMTPSenders: junk@peufeu.com, lists@peufeu.com, peufeu@peufeu.com, pfcaillaud@peufeu.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - h07.llord.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - peufeu.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.911 tagged_above=0 required=5 tests=AWL=0.246, BAYES_05=-1.11, RCVD_IN_NJABL_SPAM=2.775 X-Spam-Level: * X-Archive-Number: 200704/408 X-Sequence-Number: 112311 Here you go. Fetches versions and prints most recent minor for each major Tests all mirrors for speed and prints out the 4 fastest (takes some ti= me) http://www.crummy.com/software/BeautifulSoup/ Have a nice day ! #! /bin/env python # -*- coding: utf-8 -*- import urllib, BeautifulSoup, re, time, sys def get_all_versions(): soup =3D = BeautifulSoup.BeautifulSoup( urllib.urlopen( "http://ftp3.fr.postgresql.= org/pub/postgresql/source/" = ).read() ) for a in soup( 'a', {'href': re.compile( r"v\d+.\d+.\d+" ) } ): yield map( int, re.search( r"v(\d+)\.(\d+)\.(\d+)*", a['href'] = ).groups() ) def get_latest_versions(): lastversions =3D {} for a,b,c in sorted( get_all_versions() ): lastversions[ (a,b) ] =3D c return sorted( lastversions.items() ) def parse_query_string( url ): return dict( map( urllib.unquote_plus, pair.split('=3D',1) ) for pair i= n = re.split( "&(?:amp;|)", urllib.splitquery( url )[1] ) ) def get_mirrors(): soup =3D = BeautifulSoup.BeautifulSoup( urllib.urlopen( "http://wwwmaster.postgresq= l.org/download/mirrors-ftp" = ).read() ) for a in soup( 'a', {'href': re.compile( r"\?setmir=3D.*url=3D" ) } ): yield parse_query_string( a['href'] )['url'] def get_fastest_mirrors( urls, filename ): for url in urls: sys.stdout.write( " %s\r" % url ) t =3D time.time() try: urllib.urlopen( url + filename ) except: pass d =3D time.time()-t print "%.02f s" % d yield d, url for major, minor in get_latest_versions(): print "%d.%d.%d" % (major[0], major[1], minor) mirrors =3D get_mirrors() fastest =3D sorted( get_fastest_mirrors( mirrors, "sync_timestamp" ))[:4= ] for d, mirror in fastest: print "%.02f s %s" % (d,mirror) On Tue, 10 Apr 2007 00:34:02 +0200, Andrew Hammond = wrote: > On 4/9/07, CAJ CAJ wrote: >> On 9 Apr 2007 14:47:20 -0700, Andrew Hammond >> wrote: >> > I'm writing a script that wants to know the latest release for a gi= ven >> > major.minor version. Is there some better way than parsing >> > http://www.postgresql.org/ftp/source/ or trying to >> connect to ftp >> > (which is invariably timing out on me today. Is that box getting >> > hammered or something?) and doing the parsing that? Both approaches= >> > feel quite awkward to me. >> >> Use wget to download via HTTP (added recently). Probably wise to ad= d a >> couple mirrors in your script. > > I'm not asking how to download stuff. I'm asking how to figure out the= > current release number for a given major.minor. I thought that was > clear in my original post, but I guess not. For example, how do I > determine (programmatically) the lastest version of 8.1. > > I'm also interested in a clever way to select one of the "close" > mirrors at random for downloading via http. However I had planned to > hold that question until I'd solved the first issue. > > Andrew > > ---------------------------(end of broadcast)-------------------------= -- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq