Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Jul 17, 2008
1 parent c378844 commit b809937
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions z3c/jbot/manager.py
Expand Up @@ -14,12 +14,15 @@ def root_length(a, b):
else:
return 0

def sort_by_path(path, paths):
return sorted(
paths, key=lambda syspath: root_length(syspath, path), reverse=True)

def find_zope2_product(path):
"""Check the Zope2 magic Products semi-namespace to see if the
path is part of a Product."""
_syspaths = sorted(
sys.modules["Products"].__path__,
key=lambda syspath: root_length(syspath, path), reverse=True)

_syspaths = sort_by_path(path, sys.modules["Products"].__path__)
syspath = _syspaths[0]

if not path.startswith(syspath):
Expand All @@ -34,9 +37,7 @@ def find_package(syspaths, path):
"""Determine the Python-package where path is located. If the path is
not located within the Python sys-path, return ``None``."""

_syspaths = sorted(
syspaths, key=lambda syspath: root_length(syspath, path), reverse=True)

_syspaths = sort_by_path(path, syspaths)
syspath = _syspaths[0]

path = os.path.normpath(path)
Expand Down

0 comments on commit b809937

Please sign in to comment.