Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
6f12aecb
Commit
6f12aecb
authored
Apr 24, 2019
by
Никита Ефремов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add package_updates module
parent
42f1321e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
3 deletions
+52
-3
main.conf
configs/settingsd/main.conf
+3
-0
fmod_package_updates.py
plugins/functions/fmod_package_updates.py
+39
-0
process.py
settingsd/tools/process.py
+10
-3
No files found.
configs/settingsd/main.conf
View file @
6f12aecb
...
...
@@ -27,3 +27,6 @@ enabled = yes
[
date_time
]
enabled
=
yes
[
package_updates
]
enabled
=
yes
plugins/functions/fmod_package_updates.py
0 → 100644
View file @
6f12aecb
import
os
import
re
from
settingsd
import
const
from
settingsd
import
config
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd.tools.process
import
execProcess
INTERFACE_NAME
=
"packageUpdates"
SERVICE_NAME
=
"package_updates"
APT_EXECUTABLE
=
"/usr/bin/apt"
PACKAGE_REGEX
=
re
.
compile
(
r'^(\S+)/\S+'
)
class
PackageUpdates
(
service
.
FunctionObject
)
:
@service.functionMethod
(
INTERFACE_NAME
,
in_signature
=
""
,
out_signature
=
"as"
)
def
get_available_updates
(
self
):
execProcess
([
APT_EXECUTABLE
,
'update'
])
raw_output
,
=
execProcess
([
APT_EXECUTABLE
,
'list'
,
'--upgradable'
])[:
1
]
return
self
.
_extract_upgradable_packages
(
raw_output
.
decode
(
'utf-8'
))
@service.functionMethod
(
INTERFACE_NAME
,
in_signature
=
""
,
out_signature
=
""
)
def
install_updates
(
self
):
execProcess
([
APT_EXECUTABLE
,
'upgrade'
,
'-y'
],
shell
=
True
,
inherit_env
=
True
)
def
_extract_upgradable_packages
(
self
,
apt_output
):
lines
=
apt_output
.
split
(
'
\n
'
)
matches
=
[
PACKAGE_REGEX
.
match
(
line
)
for
line
in
lines
]
return
[
m
[
1
]
for
m
in
matches
if
m
]
class
Service
(
service
.
Service
)
:
def
initService
(
self
):
shared
.
Functions
.
addSharedObject
(
SERVICE_NAME
,
PackageUpdates
(
SERVICE_NAME
,
self
))
@classmethod
def
serviceName
(
self
):
return
SERVICE_NAME
settingsd/tools/process.py
View file @
6f12aecb
# -*- coding: utf-8 -*-
import
subprocess
from
os
import
environ
from
..
import
const
from
..
import
config
...
...
@@ -13,12 +14,19 @@ class SubprocessFailure(Exception) :
##### Public methods #####
def
execProcess
(
proc_args_list
,
proc_input
=
None
,
fatal_flag
=
True
,
confidential_input_flag
=
False
)
:
def
execProcess
(
proc_args_list
,
proc_input
=
None
,
fatal_flag
=
True
,
confidential_input_flag
=
False
,
inherit_env
=
False
,
shell
=
False
)
:
if
shell
and
not
isinstance
(
proc_args_list
,
str
):
proc_args_list
=
' '
.
join
(
proc_args_list
)
logger
.
debug
(
"{submod}: Executing child process
\"
%
s
\"
"
%
(
str
(
proc_args_list
)))
env
=
{
"LC_ALL"
:
"C"
}
if
inherit_env
:
env
=
{
**
environ
,
**
env
}
proc
=
subprocess
.
Popen
(
proc_args_list
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
}
)
env
=
env
,
shell
=
shell
)
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
(
proc_input
)
if
proc
.
returncode
!=
0
:
...
...
@@ -35,4 +43,3 @@ def execProcess(proc_args_list, proc_input = None, fatal_flag = True, confidenti
logger
.
debug
(
"{submod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
str
(
proc_args_list
),
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment