~ubuntu-core-dev/software-properties/main

« back to all changes in this revision

Viewing changes to Common/DistInfo.py

  • Committer: Michael Vogt
  • Date: 2005-11-15 13:18:07 UTC
  • Revision ID: egon@top-20051115131807-12fada324eb74180
* initial revision (after accidently killing it)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# DistInfo.py - simple parser for a xml-based metainfo file
 
3
#  
 
4
#  Copyright (c) 2005 Gustavo Noronha Silva
 
5
#  
 
6
#  Author: Gustavo Noronha Silva <kov@debian.org>
 
7
 
8
#  This program is free software; you can redistribute it and/or 
 
9
#  modify it under the terms of the GNU General Public License as 
 
10
#  published by the Free Software Foundation; either version 2 of the
 
11
#  License, or (at your option) any later version.
 
12
 
13
#  This program is distributed in the hope that it will be useful,
 
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#  GNU General Public License for more details.
 
17
 
18
#  You should have received a copy of the GNU General Public License
 
19
#  along with this program; if not, write to the Free Software
 
20
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
21
#  USA
 
22
 
 
23
import os
 
24
import gettext
 
25
import ConfigParser
 
26
 
 
27
_ = gettext.gettext
 
28
 
 
29
class Suite:
 
30
    name = None
 
31
    description = None
 
32
    base_uri = None
 
33
    repository_type = None
 
34
    components = None
 
35
 
 
36
class Component:
 
37
    name = None
 
38
    description = None
 
39
    enabled = None
 
40
 
 
41
class DistInfo:
 
42
    def __init__(self, dist = None,
 
43
                 base_dir = "/usr/share/update-manager/dists"):
 
44
        self.metarelease_uri = ''
 
45
        self.suites = []
 
46
 
 
47
        if not dist:
 
48
            pipe = os.popen("lsb_release -i | cut -d : -f 2-")
 
49
            dist = pipe.read().strip()
 
50
            pipe.close()
 
51
            del pipe
 
52
 
 
53
        dist_fname = "%s/%s.info" % (base_dir, dist)
 
54
        dist_file = open (dist_fname)
 
55
        if not dist_file:
 
56
            return
 
57
        suite = None
 
58
        component = None
 
59
        for line in dist_file:
 
60
            tokens = line.split (':', 1)
 
61
            if len (tokens) < 2:
 
62
                continue
 
63
            field = tokens[0].strip ()
 
64
            value = tokens[1].strip ()
 
65
            if field == 'ChangelogURI':
 
66
                self.changelogs_uri = _(value)
 
67
            elif field == 'MetaReleaseURI':
 
68
                self.metarelease_uri = value
 
69
            elif field == 'Suite':
 
70
                if suite:
 
71
                    if component:
 
72
                        suite.components.append (component)
 
73
                        component = None
 
74
                    self.suites.append (suite)
 
75
                suite = Suite ()
 
76
                suite.name = value
 
77
                suite.components = []
 
78
            elif field == 'RepositoryType':
 
79
                suite.repository_type = value
 
80
            elif field == 'BaseURI':
 
81
                suite.base_uri = value
 
82
            elif field == 'Description':
 
83
                suite.description = _(value)
 
84
            elif field == 'Component':
 
85
                if component:
 
86
                    suite.components.append (component)
 
87
                component = Component ()
 
88
                component.name = value
 
89
            elif field == 'Enabled':
 
90
                component.enabled = bool(int(value))
 
91
            elif field == 'CompDescription':
 
92
                component.description = _(value)
 
93
        if suite:
 
94
            if component:
 
95
                suite.components.append (component)
 
96
                component = None
 
97
            self.suites.append (suite)
 
98
            suite = None
 
99
 
 
100
 
 
101
if __name__ == "__main__":
 
102
    d = DistInfo ("Debian", "../distribution-data")
 
103
    print d.changelogs_uri
 
104
    for suite in d.suites:
 
105
        print suite.name
 
106
        print suite.description
 
107
        print suite.base_uri
 
108
        for component in suite.components:
 
109
            print component.name
 
110
            print component.description
 
111
            print component.enabled