Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P2370
cmd.py
Active
Public
Actions
Authored by
•
mmodell
on Dec 3 2015, 5:05 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
Scap
Referenced Files
F3044857: cmd.py
Dec 3 2015, 5:05 PM
2015-12-03 17:05:54 (UTC+0)
Subscribers
None
# -*- 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'
,
'--'
)
Event Timeline
•
mmodell
edited the content of this paste.
(Show Details)
Dec 3 2015, 5:05 PM
2015-12-03 17:05:54 (UTC+0)
•
mmodell
changed the title of this paste from untitled to
cmd.py
.
•
mmodell
updated the paste's language from
autodetect
to
autodetect
.
•
mmodell
added a project:
Scap
.
daniel
mentioned this in
T117032: Create configuration for specifying units conversions
.
Jan 13 2016, 11:52 AM
2016-01-13 11:52:30 (UTC+0)
Smalyshev
mentioned this in
T150877: Unit conversion does not create psn:P2043 for Q531
.
Nov 16 2016, 5:30 PM
2016-11-16 17:30:07 (UTC+0)
daniel
mentioned this in
T171478: Explicitly track precision of unit conversion factory
.
Jul 24 2017, 2:12 PM
2017-07-24 14:12:23 (UTC+0)
matthiasmullie
mentioned this in
T244856: Prefer relevant unit suggestions over other entities for MediaInfo statements
.
Feb 11 2020, 2:18 PM
2020-02-11 14:18:16 (UTC+0)
Log In to Comment