Folgendes habe ich fabriziert:
Code: Alles auswählen
#!/usr/bin/env python
# coding: utf-8
import pkg_resources
PKG_DIST_ATTRS = ("version", "project_name", "location")
pkg_env = pkg_resources.Environment()
for pkg_key in pkg_env:
print "***", pkg_key, "***"
# pkg_resources.Distribution instance:
pkg_dist = pkg_env[pkg_key][0]
for attr_name in PKG_DIST_ATTRS:
print attr_name, getattr(pkg_dist, attr_name)
print "-"*80
for line in pkg_dist.get_metadata_lines("PKG-INFO"):
print line
1. die erhaltenen Daten sind Strings, ich hätte aber gern unicode. Das Umwandeln mit "utf-8" klappt lokal, aber nicht auf den Server... (Das untersuche ich später noch genauer)
2. pkg_resources.Distribution.get_metadata liefert nur einen String bzw. einen iterator über die Zeilen zurück. Das sieht dann z.B. so aus:
Den String muß man also umständlich aufbröseln.Metadata-Version: 1.0
Name: eyeD3
Version: 0.6.16
Summary: Python ID3 and mp3 Tools
Home-page: http://eyed3.nicfit.net/
Author: Travis Shirk
Author-email: travis@pobox.com
License: UNKNOWN
Description:
eyeD3 is a Python module and program for processing ID3 tags.
Information about mp3 files (i.e bit rate, sample frequency,
play time, etc.) is also provided. The formats supported are ID3
v1.0/v1.1 and v2.3/v2.4.
Platform: UNKNOWN
Irgendwie muß es doch möglich sein direkt ein dict zu bekommen, oder?
Hintergrund:
Ich hab ein PyLucid Plugin geschrieben, welches Informationen über installierte Python Module auflistet. Das "Endprodukt" sieht dann so aus: http://www.pylucid.org/permalink/41/dep ... copyrights