Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Jérome Perrin
slapos.core
Commits
697ced06
Commit
697ced06
authored
Sep 24, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapgrid: Refactor iterating over dir entries
parent
c76912d0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
64 deletions
+70
-64
slapos/grid/promise/__init__.py
slapos/grid/promise/__init__.py
+56
-59
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+2
-5
slapos/util.py
slapos/util.py
+12
-0
No files found.
slapos/grid/promise/__init__.py
View file @
697ced06
...
@@ -44,7 +44,7 @@ import hashlib
...
@@ -44,7 +44,7 @@ import hashlib
from
datetime
import
datetime
from
datetime
import
datetime
from
multiprocessing
import
Process
,
Queue
as
MQueue
from
multiprocessing
import
Process
,
Queue
as
MQueue
from
six.moves
import
queue
,
reload_module
from
six.moves
import
queue
,
reload_module
from
slapos.util
import
str2bytes
,
mkdir_p
,
chownDirectory
from
slapos.util
import
str2bytes
,
mkdir_p
,
chownDirectory
,
listifdir
from
slapos.grid.utils
import
dropPrivileges
,
killProcessTree
from
slapos.grid.utils
import
dropPrivileges
,
killProcessTree
from
slapos.grid.promise
import
interface
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
(
GenericPromise
,
PromiseQueueResult
,
from
slapos.grid.promise.generic
import
(
GenericPromise
,
PromiseQueueResult
,
...
@@ -731,10 +731,8 @@ class PromiseLauncher(object):
...
@@ -731,10 +731,8 @@ class PromiseLauncher(object):
error
=
0
error
=
0
success
=
0
success
=
0
promise_name_list
=
[]
promise_name_list
=
[]
if
os
.
path
.
exists
(
self
.
promise_folder
)
and
os
.
path
.
isdir
(
self
.
promise_folder
):
for
promise_name
in
listifdir
(
self
.
promise_folder
):
for
promise_name
in
os
.
listdir
(
self
.
promise_folder
):
if
promise_name
.
endswith
((
'.pyc'
,
'.pyo'
)):
for
suffix
in
[
'.pyc'
,
'.pyo'
]:
if
promise_name
.
endswith
(
suffix
):
promise_path
=
os
.
path
.
join
(
self
.
promise_folder
,
promise_name
)
promise_path
=
os
.
path
.
join
(
self
.
promise_folder
,
promise_name
)
if
not
os
.
path
.
exists
(
promise_path
[:
-
1
]):
if
not
os
.
path
.
exists
(
promise_path
[:
-
1
]):
try
:
try
:
...
@@ -816,10 +814,9 @@ class PromiseLauncher(object):
...
@@ -816,10 +814,9 @@ class PromiseLauncher(object):
if
key
not
in
promise_name_list
:
if
key
not
in
promise_name_list
:
new_state_dict
.
pop
(
key
,
None
)
new_state_dict
.
pop
(
key
,
None
)
if
not
self
.
run_only_promise_list
and
os
.
path
.
exists
(
self
.
legacy_promise_folder
)
\
if
not
self
.
run_only_promise_list
:
and
os
.
path
.
isdir
(
self
.
legacy_promise_folder
):
# run legacy promise styles
# run legacy promise styles
for
promise_name
in
os
.
list
dir
(
self
.
legacy_promise_folder
):
for
promise_name
in
listif
dir
(
self
.
legacy_promise_folder
):
promise_path
=
os
.
path
.
join
(
self
.
legacy_promise_folder
,
promise_name
)
promise_path
=
os
.
path
.
join
(
self
.
legacy_promise_folder
,
promise_name
)
if
not
os
.
path
.
isfile
(
promise_path
)
or
\
if
not
os
.
path
.
isfile
(
promise_path
)
or
\
not
os
.
access
(
promise_path
,
os
.
X_OK
):
not
os
.
access
(
promise_path
,
os
.
X_OK
):
...
...
slapos/grid/slapgrid.py
View file @
697ced06
...
@@ -55,7 +55,7 @@ from slapos import manager as slapmanager
...
@@ -55,7 +55,7 @@ from slapos import manager as slapmanager
from
slapos.slap.slap
import
NotFoundError
from
slapos.slap.slap
import
NotFoundError
from
slapos.slap.slap
import
ServerError
from
slapos.slap.slap
import
ServerError
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
from
slapos.util
import
mkdir_p
,
chownDirectory
,
string_to_boolean
from
slapos.util
import
mkdir_p
,
chownDirectory
,
string_to_boolean
,
listifdir
from
slapos.grid.exception
import
BuildoutFailedError
from
slapos.grid.exception
import
BuildoutFailedError
from
slapos.grid.SlapObject
import
Software
,
Partition
from
slapos.grid.SlapObject
import
Software
,
Partition
from
slapos.grid.svcbackend
import
(
launchSupervisord
,
from
slapos.grid.svcbackend
import
(
launchSupervisord
,
...
@@ -1596,10 +1596,7 @@ stderr_logfile_backups=1
...
@@ -1596,10 +1596,7 @@ stderr_logfile_backups=1
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition
.
getId
())
computer_partition
.
getId
())
report_path
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
)
report_path
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
)
if
os
.
path
.
isdir
(
report_path
):
script_list_to_run
=
listifdir
(
report_path
)
script_list_to_run
=
os
.
listdir
(
report_path
)
else
:
script_list_to_run
=
[]
# We now generate the pseudorandom name for the xml file
# We now generate the pseudorandom name for the xml file
# and we add it in the invocation_list
# and we add it in the invocation_list
...
...
slapos/util.py
View file @
697ced06
...
@@ -95,6 +95,18 @@ def mkdir_p(path, mode=0o700):
...
@@ -95,6 +95,18 @@ def mkdir_p(path, mode=0o700):
raise
raise
def
listifdir
(
path
):
"""
Like listdir, but returns an empty tuple if the path is not a directory.
"""
try
:
return
os
.
listdir
(
path
)
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
return
()
def
chownDirectory
(
path
,
uid
,
gid
):
def
chownDirectory
(
path
,
uid
,
gid
):
if
os
.
getuid
()
!=
0
:
if
os
.
getuid
()
!=
0
:
# we are probably inside of a webrunner
# we are probably inside of a webrunner
...
...
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