From: Cédric Aguerre Date: Fri, 25 Mar 2016 10:10:09 +0000 (+0100) Subject: Extract archives only when necessary X-Git-Tag: kw11013~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b082d7233c6ef4fbac4bb21da9689fbc946b4fb;p=tools%2Fpvdeliv.git Extract archives only when necessary --- diff --git a/scripts/BuildSalomeMini.py b/scripts/BuildSalomeMini.py index eaf7641..dd01742 100755 --- a/scripts/BuildSalomeMini.py +++ b/scripts/BuildSalomeMini.py @@ -2,6 +2,7 @@ import os,subprocess,sys,re,datetime,shutil,glob import ConfigParser +import tarfile current_directory=os.path.dirname(os.path.abspath(__file__)) @@ -219,40 +220,29 @@ def extractSrcFromArchive(srcLoc,srcDir,pattern): zz=AutoChdir(srcDir) if os.path.exists(tmpDir): assert(False) - os.mkdir(tmpDir) srcDN=None ret=None myExt=os.path.splitext(srcLoc)[1] - if myExt in [".gz",".tgz",".bz2"]: - if myExt in [".gz",".tgz"]: - myCmd=["tar","xfz",srcLoc] - else: - myCmd=["tar","xfj",srcLoc] - print "Command: ", " ".join(myCmd) - p=subprocess.Popen(myCmd,cwd=tmpDir,stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p.communicate() - assert(p.returncode==0) - # - li=os.listdir(tmpDir) - assert(len(li)==1) - li=filter(lambda x: pattern.lower() in x.lower(),li) - assert(len(li)==1) - unzipDir=os.path.join(tmpDir,li[0]) - assert(os.path.isdir(unzipDir)) - srcDN=os.path.basename(li[0]) - ret=os.path.realpath(os.path.join(os.getcwd(),srcDN)) - if os.path.exists(ret): - print("\"%s\" already exists : keep it as this !"%ret) - shutil.rmtree(tmpDir) - else: - shutil.move(unzipDir,os.getcwd()) - os.rmdir(tmpDir) - pass - else: - assert(False) - #for elt in os.listdir(os.getcwd()): - # print datetime.date.fromtimestamp(os.stat(elt).st_ctime) - # pass + + try: + tar_file = tarfile.open(name=srcLoc, mode='r|*') + name0 = tar_file.getnames()[0] # raise IndexError if tar_file is empty + base0 = name0.split('/')[0] + ret = os.path.realpath(os.path.join(os.getcwd(), base0)) + if os.path.exists(ret): + print("\"%s\" already exists : keep it as this !"%ret) + tar_file.close() + return ret + os.mkdir(tmpDir) + tar_file.extractall(tmpDir) + tar_file.close() + except: + os.rmdir(tmpDir) + assert(False) + pass + unzipDir = os.path.join(tmpDir, base0) + shutil.move(unzipDir, os.getcwd()) + os.rmdir(tmpDir) return ret def extractSrcFromGit(gitLoc,srcDir,pattern): @@ -479,6 +469,7 @@ for d in [topSrcDir,topBuildDir,topInstallDir]: # pattern="cmake" srcDir=extractSrc(topSrcDir,pattern) + installDir=compileOld(envAcc,srcDir,topBuildDir,topInstallDir,[],False) accumulateEnv(installDir,pattern,envAcc) #