File: mount.py

package info (click to toggle)
mock 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,572 kB
  • ctags: 533
  • sloc: python: 4,816; sh: 429; ansic: 66; makefile: 47
file content (55 lines) | stat: -rw-r--r-- 1,880 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
# License: GPL2 or later see COPYING
# Written by Daniel Mach
# Copyright (C) 2011 Daniel Mach <dmach@redhat.com>


"""
# The mount plugin is enabled by default.
# To disable it, use following option:
config_opts['plugin_conf']['mount_enable'] = False


# To configure the mount plugin, for each mount point use following option:
config_opts['plugin_conf']['mount_opts']['dirs'].append(
    ("/dev/device", "/mount/path/in/chroot/", "vfstype", "mount_options"))

# A real life example:
config_opts['plugin_conf']['mount_opts']['dirs'].append(
    ("server.example.com:/exports/data", "/mnt/data", "nfs", "rw,hard,intr,nosuid,nodev,noatime,tcp"))
"""

from mockbuild.mounts import FileSystemMountPoint
from mockbuild.trace_decorator import traceLog
import mockbuild.util

requires_api_version = "1.1"


# plugin entry point
@traceLog()
def init(plugins, conf, buildroot):
    Mount(plugins, conf, buildroot)


class Mount(object):
    """mount dirs into chroot"""
    @traceLog()
    def __init__(self, plugins, conf, buildroot):
        self.buildroot = buildroot
        self.config = buildroot.config
        self.state = buildroot.state
        self.opts = conf
        plugins.add_hook("preinit", self._mountPreInitHook)
        for device, dest_dir, vfstype, mount_opts in self.opts['dirs']:
            buildroot.mounts.add(
                FileSystemMountPoint(buildroot.make_chroot_path(dest_dir),
                                     filetype=vfstype,
                                     device=device,
                                     options=mount_opts))

    @traceLog()
    def _mountPreInitHook(self):
        for device, dest_dir, vfstype, mount_opts in self.opts['dirs']:
            mockbuild.util.mkdirIfAbsent(self.buildroot.make_chroot_path(dest_dir))