File: __init__.py

package info (click to toggle)
bootstrap-vz 0.9.11%2B20180121git-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,244 kB
  • sloc: python: 8,800; sh: 813; makefile: 16
file content (33 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (2)
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
from contextlib import contextmanager


def get_partitions():
    import re
    regexp = re.compile('^ *(?P<major>\d+) *(?P<minor>\d+) *(?P<num_blks>\d+) (?P<dev_name>\S+)$')
    matches = {}
    path = '/proc/partitions'
    with open(path) as partitions:
        next(partitions)
        next(partitions)
        for line in partitions:
            match = regexp.match(line)
            if match is None:
                raise RuntimeError('Unable to parse {line} in {path}'.format(line=line, path=path))
            matches[match.group('dev_name')] = match.groupdict()
    return matches


@contextmanager
def unmounted(volume):
    from bootstrapvz.base.fs.partitionmaps.none import NoPartitions

    p_map = volume.partition_map
    root_dir = p_map.root.mount_dir
    p_map.root.unmount()
    if not isinstance(p_map, NoPartitions):
        p_map.unmap(volume)
        yield
        p_map.map(volume)
    else:
        yield
    p_map.root.mount(destination=root_dir)