File: sbuild.py

package info (click to toggle)
python3-dmm 0.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: python: 441; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 2,427 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
sbuild functions for for dmm.
"""

import os
import subprocess

def install(chroot, packages):
    """
    Install APT packages.

    chroot - specify chroot to do this in, False for host.
    """
    if chroot:
        result = os.system('LANG=C LANGUAGE=C LC_TYPE=C LC_MESSAGES=C '
                           'LC_ALL=C DEBIAN_FRONTEND=noninteractive '
                           'chroot %s apt-get -y install %s'
                           % (chroot,  packages))
        return result
    else:
        result = os.system('LANG=C LANGUAGE=C LC_TYPE=C LC_MESSAGES=C '
                           'LC_ALL=C DEBIAN_FRONTEND=noninteractive '
                           'apt-get -y install %s' % (packages))
        return result


def clean(chroot):
    """
    Clean apt archives.

    chroot - specify chroot to do this in, False for host.
    """
    if chroot:
        os.system('chroot %s apt-get clean' % chroot)
    else:
        os.system('apt-get clean')


def update(chroot):
    """
    Update APT archives.
    """
    if chroot:
        os.system('chroot %s apt-get -q update' % (chroot))
    else:
        os.system('apt-get -q update')


def download_only(chroot, packages):
    """
    Download packages for apt cache.
    For download-only, we do this one package at a time, since it's possible
    that some packages might conflict, and you might want to ship conflicting
    files on media.

    chroot - specify chroot to do this in, False for host.
    """
    for package in packages.split():
        if chroot:
            os.system('chroot %s apt-get -d -y --reinstall install %s'
                      % (chroot, package))
        else:
            os.system('apt-get -d -y --reinstall install %s' % (package))


def recipe_run(config, globalconf):
    """
    Perform actions for apt module
    """
    if config['action'] == 'install':
        if config['download_only']:
            # The use case for download only is mostly for cases like live
            # media preperation where we want to set up a package pool for
            # the media
            download_only(globalconf['chroot'], config['packages'])
        else:
            install(config['chroot'], config['packages'])

    elif config['update-sources']:
        update(globalconf['chroot'])

    if config['action'] == 'clean':
        clean(globalconf['chroot'])
    if config['clean_cache']:
        clean(globalconf['chroot'])