Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Justin
slapos.toolbox
Commits
cf048c64
Commit
cf048c64
authored
Feb 23, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add is-process-older-than-dependency-set script
parent
5004a8ec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
setup.py
setup.py
+1
-0
slapos/promise/is_process_older_than_dependency_set/__init__.py
.../promise/is_process_older_than_dependency_set/__init__.py
+57
-0
No files found.
setup.py
View file @
cf048c64
...
...
@@ -69,6 +69,7 @@ setup(name=name,
'equeue = slapos.equeue:main'
,
'htpasswd = slapos.htpasswd:main'
,
'is-local-tcp-port-opened = slapos.promise.is_local_tcp_port_opened:main'
,
'is-process-older-than-dependency-set = slapos.promise.is_process_older_than_dependency_set:main'
,
'killpidfromfile = slapos.systool:killpidfromfile'
,
# BBB
'runResiliencyUnitTestTestNode = slapos.resiliencytest:runUnitTest'
,
'runResiliencyScalabilityTestNode = slapos.resiliencytest:runResiliencyTest'
,
...
...
slapos/promise/is_process_older_than_dependency_set/__init__.py
0 → 100755
View file @
cf048c64
#!/usr/bin/env python
"""
Check if a process is running with an old version of the modules
found in the running python paths + optional additional python paths.
It parses all folders containing an `__init__.py` file and checks if
a file modification date is greater than the start date of the
process.
"""
import
sys
import
os
import
errno
import
psutil
ignored_extension_set
=
set
([
".pyc"
])
def
moduleIsModifiedSince
(
top
,
since
,
followlinks
=
False
):
for
root
,
dir_list
,
file_list
in
os
.
walk
(
top
,
followlinks
=
followlinks
):
if
root
==
top
:
continue
if
"__init__.py"
not
in
file_list
:
del
dir_list
[:]
continue
for
name
in
file_list
:
_
,
ext
=
os
.
path
.
splitext
(
name
)
if
ext
in
ignored_extension_set
:
continue
if
since
<
os
.
stat
(
os
.
path
.
join
(
root
,
name
)).
st_mtime
:
return
True
return
False
def
isProcessOlderThanDependencySet
(
pid
,
python_path_list
):
start_time
=
psutil
.
Process
(
pid
).
create_time
()
return
any
(
moduleIsModifiedSince
(
product_path
,
start_time
)
for
product_path
in
python_path_list
)
def
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
python_path_list
):
with
open
(
pid_file_path
,
"r"
)
as
f
:
pid
=
int
(
f
.
readline
())
return
isProcessOlderThanDependencySet
(
pid
,
python_path_list
)
def
main
():
pid_file_path
,
additional_python_path
=
sys
.
argv
[
1
],
sys
.
argv
[
2
:]
if
len
(
sys
.
argv
)
>
2
else
[]
try
:
if
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
sys
.
path
+
additional_python_path
):
return
1
return
0
except
(
OSError
,
IOError
)
as
err
:
if
err
.
errno
==
errno
.
ENOENT
:
return
0
raise
except
psutil
.
NoSuchProcess
:
return
0
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
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