Statistics
| Branch: | Tag: | Revision:

root / image_creator / os_type / __init__.py @ 0d5a999d

History | View | Annotate | Download (1.3 kB)

1
#!/usr/bin/env python
2

    
3
def add_prefix(target):
4
    def wrapper(self, *args):
5
        prefix = args[0]
6
        return map(lambda x: prefix + x, target(self, *args))
7
    return wrapper
8

    
9
class OSBase(object):
10
    def __init__(self, rootdev, ghandler):
11
        self.root = rootdev
12
        self.g = ghandler
13

    
14
    @add_prefix
15
    def ls(self, directory): return self.g.ls(directory)
16

    
17
    @add_prefix
18
    def find(self, directory): return self.g.find(directory)
19

    
20
    def get_metadata(self):
21
        meta = {}
22
        meta["OSFAMILY"] = self.g.inspect_get_type(self.root)
23
        meta["OS"] = self.g.inspect_get_distro(self.root)
24
        meta["description"] = self.g.inspect_get_product_name(self.root)
25

    
26
        return meta
27

    
28
    def mount_all(self):
29
        mps = g.inspect_get_mountpoints(self.root)
30
        # Sort the keys to mount the fs in a correct order.
31
        # / should be mounted befor /boot, etc
32
        def compare (a, b):
33
            if len(a[0]) > len(b[0]): return 1
34
            elif len(a[0]) == len(b[0]): return 0
35
            else: return -1
36
        mps.sort(compare)
37
        for mp, dev in mps:
38
            try:
39
                self.g.mount(dev, mp)
40
            except RuntimeError as msg:
41
                print "%s (ignored)" % msg
42

    
43
    def cleanup_sensitive_data(self):
44
        raise NotImplementedError
45

    
46
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :