Created
September 25, 2014 04:33
-
-
Save ninowalker/830e08858d928a14e6ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg_resources | |
def get_pkg_license(pkgname): | |
""" | |
Given a package reference (as from requirements.txt), | |
return license listed in package metadata. | |
NOTE: This function does no error checking and is for | |
demonstration purposes only. | |
""" | |
pkgs = pkg_resources.require(pkgname) | |
pkg = pkgs[0] | |
for line in pkg.get_metadata_lines('PKG-INFO'): | |
(k, v) = line.split(': ', 1) | |
if k == "License": | |
return v | |
return None | |
for w in pkg_resources.working_set: | |
try: | |
print w, get_pkg_license(str(w).split(" ")[0]) | |
except: | |
print "UNKNOWN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment