Because SCons has dual license.
From https://github.com/flashpixx/Storage/tree/master/Scons
Change-Id: If45a359bb41efb3bdd93d33d20e6d26ec28847c5
Signed-off-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14951
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Hyuna Jo <hyuna0213.jo@samsung.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
# -*- coding: utf-8 -*-
+# -- Dual Licence ----------------------------------------------------------
+
############################################################################
# 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 #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
############################################################################
-# This builder originated from work by Philipp Kraus and flashpixx project
-# (see https://github.com/flashpixx). Based on the Unpack.py, it only
-# contains changes to allow a complete unpacking of the archive.
-# It is assumed that the target represents a file in the archive after it
-# is unpacked.
+# --------------------------------------------------------------------------
+
+############################################################################
+# BSD 3-Clause License #
+# #
+# This file is a SCons (http://www.scons.org/) builder #
+# Copyright (c) 2012-14, Philipp Kraus, <philipp.kraus@flashpixx.de> #
+# All rights reserved. #
+# #
+# Redistribution and use in source and binary forms, with or without #
+# modification, are permitted provided that the following conditions are #
+# met: #
+# #
+# 1. Redistributions of source code must retain the above copyright #
+# notice, this list of conditions and the following disclaimer. #
+# #
+# 2. Redistributions in binary form must reproduce the above copyright #
+# notice, this list of conditions and the following disclaimer in the #
+# documentation and/or other materials provided with the distribution. #
+# #
+# 3. Neither the name of the copyright holder nor the names of its #
+# contributors may be used to endorse or promote products derived from #
+# this software without specific prior written permission. #
+# #
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A #
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED #
+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
+############################################################################
+
+
# The Unpack Builder can be used for unpacking archives (eg Zip, TGZ, BZ, ... ).
-# The emitter of the Builder reads the archive data and creates a returning
-# file list the builder extract the archive. The environment variable
-# stores a dictionary "UNPACK" for set different extractions (subdict "EXTRACTOR"):
+# The emitter of the Builder reads the archive data and creates a returning file list
+# the builder extract the archive. The environment variable stores a dictionary "UNPACK"
+# for set different extractions (subdict "EXTRACTOR"):
# {
# PRIORITY => a value for setting the extractor order (lower numbers = extractor is used earlier)
# SUFFIX => defines a list with file suffixes, which should be handled with this extractor
import subprocess, os
-import SCons.Errors, SCons.Warnings, SCons.Util
+
+import SCons.Errors, SCons.Warnings
+import SCons.Util
+
# enables Scons warning for this builder
class UnpackWarning(SCons.Warnings.Warning) :
SCons.Warnings.enableWarningClass(UnpackWarning)
+
+
# extractor function for Tar output
# @param env environment object
# @param count number of returning lines
# @param env environment object
# @return extractor entry or None on non existing
def __getExtractor( source, env ) :
- # we check each unpacker and get the correct list command first, run the command and
+ # we check each unpacker and get the correc list command first, run the command and
# replace the target filelist with the list values, we sorte the extractors by their priority
for unpackername, extractor in sorted(env["UNPACK"]["EXTRACTOR"].iteritems(), key = lambda (k,v) : (v["PRIORITY"],k)):
+ # if the run command not set, we continue the extractor search, otherwise we check the extractor parameters
if not SCons.Util.is_String(extractor["RUN"]) :
raise SCons.Errors.StopError("list command of the unpack builder for [%s] archives is not a string" % (unpackername))
if not len(extractor["RUN"]) :
# action function for extracting of the data
# @param target target packed file
# @param source extracted files
-# @param env environment object
+# @env environment object
def __action( target, source, env ) :
- cwd = os.path.realpath('.')
extractor = __getExtractor([File(source)], env)
if not extractor :
- print '''******************************* Error *****************************************
-*
-* Doesn't support auto extracting [%s], please extract it to [%s].
-* *
-*******************************************************************************
-''' % (source, cwd)
- raise SCons.Errors.StopError( "can not find any extractor value for the source file [%s]" % (source) )
+ raise SCons.Errors.StopError( "can not find any extractor value for the source file [%s]" % (source[0]) )
- extractor_cmd = extractor["EXTRACTCMD"]
# if the extract command is empty, we create an error
- if len(extractor_cmd) == 0 :
- raise SCons.Errors.StopError( "the extractor command for the source file [%s] is empty" % (source) )
+ if len(extractor["EXTRACTCMD"]) == 0 :
+ raise SCons.Errors.StopError( "the extractor command for the source file [%s] is empty" % (source[0]) )
# build it now (we need the shell, because some programs need it)
handle = None
-
- cmd = env.subst(extractor_cmd, source=source, target=target)
+ cmd = env.subst(extractor["EXTRACTCMD"], source=source, target=target)
if env["UNPACK"]["VIWEXTRACTOUTPUT"] :
handle = subprocess.Popen( cmd, shell=True )
else :
devnull = open(os.devnull, "wb")
- handle = subprocess.Popen(cmd, shell=True, stdout=devnull, cwd = cwd)
+ handle = subprocess.Popen( cmd, shell=True, stdout=devnull )
if handle.wait() <> 0 :
- print '''******************************* Error *****************************************
-*
-* Fail to unpack [%s]. It should be due to it isn't downloaded completely.
-* Please download it manually or delete it and let the script auto download it*
-* again. *
-* *
-*******************************************************************************
-''' % (source)
- raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source) )
+ raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) )
+
# emitter function for getting the files
# within the archive
# @param target target packed file
# @param source extracted files
-# @param env environment object
+# @env environment object
def __emitter( target, source, env ) :
+ extractor = __getExtractor(source, env)
+ if not extractor :
+ raise SCons.Errors.StopError( "can not find any extractor value for the source file [%s]" % (source[0]) )
+
+ # we do a little trick, because in some cases we do not have got a physical
+ # file (eg we download a packed archive), so we don't get a list or knows
+ # the targets. On physical files we can do this with the LISTCMD, but on
+ # non-physical files we hope the user knows the target files, so we inject
+ # this knowledge into the return target.
+ if env.has_key("UNPACKLIST") :
+ if not SCons.Util.is_List(env["UNPACKLIST"]) and not SCons.Util.is_String(env["UNPACKLIST"]) :
+ raise SCons.Errors.StopError( "manual target list of [%s] must be a string or list" % (source[0]) )
+ if not env["UNPACKLIST"] :
+ raise SCons.Errors.StopError( "manual target list of [%s] need not be empty" % (source[0]) )
+ return env["UNPACKLIST"], source
+
+
+ # we check if the source file exists, because we would like to read the data
+ if not source[0].exists() :
+ raise SCons.Errors.StopError( "source file [%s] must be exist" % (source[0]) )
+
+ # create the list command and run it in a subprocess and pipes the output to a variable,
+ # we need the shell for reading data from the stdout
+ cmd = env.subst(extractor["LISTCMD"], source=source, target=target)
+ handle = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
+ target = handle.stdout.readlines()
+ handle.communicate()
+ if handle.returncode <> 0 :
+ raise SCons.Errors.StopError("error on running list command [%s] of the source file [%s]" % (cmd, source[0]) )
+
+ # if the returning output exists and the listseperator is a callable structure
+ # we run it for each line of the output and if the return of the callable is
+ # a string we push it back to the target list
+ try :
+ if callable(extractor["LISTEXTRACTOR"]) :
+ target = filter( lambda s : SCons.Util.is_String(s), [ extractor["LISTEXTRACTOR"]( env, len(target), no, i) for no, i in enumerate(target) ] )
+ except Exception, e :
+ raise SCons.Errors.StopError( "%s" % (e) )
+
+ # the line removes duplicated names - we need this line, otherwise an cyclic dependency error will occured,
+ # because the list process can create redundant data (an archive file can not store redundant content in a filepath)
+ target = [i.strip() for i in list(set(target))]
+ if not target :
+ SCons.Warnings.warn(UnpackWarning, "emitter file list on target [%s] is empty, please check your extractor list function [%s]" % (source[0], cmd) )
+
+ # we append the extractdir to each target if is not absolut
+ if env["UNPACK"]["EXTRACTDIR"] <> "." :
+ target = [i if os.path.isabs(i) else os.path.join(env["UNPACK"]["EXTRACTDIR"], i) for i in target]
+
return target, source
def __unpack_all(env, target, source) :
- if os.path.exists(target):
- return
+ if os.path.exists(target):
+ return
- print "Unpacking %s ..." % source
- __action(target, source, env)
+ print "Unpacking %s ..." % source
+ __action(target, source, env)
# generate function, that adds the builder to the environment
-# @param env environment object
+# @env environment object
def generate( env ) :
# setup environment variable
toolset = {
# -*- coding: utf-8 -*-
+# -- Dual Licence ----------------------------------------------------------
+
############################################################################
# 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 #
# 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.
+# --------------------------------------------------------------------------
+
+############################################################################
+# BSD 3-Clause License #
+# #
+# This file is a SCons (http://www.scons.org/) builder #
+# Copyright (c) 2012-14, Philipp Kraus, <philipp.kraus@flashpixx.de> #
+# All rights reserved. #
+# #
+# Redistribution and use in source and binary forms, with or without #
+# modification, are permitted provided that the following conditions are #
+# met: #
+# #
+# 1. Redistributions of source code must retain the above copyright #
+# notice, this list of conditions and the following disclaimer. #
+# #
+# 2. Redistributions in binary form must reproduce the above copyright #
+# notice, this list of conditions and the following disclaimer in the #
+# documentation and/or other materials provided with the distribution. #
+# #
+# 3. Neither the name of the copyright holder nor the names of its #
+# contributors may be used to endorse or promote products derived from #
+# this software without specific prior written permission. #
+# #
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A #
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED #
+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
+############################################################################
+
+
+
+# the URLDownload-Builder can be download any data from an URL into a target file
+# and can replace the target file name with the URL filename (the setting variable
+# within the environment object is a boolean type with the name "URLDOWNLOAD_USEURLFILENAM",
+# default setting replaces the target name with the URL filename)
-# 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
-#
+
+# define an own node, for checking the data behind the URL,
+# we must download only than, if the data is changed, the
+# node derivates from the Python.Value node
class URLNode(SCons.Node.Python.Value) :
- def make_ready(self) :
+
+ # overload the get_csig (copy the source from the
+ # Python.Value node and append the data of the URL header
+ def get_csig(self, calc=None):
+ try:
+ return self.ninfo.csig
+ except AttributeError:
+ pass
+
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']
+ response = urllib2.urlopen( str(self.value) ).info()
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
+ raise SCons.Errors.StopError( "%s [%s]" % (e, self.value) )
+
+ contents = ""
+ if "Last-Modified" in response :
+ contents = contents + response["Last-Modified"]
+ if "Content-Length" in response :
+ contents = contents + response["Content-Length"]
+ if not contents :
+ contents = self.get_contents()
+ self.get_ninfo().csig = contents
+ return contents
+
+
+
+# creates the downloading 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])
+def __message( s, target, source, env ) :
+ print "downloading [%s] to [%s] ..." % (source[0], target[0])
-# Creates the action ie. the download function.
-# This reads the data from the URL and writes it down to the file
+
+# the download function, which 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' )
+ stream = urllib2.urlopen( str(source[0]) )
+ file = open( str(target[0]), "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))
+ stream.close()
except Exception, e :
- raise SCons.Errors.StopError( '%s [%s]' % (e, source[0]) )
+ raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) )
-# Defines the emitter of the builder
+# 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
+ # we need a temporary file, because the dependency graph
+ # of Scons need a physical existing file - so we prepare it
+ target[0].prepare()
+
+ if not env.get("URLDOWNLOAD_USEURLFILENAME", False) :
+ return target, source
+
+ try :
+ url = urlparse.urlparse( urllib2.urlopen( str(source[0]) ).geturl() )
+ except Exception, e :
+ raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) )
+
+ return url.path.split("/")[-1], source
+
+
+
# generate function, that adds the builder to the environment,
+# the value "DOWNLOAD_USEFILENAME" replaces the target name with
+# the filename of the URL
# @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 )
+ 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 )
+ env.Replace(URLDOWNLOAD_USEURLFILENAME = True )
+
# existing function of the builder
# @param env environment object
# @return true
def exists(env) :
- return 1
+ return 1
\ No newline at end of file
# -*- coding: utf-8 -*-
+# -- Dual Licence ----------------------------------------------------------
+
############################################################################
# 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 #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
############################################################################
-# This builder originated from work by Philipp Kraus and flashpixx project
-# (see https://github.com/flashpixx). Based on the Unpack.py, it only
-# contains changes to allow a complete unpacking of the archive.
-# It is assumed that the target represents a file in the archive after it
-# is unpacked.
+# --------------------------------------------------------------------------
+
+############################################################################
+# BSD 3-Clause License #
+# #
+# This file is a SCons (http://www.scons.org/) builder #
+# Copyright (c) 2012-14, Philipp Kraus, <philipp.kraus@flashpixx.de> #
+# All rights reserved. #
+# #
+# Redistribution and use in source and binary forms, with or without #
+# modification, are permitted provided that the following conditions are #
+# met: #
+# #
+# 1. Redistributions of source code must retain the above copyright #
+# notice, this list of conditions and the following disclaimer. #
+# #
+# 2. Redistributions in binary form must reproduce the above copyright #
+# notice, this list of conditions and the following disclaimer in the #
+# documentation and/or other materials provided with the distribution. #
+# #
+# 3. Neither the name of the copyright holder nor the names of its #
+# contributors may be used to endorse or promote products derived from #
+# this software without specific prior written permission. #
+# #
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A #
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED #
+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
+############################################################################
+
+
# The Unpack Builder can be used for unpacking archives (eg Zip, TGZ, BZ, ... ).
-# The emitter of the Builder reads the archive data and creates a returning
-# file list the builder extract the archive. The environment variable
-# stores a dictionary "UNPACK" for set different extractions (subdict "EXTRACTOR"):
+# The emitter of the Builder reads the archive data and creates a returning file list
+# the builder extract the archive. The environment variable stores a dictionary "UNPACK"
+# for set different extractions (subdict "EXTRACTOR"):
# {
# PRIORITY => a value for setting the extractor order (lower numbers = extractor is used earlier)
# SUFFIX => defines a list with file suffixes, which should be handled with this extractor
import subprocess, os
-import SCons.Errors, SCons.Warnings, SCons.Util
+
+import SCons.Errors, SCons.Warnings
+import SCons.Util
+
# enables Scons warning for this builder
class UnpackWarning(SCons.Warnings.Warning) :
SCons.Warnings.enableWarningClass(UnpackWarning)
+
+
# extractor function for Tar output
# @param env environment object
# @param count number of returning lines
# @param env environment object
# @return extractor entry or None on non existing
def __getExtractor( source, env ) :
- # we check each unpacker and get the correct list command first, run the command and
+ # we check each unpacker and get the correc list command first, run the command and
# replace the target filelist with the list values, we sorte the extractors by their priority
for unpackername, extractor in sorted(env["UNPACK"]["EXTRACTOR"].iteritems(), key = lambda (k,v) : (v["PRIORITY"],k)):
+ # if the run command not set, we continue the extractor search, otherwise we check the extractor parameters
if not SCons.Util.is_String(extractor["RUN"]) :
raise SCons.Errors.StopError("list command of the unpack builder for [%s] archives is not a string" % (unpackername))
if not len(extractor["RUN"]) :
# action function for extracting of the data
# @param target target packed file
# @param source extracted files
-# @param env environment object
+# @env environment object
def __action( target, source, env ) :
extractor = __getExtractor(source, env)
if not extractor :
raise SCons.Errors.StopError( "can not find any extractor value for the source file [%s]" % (source[0]) )
- extractor_cmd = extractor["EXTRACTCMD"]
# if the extract command is empty, we create an error
- if len(extractor_cmd) == 0 :
+ if len(extractor["EXTRACTCMD"]) == 0 :
raise SCons.Errors.StopError( "the extractor command for the source file [%s] is empty" % (source[0]) )
# build it now (we need the shell, because some programs need it)
source_path = os.path.realpath(source[0].path)
target_path = os.path.realpath(target[0].path)
- cmd = env.subst(extractor_cmd, source=source_path, target=target)
+ cmd = env.subst(extractor["EXTRACTCMD"], source=source_path, target=target)
cwd = os.path.dirname(source_path)
if env["UNPACK"]["VIWEXTRACTOUTPUT"] :
handle = subprocess.Popen( cmd, shell=True, stdout=devnull, cwd=cwd)
if handle.wait() <> 0 :
- raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) )
+ raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) )
fhandle = open(target_path, 'a')
try:
# within the archive
# @param target target packed file
# @param source extracted files
-# @param env environment object
+# @env environment object
def __emitter( target, source, env ) :
return target, source
+
+
# generate function, that adds the builder to the environment
-# @param env environment object
+# @env environment object
def generate( env ) :
# setup environment variable
toolset = {
# read tools for Windows system
if env["PLATFORM"] <> "darwin" and "win" in env["PLATFORM"] :
- if env.WhereIs("7z") :
+ if env.WhereIs("7z"):
toolset["EXTRACTOR"]["TARGZ"]["RUN"] = "7z"
toolset["EXTRACTOR"]["TARGZ"]["LISTEXTRACTOR"] = __fileextractor_win_7zip
toolset["EXTRACTOR"]["TARGZ"]["LISTFLAGS"] = "x"