def _doInstall(self): ball = self.getBall() if cautils.is_tarfile(ball): if not self.__cygwinPlatform: self._doInstallExternal(ball) tf = cautils.open_tarfile(ball, self.__dosXz) if self.__cygwinPlatform: tf.extractall(self.__absRoot) # Force slash to the end of each directories members = tf.getmembers() tf.close() lst = [] for m in members: if m.isdir() and not m.name.endswith("/"): lst.append(m.name + "/") else: lst.append(m.name) else: print("{0}: bad tarball {1}. Install failed.".format( self.__appName, ball), file=sys.stderr) return self._writeFileList(lst) status = 1 if not self.__pkgName in self._integrityControl(): status = 0 self.__installed[status][self.__pkgName] = os.path.basename(ball) self._writeInstalled()
def _doInstall(self): ball = self.getBall(); if cautils.is_tarfile(ball): if not self.__cygwinPlatform: self._doInstallExternal(ball); tf = cautils.open_tarfile(ball, self.__dosXz); if self.__cygwinPlatform: tf.extractall(self.__absRoot); # Force slash to the end of each directories members = tf.getmembers(); tf.close(); lst = []; for m in members: if m.isdir() and not m.name.endswith("/"): lst.append(m.name + "/"); else: lst.append(m.name); else: print("{0}: bad tarball {1}. Install failed.".format( self.__appName, ball ), file=sys.stderr); return; self._writeFileList(lst); status = 1; if not self.__pkgName in self._integrityControl(): status = 0; self.__installed[status][self.__pkgName] = os.path.basename(ball); self._writeInstalled();
def _doInstallExternal(self, ball): # Currently we use a temporary directory and extractall() then copy: # this is very slow. The Python documentation warns more sophisticated # approaches have pitfalls without specifying what they are. tf = cautils.open_tarfile(ball, self.__dosXz); members = tf.getmembers(); tempdir = tempfile.mkdtemp(); try: tf.extractall(tempdir); for m in members: if m.isdir(): path = self.__pm.mapPath("/" + m.name); if not os.path.exists(path): os.makedirs(path, m.mode); for m in members: if m.isdir(): path = self.__pm.mapPath("/" + m.name); if not os.path.exists(path): os.makedirs(path, m.mode); else: path = self.__pm.mapPath("/" + m.name); dirname = os.path.dirname(path); if not os.path.exists(dirname): os.makedirs(dirname); if os.path.exists(path): os.chmod(path, 0o777); os.remove(path); # Windows extract() is robust but can't form Cygwin links # (It produces copies instead: bulky and bugbait.) # Convert to links if possible -- depends on coreutils being installed if m.issym() and self.__lnExists: link_target = m.linkname; Process([ self.__dosLn, "-s", link_target, path ]).run(True); elif m.islnk() and self.__lnExists: # Hard link -- expect these to be very rare link_target = m.linkname; mapped_target = self.__pm.mapPath("/" + m.linkname); # Must ensure target exists before forming hard link if not os.path.exists(mapped_target): shutil.move( os.path.join(tempdir, link_target), mapped_target ); Process([ self.__dosLn, mapped_target, path ]).run(True); else: shutil.move(os.path.join(tempdir, m.name), path); finally: tf.close(); cautils.rmtree(tempdir);
def _doInstallExternal(self, ball): # Currently we use a temporary directory and extractall() then copy: # this is very slow. The Python documentation warns more sophisticated # approaches have pitfalls without specifying what they are. tf = cautils.open_tarfile(ball, self.__dosXz) members = tf.getmembers() tempdir = tempfile.mkdtemp() try: tf.extractall(tempdir) for m in members: if m.isdir(): path = self.__pm.mapPath("/" + m.name) if not os.path.exists(path): os.makedirs(path, m.mode) for m in members: if m.isdir(): path = self.__pm.mapPath("/" + m.name) if not os.path.exists(path): os.makedirs(path, m.mode) else: path = self.__pm.mapPath("/" + m.name) dirname = os.path.dirname(path) if not os.path.exists(dirname): os.makedirs(dirname) if os.path.exists(path): os.chmod(path, 0o777) os.remove(path) # Windows extract() is robust but can't form Cygwin links # (It produces copies instead: bulky and bugbait.) # Convert to links if possible -- depends on coreutils being installed if m.issym() and self.__lnExists: link_target = m.linkname Process([self.__dosLn, "-s", link_target, path]).run(True) elif m.islnk() and self.__lnExists: # Hard link -- expect these to be very rare link_target = m.linkname mapped_target = self.__pm.mapPath("/" + m.linkname) # Must ensure target exists before forming hard link if not os.path.exists(mapped_target): shutil.move(os.path.join(tempdir, link_target), mapped_target) Process([self.__dosLn, mapped_target, path]).run(True) else: shutil.move(os.path.join(tempdir, m.name), path) finally: tf.close() cautils.rmtree(tempdir)
def _doUnpack(self): ball = self.getBall() basename = os.path.basename(ball) self.__pkgName = re.sub(r"(-src)*\.tar\.(bz2|gz)", '', basename) if os.path.exists(self.__pkgName): self._printErr("{0} already exists. Not overwriting.".format( self.__pkgName)) return 1 os.mkdir(self.__pkgName) if cautils.is_tarfile(ball): tf = cautils.open_tarfile(ball, self.__dosXz) tf.extractall(self.__pkgName) tf.close() else: raise InvalidFileException("Bad source tarball {0}, \n" "SOURCE UNPACK FAILED".format(ball)) if not os.path.exists(self.__pkgName): raise IOError(self.__pkgName) print(self.__pkgName)
def _successOpenTarfile(self, pkgname, xzPath="xz"): ball = os.path.join( self._dir_mirror, self._var_setupIni.__dict__[pkgname].install.curr.url, ); filesOnBallDir = os.listdir(os.path.dirname(ball)); tf = utils.open_tarfile(ball, xzPath); members = tf.getmembers(); tf.close(); self.assertEqual(filesOnBallDir, os.listdir(os.path.dirname(ball))); filelist = []; for member in members : path = member.name; if member.isdir() : path = path.rstrip("/")+"/"; filelist.append(path); self.assertEqual(sorted(filelist), sorted(self._var_setupIni.__dict__[pkgname].filelist));
def _doUnpack(self): ball = self.getBall(); basename = os.path.basename(ball); self.__pkgName = re.sub(r"(-src)*\.tar\.(bz2|gz)", '', basename); if os.path.exists(self.__pkgName): self._printErr("{0} already exists. Not overwriting.".format( self.__pkgName )); return 1; os.mkdir(self.__pkgName); if cautils.is_tarfile(ball): tf = cautils.open_tarfile(ball, self.__dosXz); tf.extractall(self.__pkgName); tf.close(); else: raise InvalidFileException( "Bad source tarball {0}, \n" "SOURCE UNPACK FAILED".format(ball) ); if not os.path.exists(self.__pkgName): raise IOError(self.__pkgName); print(self.__pkgName);