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
8002d268
Commit
8002d268
authored
Oct 09, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factorize command running
parent
4e8c0188
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
13 deletions
+33
-13
printrun_utils.py
printrun/printrun_utils.py
+14
-0
pronsole.py
printrun/pronsole.py
+19
-13
No files found.
printrun/printrun_utils.py
View file @
8002d268
...
...
@@ -17,6 +17,8 @@ import os
import
sys
import
gettext
import
datetime
import
subprocess
import
shlex
# Set up Internationalization using gettext
# searching for installed locales on /usr/share; uses relative folder if not
...
...
@@ -84,6 +86,18 @@ def format_time(timestamp):
def
format_duration
(
delta
):
return
str
(
datetime
.
timedelta
(
seconds
=
int
(
delta
)))
def
run_command
(
command
,
replaces
=
None
,
stdout
=
subprocess
.
STDOUT
,
stderr
=
subprocess
.
STDOUT
,
blocking
=
False
):
command
=
shlex
.
split
(
command
.
replace
(
"
\\
"
,
"
\\\\
"
)
.
encode
())
if
replaces
is
not
None
:
replaces
[
"$python"
]
=
sys
.
executable
for
pattern
,
rep
in
replaces
.
items
():
command
=
[
bit
.
replace
(
pattern
,
rep
)
for
bit
in
command
]
command
=
[
bit
.
encode
()
for
bit
in
command
]
if
blocking
:
return
subprocess
.
call
(
command
)
else
:
return
subprocess
.
Popen
(
command
,
stderr
=
stderr
,
stdout
=
stdout
)
class
RemainingTimeEstimator
(
object
):
drift
=
None
...
...
printrun/pronsole.py
View file @
8002d268
...
...
@@ -22,13 +22,12 @@ import time
import
sys
import
subprocess
import
codecs
import
shlex
import
argparse
import
locale
import
logging
from
.
import
printcore
from
printrun.printrun_utils
import
install_locale
,
format_time
,
format_duration
from
printrun.printrun_utils
import
install_locale
,
format_time
,
format_duration
,
run_command
install_locale
(
'pronterface'
)
from
printrun
import
gcoder
...
...
@@ -1068,11 +1067,14 @@ class pronsole(cmd.Cmd):
self
.
p
.
runSmallScript
(
self
.
endScript
)
param
=
self
.
settings
.
final_command
if
not
param
:
command
=
self
.
settings
.
final_command
if
not
command
:
return
pararray
=
[
i
.
replace
(
"$s"
,
str
(
self
.
filename
))
.
replace
(
"$t"
,
format_duration
(
print_duration
))
.
encode
()
for
i
in
shlex
.
split
(
param
.
replace
(
"
\\
"
,
"
\\\\
"
)
.
encode
())]
self
.
finalp
=
subprocess
.
Popen
(
pararray
,
stderr
=
subprocess
.
STDOUT
,
stdout
=
subprocess
.
PIPE
)
self
.
finalp
=
run_command
(
command
,
{
"$s"
:
str
(
self
.
filename
),
"$t"
:
format_duration
(
print_duration
)},
stderr
=
subprocess
.
STDOUT
,
stdout
=
subprocess
.
PIPE
,
blocking
=
False
)
def
help_shell
(
self
):
self
.
log
(
"Executes a python command. Example:"
)
...
...
@@ -1414,14 +1416,18 @@ class pronsole(cmd.Cmd):
return
try
:
if
settings
:
param
=
self
.
expandcommand
(
self
.
settings
.
sliceoptscommand
)
.
replace
(
"
\\
"
,
"
\\\\
"
)
.
encode
()
self
.
log
(
_
(
"Entering slicer settings:
%
s"
)
%
param
)
subprocess
.
call
(
shlex
.
split
(
param
)
)
command
=
self
.
settings
.
sliceoptscommand
self
.
log
(
_
(
"Entering slicer settings:
%
s"
)
%
command
)
run_command
(
command
,
blocking
=
True
)
else
:
param
=
self
.
expandcommand
(
self
.
settings
.
slicecommand
)
.
encode
()
self
.
log
(
_
(
"Slicing: "
)
%
param
)
params
=
[
i
.
replace
(
"$s"
,
l
[
0
])
.
replace
(
"$o"
,
l
[
0
]
.
replace
(
".stl"
,
"_export.gcode"
)
.
replace
(
".STL"
,
"_export.gcode"
))
.
encode
()
for
i
in
shlex
.
split
(
param
.
replace
(
"
\\
"
,
"
\\\\
"
)
.
encode
())]
subprocess
.
call
(
params
)
command
=
self
.
settings
.
slicecommand
self
.
log
(
_
(
"Slicing: "
)
%
command
)
stl_name
=
l
[
0
]
gcode_name
=
stl_name
.
replace
(
".stl"
,
"_export.gcode"
)
.
replace
(
".STL"
,
"_export.gcode"
)
run_command
(
command
,
{
"$s"
:
stl_name
,
"$o"
:
gcode_name
},
blocking
=
True
)
self
.
log
(
_
(
"Loading sliced file."
))
self
.
do_load
(
l
[
0
]
.
replace
(
".stl"
,
"_export.gcode"
))
except
Exception
,
e
:
...
...
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