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
7db2f9b0
Commit
7db2f9b0
authored
Jun 07, 2011
by
Keegi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
macro work (in progress)
parent
b636b316
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
36 deletions
+76
-36
pronsole.py
pronsole.py
+76
-36
No files found.
pronsole.py
View file @
7db2f9b0
...
...
@@ -39,9 +39,9 @@ class pronsole(cmd.Cmd):
self
.
bedtemps
=
{
"pla"
:
"60"
,
"abs"
:
"110"
,
"off"
:
"0"
}
self
.
percentdone
=
0
self
.
tempreadings
=
""
self
.
aliases
=
{}
self
.
macros
=
{}
self
.
processing_rc
=
False
self
.
lastport
=
(
None
,
None
)
self
.
macros
=
[]
def
scanserial
(
self
):
"""scan for available ports. return a list of device names."""
...
...
@@ -130,57 +130,96 @@ class pronsole(cmd.Cmd):
ls
=
l
.
lstrip
()
ws
=
l
[:
len
(
l
)
-
len
(
ls
)]
# just leading whitespace
if
len
(
ws
)
==
0
:
del
self
.
onecmd
# remove override
print
"Macro '"
+
self
.
cur_macro_name
+
"' defined"
print
self
.
cur_macro
# debug
print
"------------"
# debug
self
.
prompt
=
"PC>"
exec
self
.
cur_macro
if
self
.
cur_macro_name
not
in
self
.
macros
:
self
.
macros
.
append
(
self
.
cur_macro_name
)
#global macro
setattr
(
self
.
__class__
,
"do_"
+
self
.
cur_macro_name
,
lambda
self
,
largs
,
macro
=
macro
:
macro
(
self
,
largs
.
split
()))
setattr
(
self
.
__class__
,
"help_"
+
self
.
cur_macro_name
,
lambda
self
,
macro_name
=
self
.
cur_macro_name
:
self
.
subhelp_macro
(
macro_name
))
#del self.cur_macro
# pass the unprocessed line to regular command processor
self
.
end_macro
()
# pass the unprocessed line to regular command processor to not require empty line in .pronsolerc
return
self
.
onecmd
(
l
)
if
ls
.
startswith
(
'#'
):
return
if
ls
.
startswith
(
'!'
):
self
.
cur_macro
+=
ws
+
ls
[
1
:]
+
"
\n
"
# python mode
else
:
self
.
cur_macro
+=
ws
+
'self.onecmd("'
+
ls
+
'".format(args))
\n
'
# parametric command mode
self
.
cur_macro
+=
ws
+
'self.onecmd("'
+
ls
+
'".format(arg))
\n
'
# parametric command mode
self
.
cur_macro_def
+=
l
+
"
\n
"
def
do_macro
(
self
,
l
):
if
len
(
l
.
strip
())
==
0
:
self
.
print_topics
(
"User-defined macros"
,
self
.
macros
,
15
,
80
)
return
self
.
cur_macro_name
=
l
.
strip
()
if
self
.
cur_macro_name
.
lower
()
.
endswith
(
"/d"
):
self
.
cur_macro_name
=
self
.
cur_macro_name
.
split
()[
0
]
self
.
macros
.
remove
(
self
.
cur_macro_name
)
delattr
(
self
.
__class__
,
"do_"
+
self
.
cur_macro_name
)
delattr
(
self
.
__class__
,
"help_"
+
self
.
cur_macro_name
)
return
if
self
.
cur_macro_name
not
in
self
.
macros
and
hasattr
(
self
.
__class__
,
"do_"
+
self
.
cur_macro_name
):
print
"Name '"
+
self
.
cur_macro_name
+
"' is already being used by built-in command or alias"
return
print
"Enter macro using indented lines, end with empty line"
def
end_macro
(
self
):
if
self
.
__dict__
.
has_key
(
"onecmd"
):
del
self
.
onecmd
# remove override
if
not
self
.
processing_rc
:
print
"Macro '"
+
self
.
cur_macro_name
+
"' defined"
print
self
.
cur_macro
+
"------------"
# debug
self
.
prompt
=
"PC>"
if
self
.
cur_macro_def
==
""
:
print
"Empty macro - cancelled"
del
self
.
cur_macro
,
self
.
cur_macro_name
,
self
.
cur_macro_def
return
self
.
macros
[
self
.
cur_macro_name
]
=
self
.
cur_macro_def
exec
self
.
cur_macro
setattr
(
self
.
__class__
,
"do_"
+
self
.
cur_macro_name
,
lambda
self
,
largs
,
macro
=
macro
:
macro
(
self
,
*
largs
.
split
()))
setattr
(
self
.
__class__
,
"help_"
+
self
.
cur_macro_name
,
lambda
self
,
macro_name
=
self
.
cur_macro_name
:
self
.
subhelp_macro
(
macro_name
))
del
self
.
cur_macro
,
self
.
cur_macro_name
,
self
.
cur_macro_def
def
do_macro
(
self
,
args
):
if
args
.
strip
()
==
""
:
self
.
print_topics
(
"User-defined macros"
,
self
.
macros
.
keys
(),
15
,
80
)
return
arglist
=
args
.
split
(
None
,
1
)
macro_name
=
arglist
[
0
]
if
macro_name
not
in
self
.
macros
and
hasattr
(
self
.
__class__
,
"do_"
+
macro_name
):
print
"Name '"
+
macro_name
+
"' is being used by built-in command"
return
if
len
(
arglist
)
==
2
:
macro_def
=
arglist
[
1
]
if
macro_def
.
lower
()
==
"/d"
:
if
macro_name
in
self
.
macros
.
keys
():
delattr
(
self
.
__class__
,
"do_"
+
macro_name
)
del
self
.
macros
[
macro_name
]
print
"Macro '"
+
macro_name
+
"' removed"
else
:
print
"Macro '"
+
macro_name
+
"' is not defined"
return
if
macro_def
.
lower
()
==
"/s"
:
self
.
subhelp_macro
(
macro_name
)
return
self
.
cur_macro_def
=
macro_def
self
.
cur_macro_name
=
macro_name
if
macro_def
.
startswith
(
"!"
):
self
.
cur_macro
=
"def macro(self,*arg):
\n
"
+
macro_def
[
1
:]
+
"
\n
"
else
:
self
.
cur_macro
=
"def macro(self,*arg):
\n
self.onecmd('"
+
macro_def
+
"'.format(arg))
\n
"
self
.
end_macro
()
return
if
not
self
.
processing_rc
:
print
"Enter macro using indented lines, end with empty line"
self
.
cur_macro_name
=
macro_name
self
.
cur_macro_def
=
""
self
.
cur_macro
=
"def macro(self,*arg):
\n
"
self
.
onecmd
=
self
.
hook_macro
# override onecmd temporarily
self
.
cur_macro
=
"def macro(self,*args):
\n
"
self
.
prompt
=
"..>"
def
help_macro
(
self
):
print
"Define macro: macro <name>"
print
"Define single-line macro: macro <name> <definition>"
print
"Define multi-line macro: macro <name>"
print
"Enter macro definition in indented lines. Use {0} .. {N} to substitute macro arguments"
def
subhelp_macro
(
self
,
macro
):
print
"'"
+
macro
+
"' is an user-defined macro."
print
"Enter python code, prefixed with ! Use arg[0] .. arg[N] to substitute macro arguments"
print
"Delete macro: macro <name> /d"
print
"Show macro definition: macro <name> /s"
print
"'macro' without arguments displays list of defined macros"
def
subhelp_macro
(
self
,
macro_name
):
if
macro_name
in
self
.
macros
.
keys
():
macro_def
=
self
.
macros
[
macro_name
]
if
"
\n
"
in
macro_def
:
print
"Macro '"
+
macro_name
+
"' defined as:"
print
self
.
macros
[
macro_name
]
+
"----------------"
else
:
print
"Macro '"
+
macro_name
+
"' defined as: '"
+
macro_def
+
"'"
else
:
print
"Macro '"
+
macro_name
+
"' is not defined"
def
postloop
(
self
):
self
.
p
.
disconnect
()
cmd
.
Cmd
.
postloop
(
self
)
def
preloop
(
self
):
self
.
processing_rc
=
True
try
:
with
open
(
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
".pronsolerc"
))
as
rc
:
for
rc_cmd
in
rc
:
...
...
@@ -188,6 +227,7 @@ class pronsole(cmd.Cmd):
self
.
onecmd
(
rc_cmd
)
except
IOError
:
pass
self
.
processing_rc
=
False
print
"Welcome to the printer console! Type
\"
help
\"
for a list of available commands."
cmd
.
Cmd
.
preloop
(
self
)
...
...
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