client/tools/rhnpush/archive.py | 55 ++++++++++++++++++++----------------
client/tools/rhnpush/solaris2mpm.py | 21 ++++++++-----
2 files changed, 44 insertions(+), 32 deletions(-)
New commits:
commit b21f24b4001db14453f5e49e1b0975ccc374b7a1
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Nov 22 15:43:59 2011 +0100
replaced external zip with zipfile module
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index d716926..694009c 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -202,9 +202,11 @@ class ArchiveParser(object):
os.chdir(parent_dir)
zip_file = os.path.join(self._parent_dir, "%s.zip" % zip_dir)
-
- cmd = "zip -q -r %s %s" % (zip_file, zip_dir)
- stat = _my_popen(cmd)
+ fd = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED)
+ for base, dirs, files in os.walk(zip_dir):
+ fd.write(base)
+ for f in files:
+ fd.write(os.path.join(base, f))
os.chdir(cwd)
commit e88fe4d7ef91729a84a652e1b03481e99c3d1df9
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Nov 22 14:36:48 2011 +0100
replaced external tar with tarfile module
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index c3d49f7..d716926 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -21,6 +21,7 @@ import shutil
import tempfile
import select
import zipfile
+import tarfile
# exceptions -------------------------------------------------------------
@@ -249,20 +250,23 @@ class ZipParser(ArchiveParser):
# parser for tar archives ------------------------------------------------
class TarParser(ArchiveParser):
+ def __init__(self, archive, tempdir="/tmp/"):
+ self.tar_file = tarfile.open(archive, 'r')
+ ArchiveParser.__init__(self, archive, tempdir)
def _get_archive_dir(self):
- list_cmd = "tar -tf %s" % (self._archive,)
- return os.popen(list_cmd).readlines()[0][:-2]
-
- def _explode_cmd(self):
- """Return the appropriate command for exploding a tar
archive"""
-
- if not _has_executable("tar"):
- raise ArchiveException("cannot open %s, 'tar' not found" %
self._archive)
+ return self.tar_file.getnames()[0]
+ def _explode(self, archive):
+ """Explode tar archive"""
self._archive_dir = os.path.join(self._temp_dir, self._get_archive_dir())
- return "cd %s; tar xf %s" % (self._temp_dir, self._archive)
+ try:
+ self.tar_file.extractall(path=self._temp_dir)
+ except Exception, e:
+ raise InvalidArchiveError("Archive did not expand to %s: %s" %
+ (self._archive_dir, str(e)))
+ return
# parser for cpio archives -----------------------------------------------
commit fee88932ae0990f1ca91da160eb6069a27def06c
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Nov 22 14:07:44 2011 +0100
don't call os.path.join() over and over
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 53ab6db..97086ab 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -369,11 +369,12 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
header.update(dct)
# a patch can patch multiple packages
- subdir = ''
+ patch_path = prefix
+ patch_path_with_subdir = os.path.join('patches/', patch_path)
# recent format has files in patches subdir
- if os.path.isdir(os.path.join(archive_parser._archive_dir, 'patches/',
prefix)):
- subdir = 'patches/'
- pkgs, x = archive_parser.list(os.path.join(subdir, prefix))
+ if os.path.isdir(os.path.join(archive_parser._archive_dir, patch_path_with_subdir)):
+ patch_path = patch_path_with_subdir
+ pkgs, x = archive_parser.list(patch_path)
for pkg in pkgs:
pkginfo_file = os.path.join(prefix, pkg, 'pkginfo')
@@ -407,7 +408,7 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
header['package_size'] = os.path.getsize(archive)
package.payload_stream = open(archive)
else:
- zip_file = archive_parser.zip(os.path.join(subdir,prefix))
+ zip_file = archive_parser.zip(patch_path)
_temp_files.append(zip_file)
header['package_name'] = os.path.basename(zip_file)
commit 5543c3e8e5ef32baab50165094a27cd9f4f81c0c
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Nov 10 14:20:15 2011 +0100
don't read 2GB file into memory at once
fixing
Error creating mpm for 10_Recommended.zip: MemoryError()
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 243fb3a..53ab6db 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -664,7 +664,12 @@ def md5sum_for_stream(data_stream):
format"""
md5obj = hashlib.new('md5')
- md5obj.update(data_stream.read())
+ while True:
+ buf = data_stream.read(1024000)
+ if buf:
+ md5obj.update(buf)
+ else:
+ break
data_stream.seek(0)
return md5obj.hexdigest()
commit 17bbe7bb16e6de39864f23f879e13e321687535a
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Nov 22 14:00:34 2011 +0100
don't hide original error message
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index 1818c48..c3d49f7 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -241,8 +241,9 @@ class ZipParser(ArchiveParser):
try:
self.zip_file.extractall(self._temp_dir)
- except:
- raise InvalidArchiveError("Archive did not expand to %s" %
self._archive_dir)
+ except Exception, e:
+ raise InvalidArchiveError("Archive did not expand to %s: %s" %
+ (self._archive_dir, str(e)))
return
# parser for tar archives ------------------------------------------------
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 1cc048c..243fb3a 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -235,8 +235,7 @@ def _run(archives=sys.argv[1:]):
raise MPMInputError("'%s' does not appear to contain Solaris
content")
except Exception, e:
- print "Error creating mpm for %s:" % archive
- # print str(e)
+ print "Error creating mpm for %s: %s" % (archive, repr(e))
# cleanup as we go
if options.CLEANUP:
commit 52d29ee4980270fb62f9ffab40e94dc10f4b5e96
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Nov 10 10:18:50 2011 +0100
replaced external unzip with zipfile module
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index 8c9ea26..1818c48 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -20,6 +20,7 @@ import subprocess
import shutil
import tempfile
import select
+import zipfile
# exceptions -------------------------------------------------------------
@@ -227,23 +228,22 @@ class ArchiveParser(object):
# parser for zip archives ------------------------------------------------
class ZipParser(ArchiveParser):
+ def __init__(self, archive, tempdir="/tmp/"):
+ self.zip_file = zipfile.ZipFile(archive, 'r')
+ ArchiveParser.__init__(self, archive, tempdir)
def _get_archive_dir(self):
- list_cmd = "unzip -l %s" % (self._archive,)
- file = os.popen(list_cmd).readlines()[3].split()[3][:-1]
- # file is usually top most dir... but not always
- # take first directory from relative path
- return file.split('/')[0]
-
- def _explode_cmd(self):
- """Return the appropriate command for exploding a zip
archive"""
-
- if not _has_executable("unzip"):
- raise ArchiveException("cannot open %s, 'unzip' not found"
% self._archive)
+ return self.zip_file.namelist()[0]
+ def _explode(self, archive):
+ """Explode zip archive"""
self._archive_dir = os.path.join(self._temp_dir, self._get_archive_dir())
- return "unzip -q -n %s -d %s" % (self._archive, self._temp_dir)
+ try:
+ self.zip_file.extractall(self._temp_dir)
+ except:
+ raise InvalidArchiveError("Archive did not expand to %s" %
self._archive_dir)
+ return
# parser for tar archives ------------------------------------------------