[csw-devel] SF.net SVN: gar:[14921] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Tue Jun 28 11:29:50 CEST 2011
Revision: 14921
http://gar.svn.sourceforge.net/gar/?rev=14921&view=rev
Author: wahwah
Date: 2011-06-28 09:29:50 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
checkpkg: Relocatable package support
GAR packages are not relocatable, but there is a couple of relocatable
packages in the catalog.
There's one function responsible from returning the basedir, but without the
trailing slash, because that't the convention of keeping paths in checkpkg.
When constructing pkgmap however, the slash needs to be added back - paths in
the files table and in the pkgmap list need to be absolute.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/README
csw/mgar/gar/v2/lib/python/inspective_package.py
csw/mgar/gar/v2/lib/python/inspective_package_test.py
csw/mgar/gar/v2/lib/python/package.py
csw/mgar/gar/v2/lib/python/pkgmap.py
Modified: csw/mgar/gar/v2/lib/python/README
===================================================================
--- csw/mgar/gar/v2/lib/python/README 2011-06-28 09:25:37 UTC (rev 14920)
+++ csw/mgar/gar/v2/lib/python/README 2011-06-28 09:29:50 UTC (rev 14921)
@@ -61,6 +61,7 @@
given as alternatives, but the reason is common.
- Notify maintainers when their package is available from mirrors
- Add support for the 'overridden' field in the database
+- Support for relocatable packages
Known problems:
- libmagic fails sometimes when processing the whole catalog
Modified: csw/mgar/gar/v2/lib/python/inspective_package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package.py 2011-06-28 09:25:37 UTC (rev 14920)
+++ csw/mgar/gar/v2/lib/python/inspective_package.py 2011-06-28 09:29:50 UTC (rev 14921)
@@ -37,18 +37,21 @@
if not self.files_metadata:
self.CheckPkgpathExists()
self.files_metadata = []
- files_root = os.path.join(self.directory, "root")
+ files_root = self.GetFilesDir()
all_files = self.GetAllFilePaths()
def StripRe(x, strip_re):
return re.sub(strip_re, "", x)
- root_re = re.compile(r"^root/")
+ root_re = re.compile(r"^(reloc|root)/")
file_magic = FileMagic()
+ basedir = self.GetBasedir()
for file_path in all_files:
full_path = unicode(self.MakeAbsolutePath(file_path))
file_info = {
"path": StripRe(file_path, root_re),
"mime_type": file_magic.GetFileMimeType(full_path)
}
+ if basedir:
+ file_info["path"] = os.path.join(basedir, file_info["path"])
if not file_info["mime_type"]:
logging.error("Could not establish the mime type of %s",
full_path)
@@ -108,32 +111,57 @@
self.binaries.sort()
return self.binaries
+ def GetPathsInSubdir(self, remove_prefix, subdir):
+ file_paths = []
+ for root, dirs, files in os.walk(os.path.join(self.pkgpath, subdir)):
+ full_paths = [os.path.join(root, f) for f in files]
+ file_paths.extend([f.replace(remove_prefix, "") for f in full_paths])
+ return file_paths
+
def GetAllFilePaths(self):
"""Returns a list of all paths from the package."""
if not self.file_paths:
+ # Support for relocatable packages
+ basedir = self.GetBasedir()
self.CheckPkgpathExists()
remove_prefix = "%s/" % self.pkgpath
- self.file_paths = []
- for root, dirs, files in os.walk(os.path.join(self.pkgpath, "root")):
- full_paths = [os.path.join(root, f) for f in files]
- self.file_paths.extend([f.replace(remove_prefix, "") for f in full_paths])
+ self.file_paths = self.GetPathsInSubdir(remove_prefix, "root")
+ self.file_paths += self.GetPathsInSubdir(remove_prefix, "reloc")
return self.file_paths
+ def GetFilesDir(self):
+ """Returns the subdirectory in which files, are either "reloc" or "root"."""
+ if os.path.exists(os.path.join(self.directory, "reloc")):
+ return "reloc"
+ else:
+ return "root"
+
def GetBinaryDumpInfo(self):
# Binaries. This could be split off to a separate function.
# man ld.so.1 for more info on this hack
env = copy.copy(os.environ)
env["LD_NOAUXFLTR"] = "1"
binaries_dump_info = []
+ basedir = self.GetBasedir()
for binary in self.ListBinaries():
- binary_abs_path = os.path.join(self.directory, "root", binary)
- binary_base_name = os.path.basename(binary)
+ # Relocatable packages complicate things. Binaries returns paths with
+ # the basedir, but files in reloc are in paths without the basedir, so
+ # we need to strip that bit.
+ binary_in_tmp_dir = binary
+ if basedir:
+ binary_in_tmp_dir = binary_in_tmp_dir[len(basedir):]
+ binary_in_tmp_dir = binary_in_tmp_dir.lstrip("/")
+ binary_abs_path = os.path.join(self.directory, self.GetFilesDir(), binary_in_tmp_dir)
+ binary_base_name = os.path.basename(binary_in_tmp_dir)
args = [common_constants.DUMP_BIN, "-Lv", binary_abs_path]
+ logging.debug("Running: %s", args)
dump_proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=env)
stdout, stderr = dump_proc.communicate()
ret = dump_proc.wait()
binary_data = ldd_emul.ParseDumpOutput(stdout)
binary_data["path"] = binary
+ if basedir:
+ binary_data["path"] = os.path.join(basedir, binary_data["path"])
binary_data["base_name"] = binary_base_name
binaries_dump_info.append(binary_data)
return binaries_dump_info
Modified: csw/mgar/gar/v2/lib/python/inspective_package_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package_test.py 2011-06-28 09:25:37 UTC (rev 14920)
+++ csw/mgar/gar/v2/lib/python/inspective_package_test.py 2011-06-28 09:29:50 UTC (rev 14921)
@@ -21,7 +21,7 @@
class InspectivePackageUnitTest(mox.MoxTestBase):
- def testOne(self):
+ def testInstantiate(self):
self.mox.StubOutWithMock(hachoir_parser, 'createParser',
use_mock_anything=True)
hachoir_parser_mock = self.mox.CreateMockAnything()
Modified: csw/mgar/gar/v2/lib/python/package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package.py 2011-06-28 09:25:37 UTC (rev 14920)
+++ csw/mgar/gar/v2/lib/python/package.py 2011-06-28 09:29:50 UTC (rev 14921)
@@ -271,9 +271,21 @@
self.ShellCommand(args, quiet=True)
return target_path
+ def GetBasedir(self):
+ basedir_id = "BASEDIR"
+ pkginfo = self.GetParsedPkginfo()
+ if basedir_id in pkginfo:
+ basedir = pkginfo[basedir_id]
+ else:
+ basedir = ""
+ # The convention in checkpkg is to not include the leading slash in paths.
+ basedir = basedir.lstrip("/")
+ return basedir
+
def GetPkgmap(self, analyze_permissions=False, strip=None):
fd = open(os.path.join(self.directory, "pkgmap"), "r")
- return pkgmap.Pkgmap(fd, analyze_permissions, strip)
+ basedir = self.GetBasedir()
+ return pkgmap.Pkgmap(fd, analyze_permissions, strip, basedir)
def SetPkginfoEntry(self, key, value):
pkginfo = self.GetParsedPkginfo()
Modified: csw/mgar/gar/v2/lib/python/pkgmap.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgmap.py 2011-06-28 09:25:37 UTC (rev 14920)
+++ csw/mgar/gar/v2/lib/python/pkgmap.py 2011-06-28 09:29:50 UTC (rev 14921)
@@ -31,14 +31,22 @@
}
def __init__(self, input, permissions=False,
- strip=None):
+ strip=None, basedir=""):
self.paths = set()
self.analyze_permissions = permissions
self.entries = []
self.classes = None
self.strip = strip
+ self.basedir = basedir
for line in input:
entry, line_to_add = self._ParseLine(line)
+ # Relocatable packages support
+ if "path" in entry and entry["path"]:
+ entry["path"] = os.path.join(basedir, entry["path"])
+ # basedir here does not include the leading slash, but in pkgmap we
+ # need it.
+ if not entry["path"].startswith("/"):
+ entry["path"] = "/" + entry["path"]
self.entries.append(entry)
if line_to_add:
self.paths.add(line_to_add)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list