-# -*- coding: utf-8 -*-\r
-\r
-############################################################################\r
-# GPL License #\r
-# #\r
-# This file is a SCons (http://www.scons.org/) builder #\r
-# Copyright (c) 2012-14, Philipp Kraus, <philipp.kraus@flashpixx.de> #\r
-# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. #\r
-# This program is free software: you can redistribute it and/or modify #\r
-# it under the terms of the GNU General Public License as #\r
-# published by the Free Software Foundation, either version 3 of the #\r
-# License, or (at your option) any later version. #\r
-# #\r
-# This program is distributed in the hope that it will be useful, #\r
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #\r
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #\r
-# GNU General Public License for more details. #\r
-# #\r
-# You should have received a copy of the GNU General Public License #\r
-# along with this program. If not, see <http://www.gnu.org/licenses/>. #\r
-############################################################################\r
-\r
-# the URLDownload-Builder can download any data from an URL into a target\r
-# file. The target name is used are the file name of the downloaded file.\r
-\r
-# This builder originated from work by Philipp Kraus and flashpixx project\r
-# (see https://github.com/flashpixx). It has been modified to leverage\r
-# the HTTP ETag header to be used as the csig. This allows the download\r
-# builder to determine if the file should be downloaded again when the\r
-# ETag header is supported\r
-\r
-import os, time\r
-import urllib2, urlparse\r
-import SCons.Builder, SCons.Node, SCons.Errors\r
-\r
-# Define a source node to represent the remote file. The construction of the\r
-# node will query the hosting site to get the ETag, size and last-modified\r
-# date. This node also defines the method by which we will determine if\r
-# the file should be downloaded again.\r
-#\r
-# This node derives from the Python.Value node\r
-#\r
-class URLNode(SCons.Node.Python.Value) :\r
- def make_ready(self) :\r
- try :\r
- stream = urllib2.urlopen( str(self.value) )\r
- info = stream.info()\r
-\r
- self.url_etag = None\r
- self.url_last_modified = None\r
- self.url_content_length = None\r
-\r
- if 'ETag' in info :\r
- self.url_etag = info['ETag']\r
- if 'Last-Modified' in info :\r
- self.url_last_modified = time.mktime(time.strptime(info['Last-Modified'], '%a, %d %b %Y %H:%M:%S GMT'))\r
- if 'Content-Length' in info :\r
- self.url_content_legth = info['Content-Length']\r
- except Exception, e :\r
- raise SCons.Errors.StopError( '%s [%s]' % (e, self.value) )\r
-\r
- def visited(self) :\r
- ninfo = self.get_ninfo()\r
-\r
- if self.url_etag :\r
- ninfo.csig = self.url_etag\r
- if self.url_last_modified :\r
- ninfo.timestamp = self.url_last_modified\r
- if self.url_content_length :\r
- ninfo.size = self.url_content_length\r
- SCons.Node.Node.visited(self);\r
-\r
- def changed_since_last_build(self, target, prev_ni):\r
- if prev_ni :\r
- if self.url_etag :\r
- if prev_ni.csig == self.url_etag :\r
- # print 'Matched on ETag:'+prev_ni.csig\r
- return False\r
-\r
- if not self.url_last_modified :\r
- # print 'Last modified date is not available'\r
- return True\r
- if not self.url_content_length :\r
- # print 'Content length is not available'\r
- return True\r
- if prev_ni.timestamp != self.url_last_modified :\r
- # print 'Modified since last build'\r
- return True\r
- if prev_ni.size != self.url_content_length :\r
- # print 'Content length has changed'\r
- return True\r
-\r
- return False\r
-\r
- # print 'Not previous built'\r
- return True\r
-\r
-# Creates the output message\r
-# @param s original message\r
-# @param target target name\r
-# @param source source name\r
-# @param env environment object\r
-def __message( s, target, source, env ) :\r
- print 'downloading [%s] from [%s] ...' % (target[0], source[0])\r
-\r
-# Creates the action ie. the download function.\r
-# This reads the data from the URL and writes it down to the file\r
-# @param target target file on the local drive\r
-# @param source URL for download\r
-# @@param env environment object\r
-def __action( target, source, env ) :\r
- try :\r
- source_name = str(source[0])\r
- target_name = str(target[0])\r
- stream = urllib2.urlopen(source_name)\r
- file = open( target_name, 'wb' )\r
- file.write(stream.read())\r
- file.close()\r
-\r
- # Change the access/modified time to match\r
- # the date on the downloaded file, if available\r
- ninfo = source[0].get_ninfo()\r
- if hasattr(ninfo, 'timestamp') :\r
- mtime = ninfo.timestamp\r
- if mtime :\r
- os.utime(target_name, (mtime, mtime))\r
- except Exception, e :\r
- raise SCons.Errors.StopError( '%s [%s]' % (e, source[0]) )\r
-\r
-\r
-# Defines the emitter of the builder\r
-# @param target target file on the local drive\r
-# @param source URL for download\r
-# @param env environment object\r
-def __emitter( target, source, env ) :\r
- return target, source\r
-\r
-# generate function, that adds the builder to the environment,\r
-# @param env environment object\r
-def generate( env ) :\r
- env['BUILDERS']['URLDownload'] = SCons.Builder.Builder( action = __action, emitter = __emitter, target_factory = SCons.Node.FS.File, source_factory = URLNode, single_source = True, PRINT_CMD_LINE_FUNC = __message )\r
-\r
-# existing function of the builder\r
-# @param env environment object\r
-# @return true\r
-def exists(env) :\r
- return 1\r
+# -*- coding: utf-8 -*-
+
+############################################################################
+# GPL License #
+# #
+# This file is a SCons (http://www.scons.org/) builder #
+# Copyright (c) 2012-14, Philipp Kraus, <philipp.kraus@flashpixx.de> #
+# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as #
+# published by the Free Software Foundation, either version 3 of the #
+# License, or (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+############################################################################
+
+# the URLDownload-Builder can download any data from an URL into a target
+# file. The target name is used are the file name of the downloaded file.
+
+# This builder originated from work by Philipp Kraus and flashpixx project
+# (see https://github.com/flashpixx). It has been modified to leverage
+# the HTTP ETag header to be used as the csig. This allows the download
+# builder to determine if the file should be downloaded again when the
+# ETag header is supported
+
+import os, time
+import urllib2, urlparse
+import SCons.Builder, SCons.Node, SCons.Errors
+
+# Define a source node to represent the remote file. The construction of the
+# node will query the hosting site to get the ETag, size and last-modified
+# date. This node also defines the method by which we will determine if
+# the file should be downloaded again.
+#
+# This node derives from the Python.Value node
+#
+class URLNode(SCons.Node.Python.Value) :
+ def make_ready(self) :
+ try :
+ stream = urllib2.urlopen( str(self.value) )
+ info = stream.info()
+
+ self.url_etag = None
+ self.url_last_modified = None
+ self.url_content_length = None
+
+ if 'ETag' in info :
+ self.url_etag = info['ETag']
+ if 'Last-Modified' in info :
+ self.url_last_modified = time.mktime(time.strptime(info['Last-Modified'], '%a, %d %b %Y %H:%M:%S GMT'))
+ if 'Content-Length' in info :
+ self.url_content_legth = info['Content-Length']
+ except Exception, e :
+ raise SCons.Errors.StopError( '%s [%s]' % (e, self.value) )
+
+ def visited(self) :
+ ninfo = self.get_ninfo()
+
+ if self.url_etag :
+ ninfo.csig = self.url_etag
+ if self.url_last_modified :
+ ninfo.timestamp = self.url_last_modified
+ if self.url_content_length :
+ ninfo.size = self.url_content_length
+ SCons.Node.Node.visited(self);
+
+ def changed_since_last_build(self, target, prev_ni):
+ if prev_ni :
+ if self.url_etag :
+ if prev_ni.csig == self.url_etag :
+ # print 'Matched on ETag:'+prev_ni.csig
+ return False
+
+ if not self.url_last_modified :
+ # print 'Last modified date is not available'
+ return True
+ if not self.url_content_length :
+ # print 'Content length is not available'
+ return True
+ if prev_ni.timestamp != self.url_last_modified :
+ # print 'Modified since last build'
+ return True
+ if prev_ni.size != self.url_content_length :
+ # print 'Content length has changed'
+ return True
+
+ return False
+
+ # print 'Not previous built'
+ return True
+
+# Creates the output message
+# @param s original message
+# @param target target name
+# @param source source name
+# @param env environment object
+def __message( s, target, source, env ) :
+ print 'downloading [%s] from [%s] ...' % (target[0], source[0])
+
+# Creates the action ie. the download function.
+# This reads the data from the URL and writes it down to the file
+# @param target target file on the local drive
+# @param source URL for download
+# @@param env environment object
+def __action( target, source, env ) :
+ try :
+ source_name = str(source[0])
+ target_name = str(target[0])
+ stream = urllib2.urlopen(source_name)
+ file = open( target_name, 'wb' )
+ file.write(stream.read())
+ file.close()
+
+ # Change the access/modified time to match
+ # the date on the downloaded file, if available
+ ninfo = source[0].get_ninfo()
+ if hasattr(ninfo, 'timestamp') :
+ mtime = ninfo.timestamp
+ if mtime :
+ os.utime(target_name, (mtime, mtime))
+ except Exception, e :
+ raise SCons.Errors.StopError( '%s [%s]' % (e, source[0]) )
+
+
+# Defines the emitter of the builder
+# @param target target file on the local drive
+# @param source URL for download
+# @param env environment object
+def __emitter( target, source, env ) :
+ return target, source
+
+# generate function, that adds the builder to the environment,
+# @param env environment object
+def generate( env ) :
+ env['BUILDERS']['URLDownload'] = SCons.Builder.Builder( action = __action, emitter = __emitter, target_factory = SCons.Node.FS.File, source_factory = URLNode, single_source = True, PRINT_CMD_LINE_FUNC = __message )
+
+# existing function of the builder
+# @param env environment object
+# @return true
+def exists(env) :
+ return 1