]> SALOME platform Git repositories - tools/pvdeliv.git/commitdiff
Salome HOME
Extract archives only when necessary
authorCédric Aguerre <cedric.aguerre@edf.fr>
Fri, 25 Mar 2016 10:10:09 +0000 (11:10 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Fri, 25 Mar 2016 10:10:09 +0000 (11:10 +0100)
scripts/BuildSalomeMini.py

index eaf7641706e13727d0d75d9d17589be12199a3d3..dd017421289cfda31217733637db06ccc09fb6c7 100755 (executable)
@@ -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)
 #