comparison paint/info.py @ 77:00c0f668f332

implementation of setup2metadata
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 27 Jan 2013 22:19:10 -0800
parents 84890934af1f
children
comparison
equal deleted inserted replaced
76:b4fb27d126aa 77:00c0f668f332
2 interfaces to get information from a package 2 interfaces to get information from a package
3 """ 3 """
4 4
5 5
6 import imp 6 import imp
7 import pkginfo
7 import os 8 import os
8 import subprocess 9 import subprocess
9 import sys 10 import sys
10 11
11 from distutils.dist import Distribution 12 from distutils.dist import Distribution
12 from distutils.dist import DistributionMetadata
13 from subprocess import check_call as call 13 from subprocess import check_call as call
14 from StringIO import StringIO 14 from StringIO import StringIO
15 15
16 # TODO: 16 # TODO:
17 # Reconcile the difference between the keys (and values) between the different 17 # Reconcile the difference between the keys (and values) between the different
35 http://www.python.org/dev/peps/pep-0314/ 35 http://www.python.org/dev/peps/pep-0314/
36 """ 36 """
37 distribution = Distribution(attrs) 37 distribution = Distribution(attrs)
38 buffer = StringIO() 38 buffer = StringIO()
39 distribution.metadata.write_pkg_file(buffer) 39 distribution.metadata.write_pkg_file(buffer)
40 raise NotImplementedError("TODO") 40 pkginfo_dist = pkginfo.Distribution()
41 pkinfo_dist.parse(buffer.getvalue())
42 newattrs = dict((i, getattr(pkginfo_dist, i)) for i in pkginfo_dist)
43 header_dict = dict((attr_name, header_name)
44 for header_name, attr_name, multiple in pkginfo_dist._getHeaderAttrs())
45 info = dict((header_dict[key], value) for key, value in newattrs.items())
46
47 # XXX pkginfo says 'Home-Page' though the spec says Home-page
48 info.setdefault('Home-page', info['Home-Page'])
49
50 return info
41 51
42 52
43 class PackageInfo(object): 53 class PackageInfo(object):
44 """abstract base class of package info""" 54 """abstract base class of package info"""
45 def __init__(self, path): 55 def __init__(self, path):