24
24
25
25
import apt
26
26
import apt_pkg
27
+ import argparse
27
28
import collections
28
29
import logging
29
30
import os
@@ -60,9 +61,11 @@ def _convert_candidates_to_upgrade_infos(candidates):
60
61
return changes_list
61
62
62
63
63
- def _write_pending_upgrades (registry , cache ):
64
+ def _write_pending_upgrades (registry , cache , exclusions ):
64
65
candidates = {
65
- p .candidate for p in cache if p .is_upgradable and not p .phasing_applied
66
+ p .candidate
67
+ for p in cache
68
+ if p .is_upgradable and not p .phasing_applied and p .name not in exclusions
66
69
}
67
70
for candidate in candidates :
68
71
logging .debug (
@@ -79,13 +82,14 @@ def _write_pending_upgrades(registry, cache):
79
82
g .labels (change .labels ['origin' ], change .labels ['arch' ]).set (change .count )
80
83
81
84
82
- def _write_held_upgrades (registry , cache ):
85
+ def _write_held_upgrades (registry , cache , exclusions ):
83
86
held_candidates = {
84
87
p .candidate for p in cache
85
88
if (
86
89
p .is_upgradable
87
90
and p ._pkg .selected_state == apt_pkg .SELSTATE_HOLD
88
91
and not p .phasing_applied
92
+ and p .name not in exclusions
89
93
)
90
94
}
91
95
for candidate in held_candidates :
@@ -103,13 +107,14 @@ def _write_held_upgrades(registry, cache):
103
107
g .labels (change .labels ['origin' ], change .labels ['arch' ]).set (change .count )
104
108
105
109
106
- def _write_obsolete_packages (registry , cache ):
110
+ def _write_obsolete_packages (registry , cache , exclusions ):
107
111
# This corresponds to the apt filter "?obsolete"
108
112
obsoletes = [p for p in cache if p .is_installed and (
109
113
p .candidate is None or
110
114
not p .candidate .origins or
111
115
(len (p .candidate .origins ) == 1 and
112
116
p .candidate .origins [0 ].origin in ['' , "/var/lib/dpkg/status" ])
117
+ and p .name not in exclusions
113
118
)]
114
119
for package in obsoletes :
115
120
if package .candidate is None :
@@ -126,9 +131,11 @@ def _write_obsolete_packages(registry, cache):
126
131
g .set (len (obsoletes ))
127
132
128
133
129
- def _write_autoremove_pending (registry , cache ):
134
+ def _write_autoremove_pending (registry , cache , exclusions ):
130
135
autoremovable_packages = {
131
- p .candidate for p in cache if p .is_auto_removable
136
+ p .candidate
137
+ for p in cache
138
+ if p .is_auto_removable and p .name not in exclusions
132
139
}
133
140
for candidate in autoremovable_packages :
134
141
logging .debug (
@@ -181,13 +188,17 @@ def _main():
181
188
if os .getenv ('DEBUG' ):
182
189
logging .basicConfig (level = logging .DEBUG )
183
190
191
+ parser = argparse .ArgumentParser ()
192
+ parser .add_argument ("--exclude" , nargs = '*' , default = [])
193
+ args = parser .parse_args (sys .argv [1 :])
194
+
184
195
cache = apt .cache .Cache ()
185
196
186
197
registry = CollectorRegistry ()
187
- _write_pending_upgrades (registry , cache )
188
- _write_held_upgrades (registry , cache )
189
- _write_obsolete_packages (registry , cache )
190
- _write_autoremove_pending (registry , cache )
198
+ _write_pending_upgrades (registry , cache , args . exclude )
199
+ _write_held_upgrades (registry , cache , args . exclude )
200
+ _write_obsolete_packages (registry , cache , args . exclude )
201
+ _write_autoremove_pending (registry , cache , args . exclude )
191
202
_write_installed_packages_per_origin (registry , cache )
192
203
_write_cache_timestamps (registry )
193
204
_write_reboot_required (registry )
0 commit comments