/usr/share/pyshared/z3c/autoinclude/dependency.py is in python-z3c.autoinclude 0.3.5-0ubuntu1.
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 | import os
import logging
from zope.dottedname.resolve import resolve
from pkg_resources import resource_exists
from pkg_resources import get_provider
from pkg_resources import get_distribution
from z3c.autoinclude.utils import DistributionManager
from z3c.autoinclude.utils import ZCMLInfo
class DependencyFinder(DistributionManager):
def includableInfo(self, zcml_to_look_for):
"""Return the packages in the dependencies which are includable.
zcml_to_look_for - a list of zcml filenames we are looking for
Returns a dictionary with the include candidates as keys, and lists
of dotted names of packages that contain the include candidates as
values.
"""
result = ZCMLInfo(zcml_to_look_for)
for req in self.context.requires():
dist_manager = DistributionManager(get_provider(req))
for dotted_name in dist_manager.dottedNames():
try:
module = resolve(dotted_name)
except ImportError, exc:
logging.getLogger("z3c.autoinclude").warn(
"resolve(%r) raised import error: %s" % (dotted_name, exc))
continue
for candidate in zcml_to_look_for:
candidate_path = os.path.join(
os.path.dirname(module.__file__), candidate)
if os.path.isfile(candidate_path):
result[candidate].append(dotted_name)
return result
def package_includes(project_name, zcml_filenames=None):
"""
Convenience function for finding zcml to load from requirements for
a given project. Takes a project name. DistributionNotFound errors
will be raised for uninstalled projects.
"""
if zcml_filenames is None:
zcml_filenames = ['meta.zcml', 'configure.zcml', 'overrides.zcml']
dist = get_distribution(project_name)
include_finder = DependencyFinder(dist)
return include_finder.includableInfo(zcml_filenames)
|