[Catalog-sig] Extending the package meta-data with more detailed download information

M.-A. Lemburg mal at egenix.com
Fri Nov 20 10:23:29 CET 2009


"Martin v. Löwis" wrote:
>> Thoughts ?
> 
> The issue I see is that you have not only one, but many such
> distributions per release. 

Exactly and that's why more information is needed to figure out
which dsitribution file to download than just a single URL
can deliver.

> So I'm curious as to how you would provide/render that information.

Since the meta-format uses RFC822 format, the natural choice would
be to be have one semi-colon separated multi-line entry per
distribution file. However, since PEP 345 already uses the semi-colon
for environment markers, we'd have to use a plain comma...

(Working) Example:

import email

meta_data = """\
Distribution-File:
 Type: sdist,
 URL: http://example.net/pkg-A-1.2.3.tgz,
 Comment: "Source package, needs a C compiler installed.",
 MD5: 123456789ABCDEF,
 SHA1: 123456789ABCDEF,
 PGP: ".....(multi-line text)
       .....",
 Python-Implementation: CPython,
 OS: Windows,
Distribution-File:
 Type: bdist_msi,
 URL: http://example.net/pkg-1.2.3.msi,
 MD5: 123456789ABCDEF,
 SHA1: 123456789ABCDEF,
 PGP: ".....(multi-line text)
       .....",
 Python-Implementation: CPython,
 Python-Version: 2.5,
 Python-Variant: UCS2,
 OS: Windows,
 OS-Version: XP,
 Architecture: x86,
 Processor: i686
Distribution-File:
 Type: bdist_rpm,
 URL: http://example.net/pkg-1.2.3.rpm,
 MD5: 123456789ABCDEF,
 SHA1: 123456789ABCDEF,
 PGP: ".....(multi-line text)
       .....",
 Python-Implementation: CPython,
 Python-Version: 2.5,
 Python-Variant: UCS2,
 OS: Fedora,
 OS-Version: 8,
 Architecture: x86,
 Processor: i386
"""
m = email.message_from_string(meta_data + '\n\n')
print m.items()

Which gives:

[('Distribution-File', ' Type: sdist,\n URL: http://example.net/pkg-A-1.2.3.tgz,\n Comment: "Source
package, needs a C compiler installed.",\n MD5: 123456789ABCDEF,\n SHA1: 123456789ABCDEF,\n PGP:
".....(multi-line text)\n       .....",\n Python-Implementation: CPython,\n OS: Windows,'),
('Distribution-File', ' Type: bdist_msi,\n URL: http://example.net/pkg-1.2.3.msi,\n MD5:
123456789ABCDEF,\n SHA1: 123456789ABCDEF,\n PGP: ".....(multi-line text)\n       .....",\n
Python-Implementation: CPython,\n Python-Version: 2.5,\n Python-Variant: UCS2,\n OS: Windows,\n
OS-Version: XP,\n Architecture: x86,\n Processor: i686'), ('Distribution-File', ' Type: bdist_rpm,\n
URL: http://example.net/pkg-1.2.3.rpm,\n MD5: 123456789ABCDEF,\n SHA1: 123456789ABCDEF,\n PGP:
".....(multi-line text)\n       .....",\n Python-Implementation: CPython,\n Python-Version: 2.5,\n
Python-Variant: UCS2,\n OS: Fedora,\n OS-Version: 8,\n Architecture: x86,\n Processor: i386')]

The entries can then be further decoded into dictionaries:

import re
ENTRY_RE = re.compile('\s+([-a-zA-Z0-9]+):\s*("[^"]+"|[^,\n\r]+)([,\n\r]|$)')

dist_files = []
for name, value in m.items():
    if name.lower() == 'distribution-file':
        d = {}
        for match in ENTRY_RE.finditer(value):
            token_name = match.group(1)
            token_value = match.group(2)
            d[token_name] = token_value
        dist_files.append(d)

print dist_files

Which gives:

[{'Comment': '"Source package, needs a C compiler installed."', 'SHA1': '123456789ABCDEF', 'URL':
'http://example.net/pkg-A-1.2.3.tgz', 'OS': 'Windows', 'Python-Implementation': 'CPython', 'PGP':
'".....(multi-line text)\n       ....."', 'Type': 'sdist', 'MD5': '123456789ABCDEF'}, {'OS':
'Windows', 'SHA1': '123456789ABCDEF', 'URL': 'http://example.net/pkg-1.2.3.msi', 'Python-Variant':
'UCS2', 'Python-Implementation': 'CPython', 'Python-Version': '2.5', 'Architecture': 'x86', 'PGP':
'".....(multi-line text)\n       ....."', 'OS-Version': 'XP', 'Type': 'bdist_msi', 'Processor':
'i686', 'MD5': '123456789ABCDEF'}, {'OS': 'Fedora', 'SHA1': '123456789ABCDEF', 'URL':
'http://example.net/pkg-1.2.3.rpm', 'Python-Variant': 'UCS2', 'Python-Implementation': 'CPython',
'Python-Version': '2.5', 'Architecture': 'x86', 'PGP': '".....(multi-line text)\n       ....."',
'OS-Version': '8', 'Type': 'bdist_rpm', 'Processor': 'i386', 'MD5': '123456789ABCDEF'}]

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 20 2009)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Catalog-SIG mailing list