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
511267b8
Commit
511267b8
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
modulare utils + add utils.apt module
parent
b8e86b45
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkgs_envsetup.py
+1
-0
1 addition, 0 deletions
pkgs_envsetup.py
utils/__init__.py
+0
-0
0 additions, 0 deletions
utils/__init__.py
utils/apt.py
+130
-0
130 additions, 0 deletions
utils/apt.py
with
131 additions
and
0 deletions
pkgs_envsetup.py
+
1
−
0
View file @
511267b8
...
...
@@ -4,6 +4,7 @@ from subprocess import run, DEVNULL, PIPE, STDOUT
PACKAGES
=
[
"
bsd-mailx
"
,
# for "mail" command used in tester
"
python3-apt
"
,
# for: test_apt
"
python3-defusedxml
"
,
# for: test_wowza
"
python3-dnspython
"
,
# for: test_caches
"
python3-openssl
"
,
# for: test_ssl
...
...
This diff is collapsed.
Click to expand it.
utils.py
→
utils
/__init__
.py
+
0
−
0
View file @
511267b8
File moved
This diff is collapsed.
Click to expand it.
utils/apt.py
0 → 100644
+
130
−
0
View file @
511267b8
#!/usr/bin/env python3
"""
A wrapper of apt module that is actually usable.
"""
import
utils
as
u
try
:
import
apt
import
apt_pkg
except
ModuleNotFoundError
:
u
.
warning
(
"
apt python module not found
"
)
exit
(
2
)
class
Apt
:
cache
:
apt
.
cache
.
Cache
packages
:
list
installed_packages
:
list
removable_packages
:
list
upgradable_packages
:
list
def
__init__
(
self
,
update
:
bool
=
False
):
self
.
cache
=
self
.
get_cache
(
update
)
self
.
packages
=
self
.
get_packages
()
self
.
installed_packages
=
self
.
get_installed_packages
()
self
.
removable_packages
=
self
.
get_removable_packages
()
self
.
upgradable_packages
=
self
.
get_upgradable_packages
()
def
install
(
self
,
name
:
str
)
->
bool
:
"""
Install a package with APT.
:param name: Package name
:type name: str
:return: Wether installation is successful or not
:rtype: bool
"""
pkg
=
self
.
cache
[
name
]
if
not
pkg
.
installed
:
pkg
.
mark_install
(
auto_fix
=
False
)
success
=
self
.
cache
.
commit
()
self
.
reload
()
return
success
def
remove
(
self
,
name
:
str
)
->
bool
:
"""
Remove a package with APT.
:param name: Package name
:type name: 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
()
self
.
reload
()
return
success
def
reload
(
self
):
"""
Reload object.
"""
self
.
cache
.
clear
()
self
.
__init__
()
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
:type update: bool
:return: An APT Cache object
:rtype: apt.cache.Cache
"""
apt_cache
=
apt
.
cache
.
Cache
()
if
update
:
apt_cache
.
update
()
apt_cache
.
open
()
return
apt_cache
def
get_packages
(
self
)
->
list
:
"""
Get packages list.
:return: Packages list
:rtype: list
"""
packages
=
list
(
self
.
cache
)
return
packages
def
get_installed_packages
(
self
)
->
list
:
"""
Get installed packages list.
:return: Installed packages list
:rtype: list
"""
installed_packages
=
[
p
for
p
in
self
.
packages
if
p
.
is_installed
]
return
installed_packages
def
get_removable_packages
(
self
)
->
list
:
"""
Get auto-removable packages list.
:return: Auto-removable packages list
:rtype: list
"""
removable_packages
=
[
p
for
p
in
self
.
installed_packages
if
p
.
is_auto_removable
]
return
removable_packages
def
get_upgradable_packages
(
self
)
->
list
:
"""
Get upgradable packages list.
:return: Upgradable packages list
:rtype: list
"""
upgradable_packages
=
[
p
for
p
in
self
.
installed_packages
if
p
.
is_upgradable
]
return
upgradable_packages
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