Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6faa8044
authored
Aug 19, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pretty-print function signatures
parent
56c3598c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
agent.py
+18
-6
No files found.
agent.py
View file @
6faa8044
...
...
@@ -15,12 +15,11 @@ import tarfile
from
os.path
import
expanduser
,
join
,
exists
from
os
import
mkdir
,
environ
from
glob
import
glob
from
inspect
import
getargspec
from
inspect
import
getargspec
,
isfunction
from
StringIO
import
StringIO
from
base64
import
decodestring
from
shutil
import
rmtree
,
move
from
datetime
import
datetime
from
types
import
FunctionType
from
utils
import
SerialLineReceiverBase
...
...
@@ -356,9 +355,9 @@ class SerialLineReceiver(SerialLineReceiverBase):
except
AttributeError
as
e
:
raise
AttributeError
(
u'Command not found:
%
s (
%
s)'
%
(
command
,
e
))
if
not
is
instance
(
func
,
FunctionType
):
if
not
is
function
(
func
):
raise
AttributeError
(
"Command refers to non-static method
%
s."
%
unicode
(
func
))
self
.
_pretty_fun
(
func
))
# check for unexpected keyword arguments
argspec
=
getargspec
(
func
)
...
...
@@ -367,7 +366,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
if
unexpected_kwargs
:
raise
TypeError
(
"Command
%
s got unexpected keyword arguments:
%
s"
%
(
unicode
(
func
),
", "
.
join
(
unexpected_kwargs
)))
self
.
_pretty_fun
(
func
),
", "
.
join
(
unexpected_kwargs
)))
mandatory_args
=
argspec
.
args
if
argspec
.
defaults
:
# remove those with default value
...
...
@@ -375,10 +374,23 @@ class SerialLineReceiver(SerialLineReceiverBase):
missing_kwargs
=
set
(
mandatory_args
)
-
set
(
args
)
if
missing_kwargs
:
raise
TypeError
(
"Command
%
s missing arguments:
%
s"
%
(
unicode
(
func
),
", "
.
join
(
missing_kwargs
)))
self
.
_pretty_fun
(
func
),
", "
.
join
(
missing_kwargs
)))
return
func
@staticmethod
def
_pretty_fun
(
fun
):
try
:
argspec
=
getargspec
(
fun
)
args
=
argspec
.
args
if
argspec
.
varargs
:
args
.
append
(
"*"
+
argspec
.
varargs
)
if
argspec
.
keywords
:
args
.
append
(
"**"
+
argspec
.
keywords
)
return
"
%
s(
%
s)"
%
(
fun
.
__name__
,
","
.
join
(
args
))
except
:
return
"<
%
s>"
%
type
(
fun
)
.
__name__
def
handle_command
(
self
,
command
,
args
):
func
=
self
.
_get_command
(
command
,
args
)
retval
=
func
(
**
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