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 , logger ):
64
+ def _write_pending_upgrades (registry , cache , logger , cli_args ):
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 cli_args .exclude
66
69
}
67
70
for candidate in candidates :
68
71
logger .debug (
@@ -79,13 +82,14 @@ def _write_pending_upgrades(registry, cache, logger):
79
82
g .labels (change .labels ['origin' ], change .labels ['arch' ]).set (change .count )
80
83
81
84
82
- def _write_held_upgrades (registry , cache , logger ):
85
+ def _write_held_upgrades (registry , cache , logger , cli_args ):
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 cli_args .exclude
89
93
)
90
94
}
91
95
for candidate in held_candidates :
@@ -103,13 +107,14 @@ def _write_held_upgrades(registry, cache, logger):
103
107
g .labels (change .labels ['origin' ], change .labels ['arch' ]).set (change .count )
104
108
105
109
106
- def _write_obsolete_packages (registry , cache , logger ):
110
+ def _write_obsolete_packages (registry , cache , logger , cli_args ):
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 cli_args .exclude
113
118
)]
114
119
for package in obsoletes :
115
120
if package .candidate is None :
@@ -126,8 +131,12 @@ def _write_obsolete_packages(registry, cache, logger):
126
131
g .set (len (obsoletes ))
127
132
128
133
129
- def _write_autoremove_pending (registry , cache , logger ):
130
- autoremovable_packages = {p .candidate for p in cache if p .is_auto_removable }
134
+ def _write_autoremove_pending (registry , cache , logger , cli_args ):
135
+ autoremovable_packages = {
136
+ p .candidate
137
+ for p in cache
138
+ if p .is_auto_removable and p .name not in cli_args .exclude
139
+ }
131
140
for candidate in autoremovable_packages :
132
141
logger .debug (
133
142
"autoremovable package: %s / %s" ,
@@ -181,13 +190,17 @@ def _main():
181
190
if os .environ .get ("DEBUG" ):
182
191
logger .setLevel (logging .DEBUG )
183
192
193
+ parser = argparse .ArgumentParser ()
194
+ parser .add_argument ("--exclude" , nargs = '*' , default = [])
195
+ args = parser .parse_args (sys .argv [1 :])
196
+
184
197
cache = apt .cache .Cache ()
185
198
186
199
registry = CollectorRegistry ()
187
- _write_pending_upgrades (registry , cache , logger )
188
- _write_held_upgrades (registry , cache , logger )
189
- _write_obsolete_packages (registry , cache , logger )
190
- _write_autoremove_pending (registry , cache , logger )
200
+ _write_pending_upgrades (registry , cache , logger , args )
201
+ _write_held_upgrades (registry , cache , logger , args )
202
+ _write_obsolete_packages (registry , cache , logger , args )
203
+ _write_autoremove_pending (registry , cache , logger , args )
191
204
_write_installed_packages_per_origin (registry , cache )
192
205
_write_cache_timestamps (registry )
193
206
_write_reboot_required (registry )
0 commit comments