File: build.py

package info (click to toggle)
debian-timeline 12
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 176 kB
  • ctags: 10
  • sloc: python: 38; makefile: 29
file content (52 lines) | stat: -rwxr-xr-x 1,442 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python

import os
import sys
import shutil

from glob import glob
from debian import deb822
from xml.dom.minidom import Document

def main(dir):
    num = 0

    doc = Document()
    events = doc.createElement('data')
    doc.appendChild(events)

    for filename in glob(os.path.join(dir, '*')):
        print >>sys.stderr, "Reading events from %s" % filename,
        input = file(filename).read().decode('utf-8').split('\n')

        obj = deb822.Deb822(input)
        for para in deb822.Deb822.iter_paragraphs(input, use_apt_pkg=False):
            events.appendChild(create_event(doc, para))
            sys.stderr.write('.')
            num += 1
        print >>sys.stderr

    print >>sys.stderr, "Writing %s events" % num

    print '<!-- Generated from %s/* - do not edit -->' % dir
    print events.toprettyxml(indent='  ').encode('utf-8')

def create_event(doc, para):
    entry = doc.createElement('entry')
    entry.setAttribute('title', para['Title'])

    if 'Start-Date' in para:
        entry.setAttribute('isDuration', 'true')
        entry.setAttribute('start', para['Start-Date'])
        entry.setAttribute('end', para['End-Date'])
    else:
        entry.setAttribute('start', para['Date'])

    if 'Source' in para:
        text = doc.createTextNode('<a href="%s">Source</a>' % para['Source'])
        entry.appendChild(text)

    return entry

if __name__ == '__main__':
    sys.exit(main(sys.argv[1]))