archive: Guess archive type from file extension
This makes "type" attribute of "Archive" tag optional.
This commit is contained in:
@@ -580,6 +580,9 @@ class Archive:
|
|||||||
targz, tarbz2, tarlzma, tarxz, tarZ, tar, zip, gzip, bzip2,
|
targz, tarbz2, tarlzma, tarxz, tarZ, tar, zip, gzip, bzip2,
|
||||||
lzma, xz, binary"""
|
lzma, xz, binary"""
|
||||||
|
|
||||||
|
if not arch_type:
|
||||||
|
arch_type = self._guess_archive_type(file_path)
|
||||||
|
|
||||||
handlers = {'targz': ArchiveTar,
|
handlers = {'targz': ArchiveTar,
|
||||||
'tarbz2': ArchiveTar,
|
'tarbz2': ArchiveTar,
|
||||||
'tarlzma': ArchiveTar,
|
'tarlzma': ArchiveTar,
|
||||||
@@ -601,6 +604,26 @@ class Archive:
|
|||||||
|
|
||||||
self.archive = handler(file_path, arch_type)
|
self.archive = handler(file_path, arch_type)
|
||||||
|
|
||||||
|
def _guess_archive_type(self, file_path):
|
||||||
|
types = (("targz", (".tar.gz", ".tgz")),
|
||||||
|
("tarbz2", (".tar.bz2", ".tar.bz", ".tbz2", ".tbz")),
|
||||||
|
("tarlzma", (".tar.lzma", ".tlz")),
|
||||||
|
("tarxz", (".tar.xz", ".txz")),
|
||||||
|
("tarZ", (".tar.Z",)),
|
||||||
|
("tar", (".tar",)),
|
||||||
|
("zip", (".zip", ".ZIP")),
|
||||||
|
("gz", (".gz",)),
|
||||||
|
("bz2", (".bz2", ".bz")),
|
||||||
|
("lzma", (".lzma",)),
|
||||||
|
("xz", (".xz",)),
|
||||||
|
("binary", (".bin", ".run", ".sh")))
|
||||||
|
|
||||||
|
for _type, extensions in types:
|
||||||
|
if file_path.endswith(extensions):
|
||||||
|
return _type
|
||||||
|
|
||||||
|
return "binary"
|
||||||
|
|
||||||
def unpack(self, target_dir, clean_dir=False):
|
def unpack(self, target_dir, clean_dir=False):
|
||||||
self.archive.unpack(target_dir, clean_dir)
|
self.archive.unpack(target_dir, clean_dir)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -153,7 +153,7 @@ class ComarProvide:
|
|||||||
class Archive:
|
class Archive:
|
||||||
|
|
||||||
s_uri = [ autoxml.String, autoxml.mandatory ]
|
s_uri = [ autoxml.String, autoxml.mandatory ]
|
||||||
a_type = [ autoxml.String, autoxml.mandatory ]
|
a_type = [ autoxml.String, autoxml.optional ]
|
||||||
a_sha1sum =[ autoxml.String, autoxml.mandatory ]
|
a_sha1sum =[ autoxml.String, autoxml.mandatory ]
|
||||||
a_target =[ autoxml.String, autoxml.optional ]
|
a_target =[ autoxml.String, autoxml.optional ]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user