archive'leri nasıl unpack() edeceğimizi bir örnek ile gösterdik...
This commit is contained in:
+16
-14
@@ -1,23 +1,25 @@
|
|||||||
# utilities to extract and build archives of zip, tar, targz, tarbz2
|
# utilities to extract and build archives of zip, tar, targz, tarbz2
|
||||||
# maintainer: baris and meren
|
# maintainer: baris and meren
|
||||||
|
|
||||||
|
import tarfile
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
class ArchiveTarGZ:
|
class ArchiveTarFile:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename, type):
|
||||||
print "testing...%s" %filename
|
self.type = type
|
||||||
|
self.filename = filename
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
print "unpack is cool"
|
if self.type == "targz":
|
||||||
|
tar = tarfile.open(config.archives_dir()+"/"+self.filename, 'r:gz')
|
||||||
class ArchiveTarBZ2:
|
for tarinfo in tar:
|
||||||
pass
|
tar.extract(tarinfo)
|
||||||
|
tar.close()
|
||||||
|
|
||||||
class ArchiveZip:
|
class ArchiveZip:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ArchiveTar:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Archive:
|
class Archive:
|
||||||
"""Unpack magic for Archive files..."""
|
"""Unpack magic for Archive files..."""
|
||||||
@@ -27,13 +29,13 @@ class Archive:
|
|||||||
targz, tarbz2, zip, tar"""
|
targz, tarbz2, zip, tar"""
|
||||||
|
|
||||||
actions = {
|
actions = {
|
||||||
'targz': ArchiveTarGZ,
|
'targz': ArchiveTarFile,
|
||||||
'tarbz2': ArchiveTarBZ2,
|
'tarbz2': ArchiveTarFile,
|
||||||
'zip': ArchiveZip,
|
'tar': ArchiveTarFile,
|
||||||
'tar': ArchiveTar
|
'zip': ArchiveZip
|
||||||
}
|
}
|
||||||
|
|
||||||
self.archive = actions.get(type)(filename)
|
self.archive = actions.get(type)(filename, type)
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
self.archive.unpack()
|
self.archive.unpack()
|
||||||
|
|||||||
Reference in New Issue
Block a user