Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3044857
cmd.py
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
mmodell
Dec 3 2015, 5:05 PM
2015-12-03 17:05:54 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
cmd.py
View Options
# -*- coding: utf-8 -*-
"""
scap.env
~~~~~~~~~~~
command execution
"""
import
scap.config
as
config
class
Command
(
object
):
def
__init__
(
self
,
*
args
):
self
.
cmd
=
args
def
__call__
(
self
,
*
args
,
**
kwargs
):
return
" "
.
join
(
self
.
args
)
class
arg
(
Command
):
def
__init__
(
self
,
name
,
cmd
):
self
.
name
=
name
self
.
cmd
=
cmd
def
required
(
self
,
required
=
True
):
self
.
_required
=
required
return
self
def
__call__
(
self
,
**
values
):
if
self
.
name
in
values
and
values
[
self
.
name
]:
val
=
values
[
self
.
name
]
return
self
.
cmd
.
format
(
val
)
else
:
return
''
class
ComposableCommand
(
Command
):
def
__init__
(
self
,
*
cmds
):
self
.
cmds
=
cmds
def
__call__
(
self
,
*
args
,
**
values
):
result
=
[]
parts
=
self
.
cmds
+
args
for
cmd
in
parts
:
rendered
=
cmd
if
callable
(
cmd
):
rendered
=
cmd
(
**
values
)
if
rendered
:
if
type
(
rendered
)
is
str
:
result
.
append
(
rendered
)
else
:
result
.
extend
(
rendered
)
return
result
class
SubCommand
(
ComposableCommand
):
pass
env
=
config
.
Environment
()
SSH_USER
=
arg
(
'user'
,
'-oUser={}'
)
SUDO_USER
=
arg
(
'user'
,
'-u {}'
)
SSH
=
ComposableCommand
(
env
[
'ssh_command'
],
SSH_USER
)
SUDO
=
ComposableCommand
(
'sudo'
,
SUDO_USER
,
'-n'
,
'--'
)
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3054117
Default Alt Text
cmd.py (1 KB)
Attached To
Mode
P2370 cmd.py
Attached
Detach File
Event Timeline
Log In to Comment