[Scons-users] first builder / download
    Dirk Bächle 
    tshortik at gmx.de
       
    Fri Aug 17 02:59:48 EDT 2012
    
    
  
Hi Phil,
On 17.08.2012 07:42, Philipp Kraus wrote:
>
>
> For example I try to download the newest version of the LUA sources, 
> so I create a function for parsing the HTML page source
>
> def LUA_DownloadURL()  :
>    # read download path of the LUA library (latest version)
>    f = urllib2.urlopen("http://www.lua.org/download.html")
>    html = f.read()
>    f.close()
>
>    found = re.search("<a href=\"ftp/lua-(.*)\.tar\.gz\">", html, 
> re.IGNORECASE)
>    if found == None :
>        raise RuntimeError("LUA Download URL not found")
>
>    downloadurl = found.group(0)
>
>    downloadurl = downloadurl.replace("\"", "")
>    downloadurl = downloadurl.replace("<", "")
>    downloadurl = downloadurl.replace(">", "")
>    downloadurl = re.sub(r'(?i)a href=', "", downloadurl)
>    downloadurl = "http://www.lua.org/" + downloadurl
>
>    filename    = downloadurl.split("/")[-1]
>
>    return downloadurl, filename
>
> The function must return first the URL of the download and on second 
> the target filename, the main scons script shows:
>
> x = env.ParseAndDownload( LUA_DownloadURL )
>
> and in x is the target filename stored (actually lua-5.2.1.tar.gz)
>
> Can you send me some tips to create better code?
>
> Thanks
>
> Phil
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> http://four.pairlist.net/mailman/listinfo/scons-users
>
in total, wouldn't it be easier to simply check whether the target file 
from your download exists with Python?
Something like:
   url, target = LUA_DownloadURL()
   if not os.path.isfile(target):
     # Download file here
I fail to see what you are winning when you try to use SCons constructs 
for the download. Having the file "to download" 
(http://www.lua.org/whatever) connected to the dependency graph would 
mean that SCons has to download the file each and every time the user 
starts a build. Just to check whether the file changed, 
accidentally...you never know, better make sure.
Is this really what you want to happen in the end?
Oh, and thanks a lot for "finally" telling us what you really intend to 
do with all that code of yours. ;)
Best regards,
Dirk
    
    
More information about the Scons-users
mailing list