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
...
@@ -35,6 +35,7 @@ import os
import
pwd
import
pwd
import
grp
import
grp
import
subprocess
import
subprocess
import
sys
from
collections
import
defaultdict
from
collections
import
defaultdict
from
netifaces
import
AF_INET
,
AF_INET6
from
netifaces
import
AF_INET
,
AF_INET6
...
@@ -351,6 +352,7 @@ class Partition(object):
...
@@ -351,6 +352,7 @@ class Partition(object):
# XXX
# XXX
def
format
(
self
):
def
format
(
self
):
self
.
user
.
createUser
()
self
.
createPath
()
self
.
createPath
()
def
createPath
(
self
):
def
createPath
(
self
):
...
@@ -373,7 +375,7 @@ class User(object):
...
@@ -373,7 +375,7 @@ class User(object):
self
.
path
=
path
self
.
path
=
path
self
.
groups
=
groups
self
.
groups
=
groups
def
create
(
self
):
def
create
User
(
self
):
grpname
=
'grp_'
+
self
.
name
if
sys
.
platform
==
'cygwin'
else
self
.
name
grpname
=
'grp_'
+
self
.
name
if
sys
.
platform
==
'cygwin'
else
self
.
name
if
not
self
.
isGroupAvailable
(
grpname
):
if
not
self
.
isGroupAvailable
(
grpname
):
call
([
'groupadd'
,
grpname
])
call
([
'groupadd'
,
grpname
])
...
@@ -393,7 +395,7 @@ class User(object):
...
@@ -393,7 +395,7 @@ class User(object):
@
classmethod
@
classmethod
def
isGroupAvailable
(
cls
,
name
):
def
isGroupAvailable
(
cls
,
name
):
try
:
try
:
pwd
.
getgrnam
(
name
)
grp
.
getgrnam
(
name
)
return
True
return
True
except
KeyError
:
except
KeyError
:
return
False
return
False
...
@@ -426,22 +428,20 @@ def call(args, raise_on_error=True):
...
@@ -426,22 +428,20 @@ def call(args, raise_on_error=True):
# Wrapping, Tracing & Dry-running
# Wrapping, Tracing & Dry-running
class
WrappedModule
(
object
):
class
WrappedModule
(
object
):
def
__init__
(
self
,
conf
,
module
,
*
methods
):
def
__init__
(
self
,
conf
,
module
,
*
*
methods
):
self
.
_conf
=
conf
self
.
_conf
=
conf
self
.
_module
=
module
self
.
_module
=
module
add
=
self
.
_addWrapper
add
=
self
.
_addWrapper
for
method
in
methods
:
for
name
,
fake_result
in
methods
.
items
():
add
(
method
)
add
(
name
,
fake_result
)
add
(
method
)
add
(
method
)
add
(
method
)
def
_addWrapper
(
self
,
name
):
def
_addWrapper
(
self
,
name
,
fake_result
):
logger
=
self
.
_conf
.
logger
logger
=
self
.
_conf
.
logger
if
self
.
_conf
.
dry_run
:
if
self
.
_conf
.
dry_run
:
def
wrapper
(
*
args
,
**
kw
):
def
wrapper
(
*
args
,
**
kw
):
l
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
item
for
item
in
kw
.
items
()]
l
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
item
for
item
in
kw
.
items
()]
logger
.
debug
(
'%s(%s)'
%
(
name
,
', '
.
join
(
l
)))
logger
.
debug
(
'%s(%s)'
%
(
name
,
', '
.
join
(
l
)))
return
fake_result
else
:
else
:
def
wrapper
(
*
args
,
**
kw
):
def
wrapper
(
*
args
,
**
kw
):
l
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
item
for
item
in
kw
.
items
()]
l
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
item
for
item
in
kw
.
items
()]
...
@@ -463,8 +463,19 @@ class WrappedSystem(object):
...
@@ -463,8 +463,19 @@ class WrappedSystem(object):
def
__enter__
(
self
):
def
__enter__
(
self
):
global
call
,
os
,
pwd
global
call
,
os
,
pwd
conf
=
self
.
conf
conf
=
self
.
conf
os
=
WrappedModule
(
conf
,
os
,
'chmod'
,
'chown'
,
'makedirs'
,
'mkdir'
)
os
=
WrappedModule
(
pwd
=
WrappedModule
(
conf
,
pwd
,
'getpwnam'
)
# XXX return value of fake
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
:
if
conf
.
dry_run
:
def
dry_call
(
args
,
raise_on_error
=
True
):
def
dry_call
(
args
,
raise_on_error
=
True
):
conf
.
logger
.
debug
(
' '
.
join
(
args
))
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