summaryrefslogtreecommitdiff
blob: 8db3a08d414f76bd3a04ba4cf0476602cf7f9a09 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL 2 or later

import xml.etree.ElementTree as ET
import codecs

from extradata import * # local
from feedextractors import * # local
from sharedutils import * # local

def to_ascii(o, current_encoding='utf-8'):
    if not isinstance(o, basestring):
        return o

    if isinstance(o, unicode):
        s = o
    else:
        s = unicode(o, current_encoding)
    return codecs.encode(s, 'ascii', 'ignore')

def append_feed(feed_uri, overlay_object):
    feed = ET.Element('feed')
    feed.text = feed_uri
    overlay_object.append(feed)

a = ET.parse(open('layman-global.txt'))
overlays = a.getroot()

for overlay in overlays:
    repo_name = overlay.attrib['name']
    extra_data = TRANSITION_DATA_EXTRA.get(repo_name, {})

    # Move 'description' tag
    description = overlay.find('description')
    overlay.remove(description)
    overlay.insert(0, description)

    # Transform 'overlay' tag
    overlay.tag = 'repo'
    del overlay.attrib['name']
    name = ET.Element('name')
    name.text = repo_name
    overlay.insert(0, name)

    # Transform 'link' tag
    link = overlay.find('link')
    if link != None:
        link.tag = 'homepage'

    # Transform 'contact' attribute
    owner = ET.Element('owner')
    overlay.append(owner)
    email = ET.Element('email')
    email.text = extra_data.get('owner', {}).\
            get('email', overlay.attrib['contact'])
    del overlay.attrib['contact']
    owner.append(email)

    # Transform 'src' and 'type' attribute
    source = ET.Element('source')
    source.text = overlay.attrib['src']
    del overlay.attrib['src']
    source.attrib['type'] = overlay.attrib['type']
    del overlay.attrib['type']
    overlay.append(source)

    # Extend by quality label
    try:
        overlay.attrib['quality'] = extra_data['quality']
    except KeyError:
        pass

    # Extend by owner type
    if repo_name in TRANSITION_DATA_PROJECTS:
        owner.attrib['type'] = 'project'

    # Extend by owner name
    try:
        maint_name = extra_data['owner']['name']
        name = ET.Element('name')
        name.text = maint_name
        owner.append(name)
    except KeyError:
        pass

    # Extend by feed URIs
    for fe in FEED_EXTRACTORS:
        uri = fe['regex'].sub(fe['format'], source.text)
        if uri != source.text:
            append_feed(uri, overlay)
            break
    try:
        feed_uris = extra_data['feeds']
    except KeyError:
        feed_uris = ()
    for uri in feed_uris:
        append_feed(uri, overlay)

    # Explicify defaults
    if 'status' not in overlay.attrib:
        overlay.attrib['status'] = 'unofficial'
    if 'quality' not in overlay.attrib:
        overlay.attrib['quality'] = 'experimental'

    # Add note on file being a generated one
    overlay.insert(0, ET.Comment('NOTE: This file is generated, do not edit.'))

# Transform 'overlays' tag
overlays.tag = 'repositories'

# Extend by format version
overlays.attrib['version'] = '1.0'



recurse_print(overlays)
indent(overlays)
repositories_xml = open('repositories.xml', 'w')
repositories_xml.write("""\
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header$ -->
<?xml-stylesheet href="/xsl/repositories.xsl" type="text/xsl"?>
<!DOCTYPE repositories SYSTEM "/dtd/repositories.dtd">
""")
a.write(repositories_xml, encoding='utf-8')
repositories_xml.close()