Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
mediaserver
envsetup
Commits
a7fcf27e
Commit
a7fcf27e
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
silent apt install
parent
aba671a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
tests/test_apt.py
+5
-0
5 additions, 0 deletions
tests/test_apt.py
utils_lib/apt.py
+48
-6
48 additions, 6 deletions
utils_lib/apt.py
with
54 additions
and
6 deletions
.gitignore
+
1
−
0
View file @
a7fcf27e
...
...
@@ -32,6 +32,7 @@ conf*.sh
auto-generated-conf.sh
log*.txt
tests/ms-testing-suite
*.log
# virtualenv
.venv/
...
...
This diff is collapsed.
Click to expand it.
tests/test_apt.py
+
5
−
0
View file @
a7fcf27e
...
...
@@ -51,6 +51,11 @@ def main():
else
:
u
.
success
(
"
system clean
"
)
# detect rc state
purgeable
=
len
(
apt
.
purgeable_packages
)
if
purgeable
:
u
.
info
(
"
there is {} packages in rc state
"
.
format
(
purgeable
))
# installation
try
:
installed
=
apt
.
install
(
"
sl
"
)
...
...
This diff is collapsed.
Click to expand it.
utils_lib/apt.py
+
48
−
6
View file @
a7fcf27e
...
...
@@ -15,6 +15,16 @@ except ModuleNotFoundError:
exit
(
2
)
class
AptInstallProgress
(
apt
.
progress
.
base
.
InstallProgress
):
def
fork
(
self
):
pid
=
os
.
fork
()
if
pid
==
0
:
logfd
=
os
.
open
(
"
/tmp/envsetup-dpkg.log
"
,
os
.
O_RDWR
|
os
.
O_CREAT
,
0o644
)
os
.
dup2
(
logfd
,
1
)
os
.
dup2
(
logfd
,
2
)
return
pid
class
Apt
:
# cache: apt.cache.Cache
# packages: list
...
...
@@ -22,18 +32,24 @@ class Apt:
# installed_packages: list
# _removable_packages: list
# removable_packages: list
# _purgeable_packages: list
# purgeable_packages: list
# _upgradable_packages: list
# upgradable_packages: list
def
__init__
(
self
,
update
:
bool
=
False
):
os
.
environ
[
"
DEBIAN_FRONTEND
"
]
=
"
noninteractive
"
os
.
environ
[
"
PATH
"
]
=
"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
"
os
.
environ
[
"
PATH
"
]
=
"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
"
self
.
cache
=
self
.
get_cache
(
update
)
self
.
packages
=
self
.
get_packages
()
self
.
_installed_packages
=
self
.
get_installed_packages
()
self
.
installed_packages
=
list
(
map
(
str
,
self
.
_installed_packages
))
self
.
_removable_packages
=
self
.
get_removable_packages
()
self
.
removable_packages
=
list
(
map
(
str
,
self
.
_removable_packages
))
self
.
_purgeable_packages
=
self
.
get_purgeable_packages
()
self
.
purgeable_packages
=
list
(
map
(
str
,
self
.
_purgeable_packages
))
self
.
_upgradable_packages
=
self
.
get_upgradable_packages
()
self
.
upgradable_packages
=
list
(
map
(
str
,
self
.
_upgradable_packages
))
...
...
@@ -49,7 +65,7 @@ class Apt:
pkg
=
self
.
cache
[
name
]
if
not
pkg
.
installed
:
pkg
.
mark_install
(
auto_fix
=
False
)
success
=
self
.
cache
.
commit
()
success
=
self
.
cache
.
commit
(
install_progress
=
AptInstallProgress
()
)
self
.
reload
()
return
success
...
...
@@ -68,23 +84,36 @@ class Apt:
return
False
def
remove
(
self
,
name
:
str
)
->
bool
:
def
remove
(
self
,
name
:
str
,
purge
:
bool
=
False
)
->
bool
:
"""
Remove a package with APT.
:param name: Package name
:type name: str
:param purge: Wether to purge package configuration files ot not, default=False
:type purge: str
:return: Wether uninstallation is successful or not
:rtype: bool
"""
pkg
=
self
.
cache
[
name
]
if
pkg
.
installed
:
pkg
.
mark_delete
(
auto_fix
=
False
)
success
=
self
.
cache
.
commit
()
pkg
.
mark_delete
(
auto_fix
=
False
,
purge
=
purge
)
success
=
self
.
cache
.
commit
(
install_progress
=
AptInstallProgress
()
)
self
.
reload
()
return
success
def
purge
(
self
,
name
:
str
)
->
bool
:
"""
Purge a package with APT.
:param name: Package name
:type name: str
:return: Wether uninstallation is successful or not
:rtype: bool
"""
return
self
.
remove
(
name
,
purge
=
True
)
def
reload
(
self
):
"""
Reload object.
"""
...
...
@@ -94,7 +123,7 @@ class Apt:
def
get_cache
(
self
,
update
:
bool
=
False
)
->
apt
.
cache
.
Cache
:
"""
Get an eventually updated Cache object.
:param update: Wether to update cacheor not, default=False
:param update: Wether to update cache
or not, default=False
:type update: bool
:return: An APT Cache object
:rtype: apt.cache.Cache
...
...
@@ -142,6 +171,19 @@ class Apt:
return
_removable_packages
def
get_purgeable_packages
(
self
)
->
list
:
"""
Get auto-removable packages list.
:return: Auto-removable packages list
:rtype: list
"""
_removable_packages
=
[
p
for
p
in
self
.
packages
if
not
p
.
is_installed
and
p
.
has_config_files
]
return
_removable_packages
def
get_upgradable_packages
(
self
)
->
list
:
"""
Get upgradable packages list.
...
...
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