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
Xavier Thompson
slapos.core
Commits
d8846274
Commit
d8846274
authored
Oct 27, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: WIP add wrappers
parent
3e5182fe
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
11 deletions
+22
-11
slapos/format.py
slapos/format.py
+22
-11
No files found.
slapos/format.py
View file @
d8846274
...
...
@@ -35,6 +35,7 @@ import os
import
pwd
import
grp
import
subprocess
import
sys
from
collections
import
defaultdict
from
netifaces
import
AF_INET
,
AF_INET6
...
...
@@ -351,6 +352,7 @@ class Partition(object):
# XXX
def
format
(
self
):
self
.
user
.
createUser
()
self
.
createPath
()
def
createPath
(
self
):
...
...
@@ -373,7 +375,7 @@ class User(object):
self
.
path
=
path
self
.
groups
=
groups
def
create
(
self
):
def
create
User
(
self
):
grpname
=
'grp_'
+
self
.
name
if
sys
.
platform
==
'cygwin'
else
self
.
name
if
not
self
.
isGroupAvailable
(
grpname
):
call
([
'groupadd'
,
grpname
])
...
...
@@ -393,7 +395,7 @@ class User(object):
@
classmethod
def
isGroupAvailable
(
cls
,
name
):
try
:
pwd
.
getgrnam
(
name
)
grp
.
getgrnam
(
name
)
return
True
except
KeyError
:
return
False
...
...
@@ -426,22 +428,20 @@ def call(args, raise_on_error=True):
# Wrapping, Tracing & Dry-running
class
WrappedModule
(
object
):
def
__init__
(
self
,
conf
,
module
,
*
methods
):
def
__init__
(
self
,
conf
,
module
,
*
*
methods
):
self
.
_conf
=
conf
self
.
_module
=
module
add
=
self
.
_addWrapper
for
method
in
methods
:
add
(
method
)
add
(
method
)
add
(
method
)
add
(
method
)
for
name
,
fake_result
in
methods
.
items
():
add
(
name
,
fake_result
)
def
_addWrapper
(
self
,
name
):
def
_addWrapper
(
self
,
name
,
fake_result
):
logger
=
self
.
_conf
.
logger
if
self
.
_conf
.
dry_run
:
def
wrapper
(
*
args
,
**
kw
):
l
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
item
for
item
in
kw
.
items
()]
logger
.
debug
(
'%s(%s)'
%
(
name
,
', '
.
join
(
l
)))
return
fake_result
else
:
def
wrapper
(
*
args
,
**
kw
):
l
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
item
for
item
in
kw
.
items
()]
...
...
@@ -463,8 +463,19 @@ class WrappedSystem(object):
def
__enter__
(
self
):
global
call
,
os
,
pwd
conf
=
self
.
conf
os
=
WrappedModule
(
conf
,
os
,
'chmod'
,
'chown'
,
'makedirs'
,
'mkdir'
)
pwd
=
WrappedModule
(
conf
,
pwd
,
'getpwnam'
)
# XXX return value of fake
os
=
WrappedModule
(
conf
,
os
,
chmod
=
None
,
chown
=
None
,
makedirs
=
None
,
mkdir
=
None
,
)
pwd
=
WrappedModule
(
conf
,
pwd
,
getpwnam
=
type
(
'fake_getpwnam'
,
(),
{
'pw_uid'
:
12345
,
'pw_gid'
:
54321
}),
)
if
conf
.
dry_run
:
def
dry_call
(
args
,
raise_on_error
=
True
):
conf
.
logger
.
debug
(
' '
.
join
(
args
))
...
...
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