Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
313a51f3
Commit
313a51f3
authored
Jun 16, 2013
by
D1plo1d
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding better error messages to prontserve
parent
871edba8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
16 deletions
+68
-16
prontserve.py
prontserve.py
+68
-16
No files found.
prontserve.py
View file @
313a51f3
...
@@ -204,18 +204,7 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
...
@@ -204,18 +204,7 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
self
.
write_message
(
args
)
self
.
write_message
(
args
)
def
on_message
(
self
,
msg
):
def
on_message
(
self
,
msg
):
cmds_whitelist
=
[
cmds
=
self
.
_cmds
()
"home"
,
"move"
,
"stop_move"
,
"set"
,
"estop"
,
"print"
,
"add_job"
,
"rm_job"
,
"change_job"
,
"get_jobs"
]
print
"message received:
%
s"
%
(
msg
)
print
"message received:
%
s"
%
(
msg
)
msg
=
re
.
sub
(
r'\s+'
,
"
\
s"
,
msg
)
.
strip
()
msg
=
re
.
sub
(
r'\s+'
,
"
\
s"
,
msg
)
.
strip
()
...
@@ -237,9 +226,12 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
...
@@ -237,9 +226,12 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
else
:
else
:
args
.
append
(
w
)
args
.
append
(
w
)
if
cmd
in
cmds
_whitelist
:
if
cmd
in
cmds
.
keys
()
:
try
:
try
:
self
.
_throwArgErrors
(
cmd
,
args
,
kwargs
)
# Set is already used by pronsole so we use construct_set
if
cmd
==
"set"
:
cmd
=
"construct_set"
if
cmd
==
"set"
:
cmd
=
"construct_set"
# Run the command
response
=
getattr
(
prontserve
,
"do_
%
s"
%
cmd
)(
*
args
,
**
kwargs
)
response
=
getattr
(
prontserve
,
"do_
%
s"
%
cmd
)(
*
args
,
**
kwargs
)
self
.
write_message
({
"ack"
:
response
})
self
.
write_message
({
"ack"
:
response
})
except
Exception
as
ex
:
except
Exception
as
ex
:
...
@@ -248,6 +240,58 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
...
@@ -248,6 +240,58 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
else
:
else
:
self
.
write_message
({
"error"
:
"
%
s command does not exist."
%
cmd
})
self
.
write_message
({
"error"
:
"
%
s command does not exist."
%
cmd
})
def
_cmds
(
self
):
return
{
"home"
:
{
'array_args'
:
True
,
'args_error'
:
"Home only (optionally) accepts axe names."
},
"move"
:
{
'named_args'
:
True
,
'args_error'
:
textwrap
.
dedent
(
"""
Move only takes a list of axes, distance pairs and optionally @
prefixed feedrates.
"""
)
.
strip
()
},
"set"
:
{
'namespaced'
:
True
,
# namespaced by the machine aspect (temp)
'named_args'
:
True
,
'args_error'
:
textwrap
.
dedent
(
"""
Set only accepts a namespace and a list of heater, value pairs.
"""
)
.
strip
()
},
"estop"
:
{
'args_error'
:
"Estop does not accept any parameters."
},
"print"
:
{
'args_error'
:
"Print does not accept any parameters."
},
"rm_job"
:
{
'namespaced'
:
True
,
# namespaced by the job id
'args_error'
:
"Rm_job only accepts a job_id."
},
"change_job"
:
{
'namespaced'
:
True
,
# namespaced by the job id
'named_args'
:
True
,
'args_error'
:
textwrap
.
dedent
(
"""
Change_job only accepts a job_id and a list of key/value pairs.
"""
)
.
strip
()
},
"get_jobs"
:
{
'args_error'
:
"Get_jobs does not accept any parameters."
}
}
def
_throwArgErrors
(
self
,
cmd
,
args
,
kwargs
):
meta
=
self
.
_cmds
()[
cmd
]
arg_errors
=
(
len
(
kwargs
)
>
0
and
not
'named_args'
in
meta
)
arg_errors
=
arg_errors
or
(
len
(
args
)
==
0
and
'namespaced'
in
meta
)
minArgs
=
0
if
'namespaced'
in
meta
:
minArgs
=
1
arg_errors
=
arg_errors
or
(
len
(
args
)
>
minArgs
and
not
'array_args'
in
meta
)
if
arg_errors
:
raise
Exception
(
meta
[
'args_error'
])
def
on_close
(
self
):
def
on_close
(
self
):
self
.
clients
.
remove
(
self
)
self
.
clients
.
remove
(
self
)
prontserve
.
listeners
.
remove
(
self
)
prontserve
.
listeners
.
remove
(
self
)
...
@@ -372,7 +416,10 @@ class Prontserve(pronsole.pronsole, EventEmitter):
...
@@ -372,7 +416,10 @@ class Prontserve(pronsole.pronsole, EventEmitter):
self
.
fire
(
"estop"
)
self
.
fire
(
"estop"
)
def
do_construct_set
(
self
,
subCmd
,
**
kwargs
):
def
do_construct_set
(
self
,
subCmd
,
**
kwargs
):
getattr
(
self
,
"do_set_
%
s"
%
subCmd
)(
**
kwargs
)
method
=
"do_set_
%
s"
%
subCmd
if
not
hasattr
(
self
,
method
):
raise
Exception
(
"
%
s is not a real namespace"
%
subCmd
)
getattr
(
self
,
method
)(
**
kwargs
)
def
do_set_temp
(
self
,
**
kwargs
):
def
do_set_temp
(
self
,
**
kwargs
):
# Setting each temperature individually
# Setting each temperature individually
...
@@ -399,7 +446,12 @@ class Prontserve(pronsole.pronsole, EventEmitter):
...
@@ -399,7 +446,12 @@ class Prontserve(pronsole.pronsole, EventEmitter):
def
do_change_job
(
self
,
job_id
,
**
kwargs
):
def
do_change_job
(
self
,
job_id
,
**
kwargs
):
print
job_id
print
job_id
print
kwargs
print
kwargs
self
.
jobs
.
update
(
int
(
job_id
),
kwargs
)
try
:
job_id
=
int
(
job_id
)
except
:
raise
Exception
(
"job_id must be a number"
)
self
.
jobs
.
update
(
job_id
,
kwargs
)
def
do_get_jobs
(
self
):
def
do_get_jobs
(
self
):
jobexport
=
[]
jobexport
=
[]
...
@@ -569,7 +621,7 @@ class PrintJobQueue(EventEmitter):
...
@@ -569,7 +621,7 @@ class PrintJobQueue(EventEmitter):
def
update
(
self
,
job_id
,
job_attrs
):
def
update
(
self
,
job_id
,
job_attrs
):
job
=
self
.
find_by_id
(
job_id
)
job
=
self
.
find_by_id
(
job_id
)
if
job
==
None
:
if
job
==
None
:
r
eturn
False
r
aise
Exception
(
"There is no job #
%
i."
%
job_id
)
# proposed future print quantity functionality
# proposed future print quantity functionality
# if hasattr(job_attrs, 'qty'): job['qty'] = qty
# if hasattr(job_attrs, 'qty'): job['qty'] = qty
if
job_attrs
[
'position'
]:
if
job_attrs
[
'position'
]:
...
...
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