[csw-devel] SF.net SVN: gar:[20823] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Sat Apr 20 14:14:38 CEST 2013
Revision: 20823
http://gar.svn.sourceforge.net/gar/?rev=20823&view=rev
Author: wahwah
Date: 2013-04-20 12:14:37 +0000 (Sat, 20 Apr 2013)
Log Message:
-----------
checkpkg: Explicitly close the file magic object.
Also adjust the unit test.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/inspective_package.py
csw/mgar/gar/v2/lib/python/inspective_package_test.py
Modified: csw/mgar/gar/v2/lib/python/inspective_package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package.py 2013-04-20 11:26:11 UTC (rev 20822)
+++ csw/mgar/gar/v2/lib/python/inspective_package.py 2013-04-20 12:14:37 UTC (rev 20823)
@@ -24,6 +24,12 @@
return re.sub(strip_re, "", x)
+def GetMachineIdOfBinary(full_path):
+ with open(full_path, 'rb') as elf_fd:
+ elffile = ELFFile(elf_fd)
+ return ENUM_E_MACHINE[elffile.header['e_machine']]
+
+
def GetFileMetadata(file_magic, base_dir, file_path):
full_path = unicode(os.path.join(base_dir, file_path))
if not os.access(full_path, os.R_OK):
@@ -54,9 +60,7 @@
else:
raise package.PackageError(msg)
if sharedlib_utils.IsBinary(file_info, check_consistency=False):
- with open(full_path, 'rb') as elf_fd:
- elffile = ELFFile(elf_fd)
- file_info["machine_id"] = ENUM_E_MACHINE[elffile.header['e_machine']]
+ file_info["machine_id"] = GetMachineIdOfBinary(full_path)
return file_info
class InspectivePackage(package.DirectoryFormatPackage):
@@ -85,6 +89,7 @@
# To prevent files from containing the full temporary path.
file_info["path"] = StripRe(file_path, ROOT_RE)
self.files_metadata.append(file_info)
+ file_magic.close()
return self.files_metadata
def ListBinaries(self):
@@ -686,9 +691,9 @@
self.cookie_count = 0
self._magic_cookie = None
- def __del__(self):
- if self.magic_cookie:
- self.magic_cookie.close()
+ def close(self):
+ self._magic_cookie.close()
+ self._magic_cookie = None
@property
def magic_cookie(self):
Modified: csw/mgar/gar/v2/lib/python/inspective_package_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package_test.py 2013-04-20 11:26:11 UTC (rev 20822)
+++ csw/mgar/gar/v2/lib/python/inspective_package_test.py 2013-04-20 12:14:37 UTC (rev 20823)
@@ -137,21 +137,8 @@
class InspectivePackageUnitTest(mox.MoxTestBase):
def testListBinaries(self):
- self.mox.StubOutWithMock(hachoir_parser, 'createParser',
- use_mock_anything=True)
- hachoir_parser_mock = self.mox.CreateMockAnything()
- parser_tag = ('class', hachoir_parser.program.elf.ElfFile)
- hachoir_parser.createParser(
- u'/fake/path/CSWfoo/root/foo-file',
- tags = [parser_tag]).AndReturn(hachoir_parser_mock)
self.mox.StubOutWithMock(os, 'access')
os.access(u'/fake/path/CSWfoo/root/foo-file', os.R_OK).AndReturn(True)
- machine_mock = self.mox.CreateMockAnything()
- machine_mock.value = 2
- hachoir_parser_mock.__getitem__('/header/machine').AndReturn(machine_mock)
- endian_mock = self.mox.CreateMockAnything()
- endian_mock.display = 'fake-endian'
- hachoir_parser_mock.__getitem__('/header/endian').AndReturn(endian_mock)
magic_cookie_mock = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(magic, 'open')
magic.open(0).AndReturn(magic_cookie_mock)
@@ -164,6 +151,7 @@
magic_cookie_mock.file(
u'/fake/path/CSWfoo/root/foo-file').AndReturn(
"application/x-executable")
+ magic_cookie_mock.close()
self.mox.StubOutWithMock(os.path, 'isdir')
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(os, 'walk')
@@ -178,6 +166,8 @@
("/fake/path/CSWfoo/root", [], ["foo-file"]),
]
)
+ self.mox.StubOutWithMock(inspective_package, 'GetMachineIdOfBinary')
+ inspective_package.GetMachineIdOfBinary(u'/fake/path/CSWfoo/root/foo-file').AndReturn(42)
self.mox.ReplayAll()
ip = inspective_package.InspectivePackage("/fake/path/CSWfoo")
ip.pkginfo_dict = {
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