Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self._source_loader = SourceLoader()
self._tar = None
self._tar_dir = self.test_project_dir / "archives"
self._tar_gz = self.test_project_dir / "archives" / "sample.tar.gz"
self._tar_xz = self.test_project_dir / "archives" / "sample.tar.xz"
self._tar_temp = Path("/var/tmp/rpg_test/")
self._tar_extracted = self._tar_temp / "extracted"
self._download = self._tar_temp / "download.tar.gz"
if path.isdir(path_to_str(self._tar_temp)):
rmtree(path_to_str(self._tar_temp))
makedirs(path_to_str(self._tar_temp))
makedirs(path_to_str(self._tar_extracted))
def md5Tar(self, t):
mdsum = Command(
"tar --list -f " + path_to_str(t) + " 2>/dev/null | "
"awk -F/ '{ if($NF != \"\") print $NF }' | "
r'sed -e "s/.*\///gm" | sort | md5sum'
).execute()
self.assertNotEqual(self.FNF_MD5, mdsum)
return mdsum
def tearDown(self):
if self._tar:
remove(path_to_str(self._tar))
if path.isdir(path_to_str(self._tar_temp)):
rmtree(path_to_str(self._tar_temp))
def setUp(self):
self._source_loader = SourceLoader()
self._tar = None
self._tar_dir = self.test_project_dir / "archives"
self._tar_gz = self.test_project_dir / "archives" / "sample.tar.gz"
self._tar_xz = self.test_project_dir / "archives" / "sample.tar.xz"
self._tar_temp = Path("/var/tmp/rpg_test/")
self._tar_extracted = self._tar_temp / "extracted"
self._download = self._tar_temp / "download.tar.gz"
if path.isdir(path_to_str(self._tar_temp)):
rmtree(path_to_str(self._tar_temp))
makedirs(path_to_str(self._tar_temp))
makedirs(path_to_str(self._tar_extracted))
def md5Dir(self, d):
md5sum = Command(
"find " + path_to_str(d) +
r' -type f | sed -e "s/.*\///gm" | sort | md5sum'
).execute()
self.assertNotEqual(self.FNF_MD5, md5sum)
return md5sum
def create_archive(self):
""" Creates archive (archvie_path) from Source folder """
self.spec.Source = self.spec.Name + "-" + self.spec.Version + ".tar.gz"
_tar = Command("tar zcf " + path_to_str(self.archive_path) +
" -C " + path_to_str(self.extracted_dir) +
" . --transform='s/^\./" +
self.spec.Name + "-" + self.spec.Version + "/g'")
_tar.execute()
logging.debug(str(_tar))
def create_archive(self):
""" Creates archive (archvie_path) from Source folder """
self.spec.Source = self.spec.Name + "-" + self.spec.Version + ".tar.gz"
_tar = Command("tar zcf " + path_to_str(self.archive_path) +
" -C " + path_to_str(self.extracted_dir) +
" . --transform='s/^\./" +
self.spec.Name + "-" + self.spec.Version + "/g'")
_tar.execute()
logging.debug(str(_tar))
def _move_files(output, files):
if not output.exists() and not output.is_dir():
Command("mkdir " + path_to_str(output)).execute()
for _out in files:
try:
Command("mv " + path_to_str(_out) +
" " + path_to_str(output)).execute()
except:
pass
def load_sources(self, source_path, extraction_dir):
""" If source_path is a directory, path tree will be
copied to extraction_dir. If it is archive
May raise IOError """
logging.debug('load_sources({}, {}) called'
.format(str(source_path), str(extraction_dir)))
path = path_to_str(source_path)
esc_extr_dir = path_to_str(extraction_dir)
if isfile(path):
compression = self._get_compression_method(path)
if not compression:
raise IOError("Input source archive '{}' is incompatible!"
.format(path))
self._extract(path, esc_extr_dir, compression)
self._process_dir(esc_extr_dir)
elif isdir(str(source_path)):
self._copy_dir(str(source_path), str(extraction_dir))
else:
raise IOError("Input source archive/directory '{}' doesn't exists!"
.format(path))