summaryrefslogtreecommitdiffstats
path: root/src/Types.py
blob: 3ec7a0469d265cd06ba7b1d204aa07b7a5199dba (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
#!/usr/bin/env python

from binascii import b2a_base64
from string import join

class ConfigFile(object):
    format="<ConfigFile name='%s' owner='%s' group='%s' perms='%s' encoding='%s'>%s</ConfigFile>"
    def __init__(self,name,owner,group,perms,content,encoding='ascii'):
        self.name=name
        self.owner=owner
        self.group=group
        self.perms=perms
        self.content=content
        self.encoding=encoding
        if encoding == 'base64':
            self.xcontent=b2a_base64(content)
        else:
            self.xcontent=self.content
        
    def toxml(self):
        return self.format%(self.name,self.owner,self.group,self.perms,self.encoding,self.xcontent)

class Service(object):
    format = '''<Service name='%s' type='%s' status='%s' scope='%s'/>'''

    def __init__(self,name,stype,status,scope):
        self.name = name
        self.type = stype
        self.status = status
        self.scope = scope

    def toxml(self):
        return self.format%(self.name,self.type,self.status,self.scope)

class Package(object):
    format = '''<Package name='%s' type='%s' url='%s'/>'''

    def __init__(self, name, t, url):
        self.name = name
        self.type = t
        self.url = url

    def toxml(self):
        return self.format%(self.name, self.type, self.url)

class Clause(list):
    format = '''<%s name='%s'>%%s</%s>'''
    
    def __init__(self, t, name, data=None):
        list.__init__(self)
        self.type = t
        self.name = name
        if data:
            self.extend(data)

    def toxml(self):
        r = self.format%(self.type,self.name,self.type)
        children = map(lambda x:x.toxml(), self)
        return r%(join(children,''))