getpackage in util.py should only parse files and packages

Directories that end with .py but are not Python packages should not be
parsed as if they are modules.
getpackage now verifies that the path is either a .py file or a package.
This fixes #526