/usr/lib/python2.7/dist-packages/pkginfo/installed.py is in python-pkginfo 1.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import glob
import os
import sys
import warnings
from pkginfo.distribution import Distribution
from pkginfo._compat import STRING_TYPES
class Installed(Distribution):
def __init__(self, package, metadata_version=None):
if isinstance(package, STRING_TYPES):
self.package_name = package
try:
__import__(package)
except ImportError:
package = None
else:
package = sys.modules[package]
else:
self.package_name = package.__name__
self.package = package
self.metadata_version = metadata_version
self.extractMetadata()
def read(self):
opj = os.path.join
if self.package is not None:
package = self.package.__package__
if package is None:
package = self.package.__name__
pattern = '%s*.egg-info' % package
file = getattr(self.package, '__file__', None)
if file is not None:
candidates = []
def _add_candidate(where):
candidates.extend(glob.glob(where))
for entry in sys.path:
if file.startswith(entry):
_add_candidate(opj(entry, 'EGG-INFO')) # egg?
_add_candidate(opj(entry, pattern)) # dist-installed?
dir, name = os.path.split(self.package.__file__)
_add_candidate(opj(dir, pattern))
_add_candidate(opj(dir, '..', pattern))
for candidate in candidates:
if os.path.isdir(candidate):
path = opj(candidate, 'PKG-INFO')
else:
path = candidate
if os.path.exists(path):
with open(path) as f:
return f.read()
warnings.warn('No PKG-INFO found for package: %s' % self.package_name)
|