aboutsummaryrefslogtreecommitdiff
path: root/load_packages.py
blob: 0209b59199d6620e05d7cbff2941d4a204550376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

import debian.deb822
import pandas as pd

def pkg(para):
    d = dict(para)

    if 'Source' in d:
        # Source fields sometimes have the source version number; strip it.
        d['_srcpkg'] = d['Source'].split(' ')[0]
    else:
        # No 'Source' field means that it has the same value as the 'Package'
        # field.
        d['_srcpkg'] = d['Package']

    return d

if __name__ == '__main__':
    packages = debian.deb822.Packages.iter_paragraphs(sys.stdin)
    df = pd.DataFrame([pkg(p) for p in packages])
    store = pd.HDFStore('pkg.h5')

    print df

    store = pd.HDFStore('pkg.h5')
    store['packages'] = df
    store.close()