Coverage for .tox/coverage/lib/python3.11/site-packages/wuttamess/apt.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-10 10:19 -0500

1# -*- coding: utf-8; -*- 

2################################################################################ 

3# 

4# WuttaMess -- Fabric Automation Helpers 

5# Copyright © 2024 Lance Edgar 

6# 

7# This file is part of Wutta Framework. 

8# 

9# Wutta Framework is free software: you can redistribute it and/or modify it 

10# under the terms of the GNU General Public License as published by the Free 

11# Software Foundation, either version 3 of the License, or (at your option) any 

12# later version. 

13# 

14# Wutta Framework is distributed in the hope that it will be useful, but 

15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 

17# more details. 

18# 

19# You should have received a copy of the GNU General Public License along with 

20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>. 

21# 

22################################################################################ 

23""" 

24APT package management 

25""" 

26 

27 

28def dist_upgrade(c, frontend='noninteractive'): 

29 """ 

30 Run a full dist-upgrade for APT. Essentially this runs: 

31 

32 .. code-block:: sh 

33 

34 apt update 

35 apt dist-upgrade 

36 """ 

37 update(c) 

38 upgrade(c, dist_upgrade=True, frontend=frontend) 

39 

40 

41def install(c, *packages, **kwargs): 

42 """ 

43 Install some package(s) via APT. Essentially this runs: 

44 

45 .. code-block:: sh 

46 

47 apt install PKG [PKG ...] 

48 """ 

49 frontend = kwargs.pop('frontend', 'noninteractive') 

50 packages = ' '.join(packages) 

51 return c.run(f'DEBIAN_FRONTEND={frontend} apt-get --assume-yes install {packages}') 

52 

53 

54def update(c): 

55 """ 

56 Update the APT package lists. Essentially this runs: 

57 

58 .. code-block:: sh 

59 

60 apt update 

61 """ 

62 c.run('apt-get update') 

63 

64 

65def upgrade(c, dist_upgrade=False, frontend='noninteractive'): 

66 """ 

67 Upgrade packages via APT. Essentially this runs: 

68 

69 .. code-block:: sh 

70 

71 apt upgrade 

72 

73 # ..or.. 

74 

75 apt dist-upgrade 

76 """ 

77 options = '' 

78 if frontend == 'noninteractive': 

79 options = '--option Dpkg::Options::="--force-confdef" --option Dpkg::Options::="--force-confold"' 

80 upgrade = 'dist-upgrade' if dist_upgrade else 'upgrade' 

81 c.run(f'DEBIAN_FRONTEND={frontend} apt-get --assume-yes {options} {upgrade}')