File: aptpkg.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 (73 lines) | stat: -rw-r--r-- 2,447 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
"""
apt functions for for dmm.
"""

from command_runner import command_runner


def install(packages="", chroot=None, **kwargs):
    """
    Install APT packages.

    chroot - specify chroot to do this in, False for host.
    """
    if chroot:
        ecode, result = command_runner('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), shell=True)
    else:
        ecode, result = command_runner('LANG=C LANGUAGE=C LC_TYPE=C '
                                       'LC_MESSAGES=C LC_ALL=C '
                                       'DEBIAN_FRONTEND=noninteractive '
                                       'apt-get -y install %s' %
                                       (packages), shell=True,
                                        live_output=True)
    return ecode, result


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

    chroot - specify chroot to do this in, False for host.
    """
    if chroot:
        ecode, result = command_runner('chroot %s apt-get clean' % chroot)
    else:
        ecode, result = command_runner('apt-get clean')
    return ecode, result


def update(chroot=None):
    """
    Update APT archives.
    """
    if chroot:
        ecode, result = command_runner('chroot %s apt-get -q update'
                                       % (chroot), shell=True,
                                          live_output=True)
    else:
        ecode, result = command_runner('apt-get -q update',
                                       shell=True, live_output=True)
    return ecode, result


def download_only(chroot=None, packages="", **kwargs):
    """
    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:
            ecode, result = command_runner('chroot %s apt-get -d -y --reinstall install %s'
                      % (chroot, package))
        else:
            ecode, result = command_runner('apt-get -d -y --reinstall install %s' % (package))
    return ecode, result