Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
74f80f56
Commit
74f80f56
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
add option --force-yes to handle asking when not interactive
parent
4536e275
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bin/cc-cli
+8
-1
8 additions, 1 deletion
bin/cc-cli
cccli/cli.py
+9
-10
9 additions, 10 deletions
cccli/cli.py
cccli/command.py
+2
-3
2 additions, 3 deletions
cccli/command.py
cccli/printer.py
+29
-8
29 additions, 8 deletions
cccli/printer.py
with
48 additions
and
22 deletions
bin/cc-cli
+
8
−
1
View file @
74f80f56
...
...
@@ -87,10 +87,15 @@ try:
dest
=
"
hsize
"
,
default
=
""
,
help
=
"
History max entry count
"
)
oparser
.
add_option
(
"
--force-yes
"
,
action
=
"
store_true
"
,
dest
=
"
forceyes
"
,
default
=
""
,
help
=
"
Answer yes to yes/no question
"
)
(
options
,
args
)
=
oparser
.
parse_args
()
# options handling
for
i
in
(
"
debug
"
,
"
login
"
,
"
server
"
,
"
port
"
,
"
timeout
"
,
"
history
"
,
"
hsize
"
):
for
i
in
(
"
debug
"
,
"
login
"
,
"
server
"
,
"
port
"
,
"
timeout
"
,
"
history
"
,
"
hsize
"
,
"
forceyes
"
):
if
hasattr
(
options
,
i
):
o
=
getattr
(
options
,
i
)
if
o
:
...
...
@@ -116,10 +121,12 @@ try:
raise
BadArgument
(
"
Invalid %s number
"
%
i
)
# check login
if
"
login
"
not
in
settings
:
printer
.
setinteractive
()
settings
[
"
login
"
]
=
printer
.
ask
(
"
Login:
"
)
# check password
if
"
pass
"
not
in
settings
:
printer
.
setinteractive
()
settings
[
"
pass
"
]
=
printer
.
getpass
(
"
Password:
"
)
# start cli
...
...
This diff is collapsed.
Click to expand it.
cccli/cli.py
+
9
−
10
View file @
74f80f56
...
...
@@ -21,14 +21,11 @@ from sjrpc.client import SimpleRpcClient
from
sjrpc.utils
import
RpcHandler
,
ConnectionProxy
,
pure
from
sjrpc.core.exceptions
import
*
class
Cli
(
object
):
def
__init__
(
self
,
settings
):
self
.
settings
=
settings
self
.
prompt
=
""
self
.
prompt
=
"
>
"
self
.
rpc
=
None
self
.
printer
=
None
self
.
alias
=
Alias
()
def
start
(
self
,
line
=
""
):
...
...
@@ -39,25 +36,27 @@ class Cli(object):
# set interactive mode
self
.
interactive
=
sys
.
stderr
.
isatty
()
and
sys
.
stdin
.
isatty
()
# start printer and load history
self
.
printer
=
Printer
(
self
.
interactive
)
self
.
printer
.
history
.
load
(
self
.
settings
.
get
(
"
history
"
,
""
))
self
.
printer
.
history
.
maxsize
(
self
.
settings
.
get
(
"
hsize
"
,
None
))
self
.
printer
=
Printer
(
self
.
interactive
,
self
.
settings
.
get
(
"
forceyes
"
,
False
),
historyfile
=
self
.
settings
.
get
(
"
history
"
,
""
),
historysize
=
self
.
settings
.
get
(
"
hsize
"
,
None
))
# load alias
self
.
alias
.
load
(
self
.
settings
.
get
(
"
alias
"
,
""
))
# print debug
self
.
printer
.
debug
(
"
Interactive: %s
"
%
self
.
interactive
)
self
.
printer
.
debug
(
"
Alias: %s
"
%
self
.
alias
)
self
.
printer
.
debug
(
"
Loaded history: %s
"
%
len
(
self
.
printer
.
history
))
#
C
onnecting
#
c
onnecting
self
.
_connect
()
# auth
entifications
# auth
self
.
_auth
()
#
P
arsing
#
p
arsing
self
.
_parse
()
# save history
self
.
printer
.
history
.
save
(
self
.
settings
.
get
(
"
history
"
,
""
))
def
_connect
(
self
):
'''
Connect to a cloud control server
'''
self
.
printer
.
debug
(
"
Connecting...
"
)
try
:
rpcc
=
SimpleRpcClient
.
from_addr
(
self
.
settings
[
"
server
"
],
...
...
This diff is collapsed.
Click to expand it.
cccli/command.py
+
2
−
3
View file @
74f80f56
...
...
@@ -193,14 +193,13 @@ class Command(object):
for
item
in
items
:
self
.
printer
.
out
(
"
%s
"
%
item
[
"
id
"
])
self
.
printer
.
out
(
"
Count: %s
"
%
len
(
items
))
if
self
.
printer
.
ask
(
"
Are you sure to %s? (yes/NO)
"
%
argv
[
0
])
!=
"
yes
"
:
if
self
.
printer
.
ask
(
"
Are you sure to %s? (yes/NO)
"
%
argv
[
0
]
,
"
yes
"
)
!=
"
yes
"
:
raise
cmdWarning
(
"
Aborted
"
)
if
len
(
items
)
>
5
:
if
self
.
printer
.
ask
(
"
You request is on more than 5 objets. Are you really sure to %s its? (Yes, I am)
"
%
argv
[
0
])
!=
"
Yes, I am
"
:
if
self
.
printer
.
ask
(
"
You request is on more than 5 objets. Are you really sure to %s its? (Yes, I am)
"
%
argv
[
0
]
,
"
Yes, I am
"
)
!=
"
Yes, I am
"
:
raise
cmdWarning
(
"
Aborted
"
)
self
.
cli
.
rpc
[
argv
[
0
]](
tql
)
def
cmd_start
(
self
,
argv
):
'''
Start objects
'''
self
.
_startstopsdestroypauseresume
(
argv
)
...
...
This diff is collapsed.
Click to expand it.
cccli/printer.py
+
29
−
8
View file @
74f80f56
...
...
@@ -10,6 +10,7 @@ import os
import
getpass
import
cccli
from
cccli.exception
import
*
color
=
{
# regular
...
...
@@ -42,17 +43,31 @@ color = {
class
Printer
(
object
):
'''
Print relative class
'''
def
__init__
(
self
,
interactive
=
False
):
def
__init__
(
self
,
interactive
=
False
,
forceyes
=
False
,
historyfile
=
None
,
historysize
=
None
):
self
.
readline
=
None
self
.
history
=
History
()
self
.
historyfile
=
historyfile
self
.
historysize
=
historysize
self
.
forceyes
=
forceyes
if
interactive
:
import
readline
self
.
readline
=
readline
self
.
history
=
History
(
self
.
readline
)
self
.
setinteractive
()
def
isinteractive
(
self
):
'''
Return if printer is in interactive mode
'''
return
self
.
readline
is
not
None
def
setinteractive
(
self
):
if
self
.
readline
is
not
None
:
return
import
readline
self
.
readline
=
readline
if
self
.
history
is
None
:
self
.
history
=
History
(
self
.
readline
)
else
:
self
.
history
.
readline
=
readline
self
.
history
.
load
(
self
.
historyfile
)
self
.
history
.
maxsize
(
self
.
historysize
)
def
out
(
self
,
message
,
fd
=
sys
.
stdout
,
nl
=
os
.
linesep
,
flush
=
True
):
'''
Print a message in fd ended by nl
'''
fd
.
write
(
"
%s%s
"
%
(
message
,
nl
))
...
...
@@ -98,20 +113,26 @@ class Printer(object):
def
getpass
(
self
,
prompt
):
'''
Ask for a password. No echo. Not in history
'''
if
self
.
readline
is
None
:
raise
cliError
(
"
Unable to ask a password in non-interactive mode
"
)
return
getpass
.
getpass
(
prompt
)
def
ask
(
self
,
prompt
):
def
ask
(
self
,
prompt
,
goodans
=
None
):
'''
Used to ask a question. Default answer not saved to history
'''
if
self
.
forceyes
and
goodans
is
not
None
:
return
goodans
if
self
.
readline
is
None
:
raise
cliError
(
"
Unable to ask question in non-interactive mode
"
)
return
self
.
getline
(
prompt
,
history
=
False
)
class
History
(
object
):
'''
History class
'''
def
__init__
(
self
,
readline
):
self
.
readline
=
readli
ne
def
__init__
(
self
):
self
.
readline
=
No
ne
def
__nonzero__
(
self
):
return
not
self
.
readline
is
None
return
self
.
readline
is
not
None
def
__getattribute__
(
self
,
name
):
r
=
object
.
__getattribute__
(
self
,
"
readline
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment