import os,subprocess,sys,re,datetime,shutil,glob
import ConfigParser
+import tarfile
current_directory=os.path.dirname(os.path.abspath(__file__))
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):
#
pattern="cmake"
srcDir=extractSrc(topSrcDir,pattern)
+
installDir=compileOld(envAcc,srcDir,topBuildDir,topInstallDir,[],False)
accumulateEnv(installDir,pattern,envAcc)
#