client/tools/rhnpush/archive.py | 54 +++++++++++++++---------------------
client/tools/rhnpush/solaris2mpm.py | 50 ++++++++++-----------------------
2 files changed, 39 insertions(+), 65 deletions(-)
New commits:
commit d66c784bca6da929568ec058fcbf5b0ac1064242
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu May 6 16:50:50 2010 +0200
559092 - do not blow up on new sun patch cluster format
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index ca50f57..3238cb6 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -204,7 +204,7 @@ class ArchiveParser(object):
zip_file = os.path.join(self._parent_dir, "%s.zip" % zip_dir)
- cmd = "zip -q -r %s %s" % (zip_file, prefix)
+ cmd = "zip -q -r %s %s" % (zip_file, zip_dir)
stat = _my_popen(cmd)
os.chdir(cwd)
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 119b13f..b325a12 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -210,6 +210,8 @@ def _run(archives=sys.argv[1:]):
write_mpm(set_mpm)
# create the individual patch mpms
patches, x = archive_parser.list()
+ if patches == ['patches']:
+ patches, x = archive_parser.list('patches/')
for dir in patches:
patch_mpm = create_patch_mpm(archive_parser, prefix=dir)
write_mpm(patch_mpm)
@@ -346,7 +348,7 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
package = rhn_mpm.MPM_Package()
# basics
- p_name = prefix or os.path.basename(archive_parser._archive_dir)
+ p_name = os.path.basename(prefix or archive_parser._archive_dir)
p_array = p_name.split("-")
header['name'] = "patch-solaris-" + p_array[0]
header['version'] = p_array[1]
@@ -369,7 +371,11 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
header.update(dct)
# a patch can patch multiple packages
- pkgs, x = archive_parser.list(prefix)
+ subdir = ''
+ # 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))
for pkg in pkgs:
pkginfo_file = os.path.join(prefix, pkg, 'pkginfo')
@@ -403,7 +409,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(prefix)
+ zip_file = archive_parser.zip(os.path.join(subdir,prefix))
_temp_files.append(zip_file)
header['package_name'] = os.path.basename(zip_file)
commit e643c0d5df922f5b9b7edd8db647cad970c970dd
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Tue May 4 13:56:39 2010 +0200
516898 - workaround for patches which do not have packed most top directory
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index a5491fe..ca50f57 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -233,7 +233,10 @@ class ZipParser(ArchiveParser):
def _get_archive_dir(self):
list_cmd = "unzip -l %s" % (self._archive,)
- return os.popen(list_cmd).readlines()[3].split()[3][:-1]
+ 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"""
commit 17763722f18c75c33414d8d892171faaaa86c25b
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon May 3 17:06:04 2010 +0200
code cleanup
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 87e18eb..119b13f 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -43,8 +43,6 @@ from spacewalk.common import rhn_mpm
from archive import get_archive_parser
-if __debug__: from pprint import pprint
-
__revision__ = "0.101"
__copyright__ = "Copyright (c) 2005, Red Hat Inc."
@@ -212,7 +210,6 @@ def _run(archives=sys.argv[1:]):
write_mpm(set_mpm)
# create the individual patch mpms
patches, x = archive_parser.list()
- if __debug__: patches.sort()
for dir in patches:
patch_mpm = create_patch_mpm(archive_parser, prefix=dir)
write_mpm(patch_mpm)
@@ -227,7 +224,6 @@ def _run(archives=sys.argv[1:]):
# package
elif _is_package_archive(archive_parser):
pkgs, x = archive_parser.list()
- if __debug__: pkgs.sort()
for dir in pkgs:
pkg_mpm = create_pkg_mpm(archive_parser, prefix=dir)
write_mpm(pkg_mpm)
@@ -240,7 +236,6 @@ def _run(archives=sys.argv[1:]):
except Exception, e:
print "Error creating mpm for %s:" % archive
- if __debug__: traceback.print_exc()
# print str(e)
# cleanup as we go
@@ -279,7 +274,6 @@ def _is_package_archive(archive_parser):
def create_patch_set_mpm(archive_parser, archive):
"""Create an mpm package from a parser holding a patch set
archive"""
-# if __debug__: print "DEBUG: creating patch set mpm for %s" % archive
# header
header = copy.deepcopy(_solaris_header_fields)
@@ -340,7 +334,6 @@ def create_patch_set_mpm(archive_parser, archive):
def create_patch_mpm(archive_parser, prefix="", archive=""):
"""Create an mpm package from a parser holding a patch
archive"""
-# if __debug__: print "DEBUG: creating patch mpm for %s" % (prefix or
archive)
# have to have one or the other
assert prefix or archive
@@ -377,7 +370,6 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
# a patch can patch multiple packages
pkgs, x = archive_parser.list(prefix)
- if __debug__: pkgs.sort()
for pkg in pkgs:
pkginfo_file = os.path.join(prefix, pkg, 'pkginfo')
@@ -407,7 +399,6 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
# payload
if archive:
-# if __debug__: print "DEBUG: payload file: %s" % archive
header['package_name'] = os.path.basename(archive)
header['package_size'] = os.path.getsize(archive)
package.payload_stream = open(archive)
@@ -415,7 +406,6 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
zip_file = archive_parser.zip(prefix)
_temp_files.append(zip_file)
-# if __debug__: print "DEBUG: payload file: %s" % zip_file
header['package_name'] = os.path.basename(zip_file)
header['package_size'] = os.path.getsize(zip_file)
package.payload_stream = open(zip_file)
@@ -430,7 +420,6 @@ def create_patch_mpm(archive_parser, prefix="",
archive=""):
def create_pkg_mpm(archive_parser, prefix=""):
"""create a pacakge mpm from an archive parser holding the package
archive"""
-# if __debug__: print "DEBUG: creating package mpm for %s" % prefix
# header
header = copy.deepcopy(_solaris_header_fields)
@@ -506,11 +495,8 @@ def parse_pkginfo(pkginfo_str):
version_match = _ver_regex.match(dct.get('version', ''))
if version_match:
- #version = _illegal_ver_regex.sub("_",
version_match.group("ver")) or "0"
- #if __debug__: print "DEBUG: version is %s" %
version_match.group("ver")
version =
_sanitize_string_version(string.rstrip(version_match.group("ver"))) or
"0"
release = version_match.group("rev")
- #if __debug__: print "DEBUG: release is %s" %
version_match.group("rev")
dct['version'] = version
if release:
@@ -683,7 +669,6 @@ def md5sum_for_stream(data_stream):
def parse_cluster_readme(readme_string):
"""Parse the README file for the summary, date and
description"""
-# if __debug__: print "DEBUG: parsing cluster readme"
lines = readme_string.splitlines()
trans_dict = { "NAME:": "summary",
@@ -703,7 +688,6 @@ def parse_cluster_readme(readme_string):
def parse_patch_readme(readme_string):
"""Parse the patch readme and return a dict containing fields: date,
summary, solaris_rel, sunos_rel, and target_arch"""
-# if __debug__: print "DEBUG: parsing patch readme"
lines = readme_string.splitlines()
trans_dict = { "Date:": "date",
@@ -917,10 +901,6 @@ def write_mpm(mpm):
if mpm is None: return
-# if __debug__:
-# print "DEBUG: mpm header"
-# pprint(mpm.header.hdr)
-
dest = _compute_filename(mpm.header)
print "Writing %s" % dest
@@ -977,7 +957,7 @@ def _normalize_arch(arch):
arch = "sparc"
# bug 170722, check that the arch is something sane
- if __debug__: assert arch in ("i386", "sparc",
"noarch"), "Unknown arch %s" % arch
+ assert arch in ("i386", "sparc", "noarch"),
"Unknown arch %s" % arch
return arch
commit 826ac6b5ceae94396e27f1b45f940de85777dbeb
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon May 3 16:08:29 2010 +0200
archive_dir is already appended to self._archive_dir
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index 35a7403..a5491fe 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -179,7 +179,7 @@ class ArchiveParser(object):
""" Returns the contens of the file, file is relative path in
archive.
Top most level (_get_archive_dir) is automaticaly added.
"""
- f = os.path.join(os.path.abspath(self._archive_dir), self._get_archive_dir(),
file)
+ f = os.path.join(os.path.abspath(self._archive_dir), file)
contents = None
if os.path.isfile(f) and os.access(f, os.R_OK):
commit 8a787342784f374f0ceb1fcc5a471d9c33a84964
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon May 3 14:52:26 2010 +0200
559092 - call external command using shell, since we provide just string and not full
path and array of arguments
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index 5830246..35a7403 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -305,7 +305,7 @@ def _my_popen(cmd):
"""Execute a command as a subprocess and return its exit
status"""
popen = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, close_fds=True)
+ stderr=subprocess.PIPE, close_fds=True, shell=True)
popen.stdin.close()
txt = ""
commit 55754c9d63b474fa85f011d6ab7645ecb0395dcf
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Apr 30 16:31:59 2010 +0200
removing comments and debugging code
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index c485ee2..5830246 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -93,10 +93,8 @@ class ArchiveParser(object):
assert self._archive_dir is not None # assigned in _explode_cmd
if cmd:
-# if __debug__: print "DEBUG: running command: %s" % cmd
status = _my_popen(cmd)
-# if __debug__: print "DEBUG: testing for %s" % self._archive_dir
if os.path.isdir(self._archive_dir):
return
@@ -160,10 +158,6 @@ class ArchiveParser(object):
else:
f.append(i)
- if __debug__:
- d.sort()
- f.sort()
-
return (d, f)
def contains(self, file):
@@ -200,7 +194,6 @@ class ArchiveParser(object):
def zip(self, prefix=""):
"""Create a zip archive of a (sub-)directory of the
archive"""
-# if __debug__: print "DEBUG: creating zip file for %s" % dir
dir = os.path.join(self._archive_dir, prefix)
zip_dir = os.path.basename(dir)
@@ -223,7 +216,6 @@ class ArchiveParser(object):
def cpio(self, prefix):
"""Create a cpio archive of a (sub-)directory of the
archive"""
-# if __debug__: print "DEBUG: creating cpio archive file for %s" %
prefix
cpio_file = os.path.join(self._temp_dir, "%s.pkg" % prefix)
@@ -339,7 +331,6 @@ def _my_popen(cmd):
def _decompress(archive):
"""[internal] Decompress compressed archives and return the new
archive name"""
-# if __debug__: print "DEBUG decompressing '%s'" % archive
cmd = ""
sfx_list = None
commit accf13867b820d64cda333215d16a24c62feb4c6
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Apr 30 16:24:33 2010 +0200
559092 - implement direct_read()
read() finds first occurence of file in this case somewhere in middle of archive,
but for README we want that one, which reside in top level directory
so we want to be able to specify full path
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index ea7ce6a..c485ee2 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -107,7 +107,7 @@ class ArchiveParser(object):
# private helper methods ---------------------------------------------
def _find(self, file):
- """[internal] Returns the absolute path to a file in the
archive"""
+ """[internal] Returns the relative path to a file in the
archive"""
file_path = None
contents = os.listdir(self._archive_dir)
@@ -131,8 +131,7 @@ class ArchiveParser(object):
contents.extend(e_contents)
else:
if entry.endswith(file):
- file_path = os.path.join(os.path.abspath(self._archive_dir), entry)
- assert os.path.isfile(file_path), "[_find] invalid path:
%s" % file_path
+ file_path = entry
break
else:
@@ -172,9 +171,21 @@ class ArchiveParser(object):
return self._find(file) is not None
def read(self, file):
- """Returns the contents of the file, or None on
error"""
+ """Returns the contents of the file, or None on error
+ First occurence of that file in archive is returned
+ """
- f = self._find(file) or ''
+ f = self._find(file)
+ if f:
+ return self.direct_read(f)
+ else:
+ return None
+
+ def direct_read(self, file):
+ """ Returns the contens of the file, file is relative path in
archive.
+ Top most level (_get_archive_dir) is automaticaly added.
+ """
+ f = os.path.join(os.path.abspath(self._archive_dir), self._get_archive_dir(),
file)
contents = None
if os.path.isfile(f) and os.access(f, os.R_OK):
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 9c451ba..87e18eb 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -292,7 +292,7 @@ def create_patch_set_mpm(archive_parser, archive):
p_name = os.path.basename(archive_parser._archive_dir)
header['name'] = "patch-cluster-solaris-" + p_name
- readme = archive_parser.read("README")
+ readme = archive_parser.direct_read("README")
header['readme'] = readme
if readme is None:
readme = archive_parser.read(p_name + ".README")
commit 2aad335d35cc018842579b166605995991a85c89
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Fri Apr 30 15:00:05 2010 +0200
no need to copy file, we can operate directly on original
diff --git a/client/tools/rhnpush/archive.py b/client/tools/rhnpush/archive.py
index 9fee4d5..ea7ce6a 100644
--- a/client/tools/rhnpush/archive.py
+++ b/client/tools/rhnpush/archive.py
@@ -50,7 +50,7 @@ class ArchiveParser(object):
"""Initialize an archive parser"""
assert os.path.exists(archive)
- self._archive = None
+ self._archive = archive
self._archive_dir = None
# bug 164756: allow optional working directory
@@ -73,18 +73,6 @@ class ArchiveParser(object):
# methods called by constructor --------------------------------------
- def _copy_archive(self, archive):
- """[internal] Copy the archive to a temporary
directory"""
-# if __debug__: print "DEBUG: copying archive to %s" % self._temp_dir
-
- # copy the archive to the temporary directory
- a_name = os.path.basename(archive)
- a_path = os.path.join(self._temp_dir, a_name)
-
- shutil.copyfile(archive, a_path)
-
- self._archive = a_path
-
def _get_archive_dir(self):
"""[internal] find the archive's top level directory
name"""
@@ -99,7 +87,6 @@ class ArchiveParser(object):
def _explode(self, archive):
"""[internal] Explode a archive for neutral
parsing"""
- self._copy_archive(archive)
cmd = self._explode_cmd()
assert self._archive is not None # assigned in _copy_archive
commit beabe0a2dc9f67879843276f39389fe35725f95f
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Apr 29 17:17:28 2010 +0200
do not read one file twice
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 67d3f4f..9c451ba 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -293,11 +293,11 @@ def create_patch_set_mpm(archive_parser, archive):
header['name'] = "patch-cluster-solaris-" + p_name
readme = archive_parser.read("README")
+ header['readme'] = readme
if readme is None:
readme = archive_parser.read(p_name + ".README")
assert readme is not None, "Couldn't fine README file for %s" % p_name
- header['readme'] = archive_parser.read("README")
# provides fields: date, summary, and description
dct = parse_cluster_readme(readme)
commit 98cac1999757b3d242c3cf38090d4208625f5f18
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Apr 29 17:07:51 2010 +0200
559092 - format of date in REDME has been changed by SUN
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index ad84512..67d3f4f 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -1060,10 +1060,10 @@ def _compute_filename(dct):
def _to_db_timestamp(s):
"""Convert common Solaris date convention to a unix
timestamp"""
- arr = s.split('/', 2)
+ arr = s.split('.', 2)
if len(arr) != 3:
return None
- m, d, y = arr
+ y, m, d = arr
try:
m = int(m)
commit baac5c9e9f07a8957b60b5bac8535bd523e2ec42
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Apr 29 16:59:33 2010 +0200
559092 - CLUSTER_README has been renamed to README by sun in new format
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 0fc1217..ad84512 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -292,12 +292,12 @@ def create_patch_set_mpm(archive_parser, archive):
p_name = os.path.basename(archive_parser._archive_dir)
header['name'] = "patch-cluster-solaris-" + p_name
- readme = archive_parser.read("CLUSTER_README")
+ readme = archive_parser.read("README")
if readme is None:
readme = archive_parser.read(p_name + ".README")
assert readme is not None, "Couldn't fine README file for %s" % p_name
- header['readme'] = archive_parser.read("CLUSTER_README")
+ header['readme'] = archive_parser.read("README")
# provides fields: date, summary, and description
dct = parse_cluster_readme(readme)
@@ -682,7 +682,7 @@ def md5sum_for_stream(data_stream):
# patch set mpm creation -------------------------------------------------
def parse_cluster_readme(readme_string):
- """Parse the CLUSTER_README file for the summary, date and
description"""
+ """Parse the README file for the summary, date and
description"""
# if __debug__: print "DEBUG: parsing cluster readme"
lines = readme_string.splitlines()
commit aa286843fa4680af003dc998154112b1bf115170
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Apr 29 16:57:31 2010 +0200
559092 - install_cluster has been renamed to installcluster by sun in new format
diff --git a/client/tools/rhnpush/solaris2mpm.py b/client/tools/rhnpush/solaris2mpm.py
index 18df915..0fc1217 100644
--- a/client/tools/rhnpush/solaris2mpm.py
+++ b/client/tools/rhnpush/solaris2mpm.py
@@ -258,17 +258,13 @@ def _close_mpm(mpm):
def _is_patch_set_archive(archive_parser):
"""[internal] Returns true iff the parser contains a patch set
archive"""
-# x, files = archive_parser.list()
-# return "install_cluster" in files
- return archive_parser.contains("install_cluster")
+ return archive_parser.contains("installcluster")
def _is_patch_archive(archive_parser):
"""[internal] Returns true iff the parser contains a patch
archive"""
patch_name = os.path.basename(archive_parser._archive_dir) # hack
readme = "README.%s" % patch_name
-# x, files = archive_parser.list()
-# return readme in files
return archive_parser.contains(readme)