def extract_tarball_to_dir(tarball, dir):
 if os.path.exists(dir):
  if os.path.isdir(dir):
   shutil.rmtree(dir)
  else:
   os.remove(dir)
 pwd = os.getcwd()
 os.chdir(os.path.dirname(os.path.abspath(dir)))
 newdir = extract_tarball(tarball)
 os.rename(newdir, dir)
 os.chdir(pwd)

def extract_tarball_to_dir ( tarball , dir ) : if os . path . exists ( dir ) : if os . path . isdir ( dir ) : shutil . rmtree ( dir ) else : os . remove ( dir ) pwd = os . getcwd ( ) os . chdir ( os . path . dirname ( os . path . abspath ( dir ) ) ) newdir = extract_tarball ( tarball ) os . rename ( newdir , dir ) os . chdir ( pwd )
extract a tarball to a specified directory name instead of whatever the top level of a tarball is - useful for versioned directory names .