Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ubuntu-kernel-cleanup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Massimiliano Adamo
ubuntu-kernel-cleanup
Commits
31b1271d
Unverified
Commit
31b1271d
authored
3 years ago
by
Max Adamo
Browse files
Options
Downloads
Patches
Plain Diff
use python apt instead of subprocess
parent
c73747e9
Branches
Branches containing commit
Tags
v0.6.1
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
README.txt
+1
-1
1 addition, 1 deletion
README.txt
ubuntu-kernel-cleanup.py
+9
-19
9 additions, 19 deletions
ubuntu-kernel-cleanup.py
with
11 additions
and
21 deletions
README.md
+
1
−
1
View file @
31b1271d
...
...
@@ -15,7 +15,7 @@ Purge unused Ubuntu kernels
### Setup
I
havent'
create
d
a release process yet.
I
did not
create a release process yet.
Meanwhile I use Git LFS to upload the package in the folder
[
deb/
](
https://gitlab.com/maxadamo/ubuntu-kernel-cleanup/-/tree/master/deb
)
directory.
...
...
This diff is collapsed.
Click to expand it.
README.txt
+
1
−
1
View file @
31b1271d
...
...
@@ -15,7 +15,7 @@ Table of Contents
Setup
I
havent’
create
d
a release process yet.
I
did not
create a release process yet.
Meanwhile I use Git LFS to upload the package in the folder deb/
directory.
...
...
This diff is collapsed.
Click to expand it.
ubuntu-kernel-cleanup.py
+
9
−
19
View file @
31b1271d
...
...
@@ -36,24 +36,15 @@ except ModuleNotFoundError as err:
def
get_packages_list
(
pkg_match
):
"""
run a shell command like this one:
dpkg --list linux-image-[1-9]* | awk
'
/^ii /&&/linux-image-/{print $2}
'
and create a sorted list of installed kernels.
Or if we need the version only it could be:
dpkg-query -f
'
${Status} ${Version}
\n
'
-W linux-image-[1-9]* | awk
'
/ok installed/{print $NF}
'
return a list of kernel package versions installed on the system
"""
installed
=
sp
.
Popen
(
"
dpkg --list %s[1-9]* | awk
\'
/^ii /&&/%s/{print $2}
\'
"
%
(
pkg_match
,
pkg_match
),
stdout
=
sp
.
PIPE
,
stderr
=
sp
.
PIPE
,
shell
=
True
)
installed_out
,
_
=
installed
.
communicate
()
installed_list
=
installed_out
.
decode
(
'
utf-8
'
).
split
(
'
\n
'
)
kernels
=
[
x
for
x
in
installed_list
if
x
!=
''
]
# delete empty items
kernel_versions
=
[
get_version
(
item
)
for
item
in
kernels
]
c_list
=
list
(
CACHE
)
c_list_names
=
[
element
.
name
for
element
in
c_list
if
CACHE
[
element
].
is_installed
]
c_list_installed
=
[
element
for
element
in
c_list_names
if
element
.
startswith
(
pkg_match
)
and
any
(
chr
.
isdigit
()
for
chr
in
element
)]
c_list_installed_versions
=
[
re
.
sub
(
r
"
(^\D+-|-\D+)
"
,
r
""
,
x
)
for
x
in
c_list_installed
]
# sort by version and unique
return
natsorted
(
list
(
set
(
kernel_versions
)))
return
natsorted
(
c_list_installed_versions
)
def
process_packages
(
version_number
,
prefix
,
execution_type
):
...
...
@@ -165,7 +156,6 @@ if __name__ == '__main__':
# we are running the latest kernel
sanitized_kernel_list
=
kern_list
del
kern_list
[
-
1
]
try
:
sanitized_kernel_list
except
NameError
:
...
...
@@ -180,9 +170,9 @@ if __name__ == '__main__':
for
kernel_version
in
purged_list
:
process_packages
(
kernel_version
,
kernel_pkg
,
EXECUTION
)
CACHE
.
close
()
# it returns always true... keeps closing :)
CACHE
.
close
()
# it returns always true... keeps closing
like swivel doors
:)
# purge empty packages
# purge empty packages
(it doesn't remove kernel but orphan packages without files)
if
EXECUTION
==
'
real
'
:
CMD
=
"
dpkg-query -f
\'
${Package} ${Status}
\\
n
\'
-W linux-* | awk
\'
/deinstall ok/{print $1}
\'
| xargs apt-get purge -y
"
# pylint: disable=C0301
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment