Merge branch 'maintenance' into devel
This commit is contained in:
commit
8ba23e84ca
34 files changed
+3225
-1190
No files matched your search
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
if __name__ == "__main__":
|
||||
import octoprint
|
||||
octoprint.main()
|
||||
@@ -135,9 +135,10 @@ from .plugins import plugin_commands
|
||||
from .dev import dev_commands
|
||||
from .client import client_commands
|
||||
from .config import config_commands
|
||||
from .analysis import analysis_commands
|
||||
|
||||
@click.group(name="octoprint", invoke_without_command=True, cls=click.CommandCollection,
|
||||
sources=[server_commands, plugin_commands, dev_commands, client_commands, config_commands])
|
||||
sources=[server_commands, plugin_commands, dev_commands, client_commands, config_commands, analysis_commands])
|
||||
@standard_options()
|
||||
@legacy_options
|
||||
@click.version_option(version=octoprint.__version__, allow_from_autoenv=False)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import click
|
||||
|
||||
#~~ "octoprint util" commands
|
||||
|
||||
@click.group()
|
||||
def analysis_commands():
|
||||
pass
|
||||
|
||||
@analysis_commands.group(name="analysis")
|
||||
def util():
|
||||
"""Analysis tools."""
|
||||
pass
|
||||
|
||||
|
||||
@util.command(name="gcode")
|
||||
@click.option("--throttle", "throttle", type=float, default=None)
|
||||
@click.option("--throttle-lines", "throttle_lines", type=int, default=None)
|
||||
@click.option("--speed-x", "speedx", type=float, default=6000)
|
||||
@click.option("--speed-y", "speedy", type=float, default=6000)
|
||||
@click.option("--speed-z", "speedz", type=float, default=300)
|
||||
@click.option("--offset", "offset", type=(float, float), multiple=True)
|
||||
@click.option("--max-t", "maxt", type=int, default=10)
|
||||
@click.option("--g90-extruder", "g90_extruder", is_flag=True)
|
||||
@click.option("--progress", "progress", is_flag=True)
|
||||
@click.argument("path", type=click.Path())
|
||||
def gcode_command(path, speedx, speedy, speedz, offset, maxt, throttle, throttle_lines, g90_extruder, progress):
|
||||
"""Runs a GCODE file analysis."""
|
||||
|
||||
import time
|
||||
import yaml
|
||||
from octoprint.util.gcodeInterpreter import gcode
|
||||
|
||||
throttle_callback = None
|
||||
if throttle:
|
||||
def throttle_callback(filePos, readBytes):
|
||||
if filePos % throttle_lines == 0:
|
||||
# only apply throttle every $throttle_lines lines
|
||||
time.sleep(throttle)
|
||||
|
||||
offsets = offset
|
||||
if offsets is None:
|
||||
offsets = []
|
||||
elif isinstance(offset, tuple):
|
||||
offsets = list(offsets)
|
||||
offsets = [(0, 0)] + offsets
|
||||
if len(offsets) < maxt:
|
||||
offsets += [(0, 0)] * (maxt - len(offsets))
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
progress_callback = None
|
||||
if progress:
|
||||
def progress_callback(percentage):
|
||||
click.echo("PROGRESS:{}".format(percentage))
|
||||
interpreter = gcode(progress_callback=progress_callback)
|
||||
|
||||
interpreter.load(path,
|
||||
speedx=speedx,
|
||||
speedy=speedy,
|
||||
offsets=offsets,
|
||||
throttle=throttle_callback,
|
||||
max_extruders=maxt,
|
||||
g90_extruder=g90_extruder)
|
||||
|
||||
click.echo("DONE:{}s".format(time.time() - start_time))
|
||||
click.echo("RESULTS:")
|
||||
click.echo(yaml.safe_dump(interpreter.get_result(), default_flow_style=False, indent=" ", allow_unicode=True))
|
||||
@@ -324,8 +324,8 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue):
|
||||
speedy = self._current.printer_profile["axes"]["y"]["speed"]
|
||||
offsets = self._current.printer_profile["extruder"]["offsets"]
|
||||
|
||||
interpreter = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "util", "gcodeInterpreter.py"))
|
||||
command = [sys.executable, interpreter, "--speed-x={}".format(speedx), "--speed-y={}".format(speedy),
|
||||
command = [sys.executable, "-m", "octoprint", "analysis", "gcode",
|
||||
"--speed-x={}".format(speedx), "--speed-y={}".format(speedy),
|
||||
"--max-t={}".format(max_extruders), "--throttle={}".format(throttle),
|
||||
"--throttle-lines={}".format(throttle_lines)]
|
||||
for offset in offsets[1:]:
|
||||
|
||||
@@ -44,7 +44,11 @@ class CoreWizardPlugin(octoprint.plugin.AssetPlugin,
|
||||
if not name:
|
||||
continue
|
||||
|
||||
config = dict(type="wizard", name=name, template="corewizard_{}_wizard.jinja2".format(key), div="wizard_plugin_corewizard_{}".format(key))
|
||||
config = dict(type="wizard",
|
||||
name=name,
|
||||
template="corewizard_{}_wizard.jinja2".format(key),
|
||||
div="wizard_plugin_corewizard_{}".format(key),
|
||||
suffix="_{}".format(key))
|
||||
if key in additional:
|
||||
additional_result = additional[key]()
|
||||
if additional_result:
|
||||
|
||||
@@ -40,6 +40,13 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
octoprint.plugin.EventHandlerPlugin):
|
||||
|
||||
ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar")
|
||||
|
||||
# valid pip install URL schemes according to https://pip.pypa.io/en/stable/reference/pip_install/
|
||||
URL_SCHEMES = ("http", "https", "git",
|
||||
"git+http", "git+https", "git+ssh", "git+git",
|
||||
"hg+http", "hg+https", "hg+static-http", "hg+ssh",
|
||||
"svn", "svn+svn", "svn+http", "svn+https", "svn+ssh",
|
||||
"bzr+http", "bzr+https", "bzr+ssh", "bzr+sftp", "bzr+ftp", "bzr+lp")
|
||||
|
||||
OPERATING_SYSTEMS = dict(windows=["win32"],
|
||||
linux=lambda x: x.startswith("linux"),
|
||||
@@ -299,6 +306,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
|
||||
def command_install(self, url=None, path=None, force=False, reinstall=None, dependency_links=False):
|
||||
if url is not None:
|
||||
if not any(map(lambda scheme: url.starts_with(scheme + "://"), self.URL_SCHEMES)):
|
||||
raise ValueError("Invalid URL to pip install from")
|
||||
|
||||
source = url
|
||||
source_type = "url"
|
||||
already_installed_check = lambda line: url in line
|
||||
|
||||
@@ -239,23 +239,57 @@ $(function() {
|
||||
};
|
||||
|
||||
self.invalidUrl = ko.pureComputed(function() {
|
||||
// supported pip install URL schemes, according to https://pip.pypa.io/en/stable/reference/pip_install/
|
||||
var allowedUrlSchemes = ["http", "https",
|
||||
"git", "git+http", "git+https", "git+ssh", "git+git",
|
||||
"hg+http", "hg+https", "hg+static-http", "hg+ssh",
|
||||
"svn", "svn+svn", "svn+http", "svn+https", "svn+ssh",
|
||||
"bzr+http", "bzr+https", "bzr+ssh", "bzr+sftp", "brz+ftp", "bzr+lp"];
|
||||
|
||||
var url = self.installUrl();
|
||||
return url !== undefined && url.trim() != "" && !(_.startsWith(url.toLocaleLowerCase(), "http://") || _.startsWith(url.toLocaleLowerCase(), "https://"));
|
||||
var lowerUrl = url !== undefined ? url.toLocaleLowerCase() : undefined;
|
||||
|
||||
var lowerUrlStartsWithScheme = function(scheme) {
|
||||
return _.startsWith(lowerUrl, scheme + "://");
|
||||
};
|
||||
|
||||
return url !== undefined && url.trim() !== ""
|
||||
&& !(_.any(allowedUrlSchemes, lowerUrlStartsWithScheme));
|
||||
});
|
||||
|
||||
self.enableUrlInstall = ko.pureComputed(function() {
|
||||
var url = self.installUrl();
|
||||
return self.enableManagement() && self.pipAvailable() && !self.safeMode() && self.online() && url !== undefined && url.trim() != "" && !self.invalidUrl();
|
||||
return self.enableManagement()
|
||||
&& self.pipAvailable()
|
||||
&& !self.safeMode()
|
||||
&& self.online()
|
||||
&& url !== undefined
|
||||
&& url.trim() !== ""
|
||||
&& !self.invalidUrl();
|
||||
});
|
||||
|
||||
self.invalidArchive = ko.pureComputed(function() {
|
||||
var allowedArchiveExtensions = [".zip", ".tar.gz", ".tgz", ".tar"];
|
||||
|
||||
var name = self.uploadFilename();
|
||||
return name !== undefined && !(_.endsWith(name.toLocaleLowerCase(), ".zip") || _.endsWith(name.toLocaleLowerCase(), ".tar.gz") || _.endsWith(name.toLocaleLowerCase(), ".tgz") || _.endsWith(name.toLocaleLowerCase(), ".tar"));
|
||||
var lowerName = name !== undefined ? name.toLocaleLowerCase() : undefined;
|
||||
|
||||
var lowerNameHasExtension = function(extension) {
|
||||
return _.endsWith(lowerName, extension);
|
||||
};
|
||||
|
||||
return name !== undefined
|
||||
&& !(_.any(allowedArchiveExtensions, lowerNameHasExtension));
|
||||
});
|
||||
|
||||
self.enableArchiveInstall = ko.pureComputed(function() {
|
||||
var name = self.uploadFilename();
|
||||
return self.enableManagement() && self.pipAvailable() && !self.safeMode() && name !== undefined && name.trim() != "" && !self.invalidArchive();
|
||||
return self.enableManagement()
|
||||
&& self.pipAvailable()
|
||||
&& !self.safeMode()
|
||||
&& name !== undefined
|
||||
&& name.trim() !== ""
|
||||
&& !self.invalidArchive();
|
||||
});
|
||||
|
||||
self.uploadElement.fileupload({
|
||||
|
||||
@@ -197,7 +197,7 @@
|
||||
</div>
|
||||
<button class="btn btn-primary span3" data-bind="enable: enableUrlInstall, css: {disabled: !enableUrlInstall()}, click: function() { if (enableUrlInstall()) { $root.installPlugin(); } }">{{ _('Install') }}</button>
|
||||
</div>
|
||||
<span class="help-block" data-bind="visible: invalidUrl">{{ _('This does not look like a valid "http://" or "https://" URL.') }}</span>
|
||||
<span class="help-block" data-bind="visible: invalidUrl">{{ _('This does not look like a valid URL. Expected http, https or any of the <a href="%(url)s" target="_blank">supported VCS URLs</a>.', url='https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support') }}</span>
|
||||
</form>
|
||||
|
||||
<h4>{{ _('... from an uploaded archive') }}</h4>
|
||||
|
||||
@@ -958,7 +958,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
})
|
||||
callback.on_printer_send_initial_data(data)
|
||||
except:
|
||||
self._logger.exception("Error while trying to send inital state update")
|
||||
self._logger.exception("Error while trying to send initial state update")
|
||||
|
||||
def _getStateFlags(self):
|
||||
return {
|
||||
|
||||
@@ -476,9 +476,12 @@ class OctoPrintFlaskRequest(flask.Request):
|
||||
|
||||
We need this because cookies are not port-specific and we don't want to overwrite our
|
||||
session and other cookies from one OctoPrint instance on our machine with those of another
|
||||
one who happens to listen on the same address albeit a different port.
|
||||
one who happens to listen on the same address albeit a different port or script root.
|
||||
"""
|
||||
return "_P" + self.server_port
|
||||
result = "_P" + self.server_port
|
||||
if self.script_root:
|
||||
return result + "_R" + self.script_root.replace("/", "|")
|
||||
return result
|
||||
|
||||
|
||||
class OctoPrintFlaskResponse(flask.Response):
|
||||
@@ -1131,6 +1134,23 @@ def restricted_access(func):
|
||||
return decorated_view
|
||||
|
||||
|
||||
def firstrun_only_access(func):
|
||||
"""
|
||||
If you decorate a view with this, it will ensure that first setup has _not_ been
|
||||
done for OctoPrint's Access Control. Otherwise it
|
||||
will cause a HTTP 403 status code to be returned by the decorated resource.
|
||||
"""
|
||||
@functools.wraps(func)
|
||||
def decorated_view(*args, **kwargs):
|
||||
# if OctoPrint has been set up yet, abort
|
||||
if settings().getBoolean(["server", "firstRun"]) and (octoprint.server.userManager is None or not octoprint.server.userManager.hasBeenCustomized()):
|
||||
return func(*args, **kwargs)
|
||||
else:
|
||||
return flask.make_response("OctoPrint is already setup, this resource is not longer available.", 403)
|
||||
|
||||
return decorated_view
|
||||
|
||||
|
||||
class AppSessionManager(object):
|
||||
|
||||
VALIDITY_UNVERIFIED = 1 * 60 # 1 minute
|
||||
|
||||
@@ -461,13 +461,26 @@ def _process_templates():
|
||||
)
|
||||
|
||||
# sorting orders
|
||||
def wizard_key_extractor(d, k):
|
||||
if d[1].get("_key", None) == "plugin_corewizard_acl":
|
||||
# Ultra special case - we MUST always have the ACL wizard first since otherwise any steps that follow and
|
||||
# that require to access APIs to function will run into errors since those APIs won't work before ACL
|
||||
# has been configured. See also #2140
|
||||
return u"0:{}".format(to_unicode(d[0]))
|
||||
elif d[1].get("mandatory", False):
|
||||
# Other mandatory steps come before the optional ones
|
||||
return u"1:{}".format(to_unicode(d[0]))
|
||||
else:
|
||||
# Finally everything else
|
||||
return u"2:{}".format(to_unicode(d[0]))
|
||||
|
||||
template_sorting = dict(
|
||||
navbar=dict(add="prepend", key=None),
|
||||
sidebar=dict(add="append", key="name"),
|
||||
tab=dict(add="append", key="name"),
|
||||
settings=dict(add="custom_append", key="name", custom_add_entries=lambda missing: dict(section_plugins=(gettext("Plugins"), None)), custom_add_order=lambda missing: ["section_plugins"] + missing),
|
||||
usersettings=dict(add="append", key="name"),
|
||||
wizard=dict(add="append", key="name", key_extractor=lambda d, k: u"0:{}".format(to_unicode(d[0])) if "mandatory" in d[1] and d[1]["mandatory"] else u"1:{}".format(to_unicode(d[0]))),
|
||||
wizard=dict(add="append", key="name", key_extractor=wizard_key_extractor),
|
||||
about=dict(add="append", key="name"),
|
||||
generic=dict(add="append", key=None)
|
||||
)
|
||||
|
||||
@@ -125,7 +125,7 @@ $(function() {
|
||||
return exports;
|
||||
})();
|
||||
|
||||
log.debug("Browser enviroment:", OctoPrint.coreui.browser);
|
||||
log.debug("Browser environment:", OctoPrint.coreui.browser);
|
||||
|
||||
//~~ AJAX setup
|
||||
|
||||
@@ -180,7 +180,7 @@ $(function() {
|
||||
gettext("Printing"),
|
||||
gettext("Paused"),
|
||||
gettext("Closed"),
|
||||
gettext("Transfering file to SD")
|
||||
gettext("Transferring file to SD")
|
||||
];
|
||||
|
||||
//~~ Initialize PNotify
|
||||
@@ -340,7 +340,7 @@ $(function() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// we could resolve the depdendencies and the view model is not defined yet => add it, it's now fully processed
|
||||
// we could resolve the dependencies and the view model is not defined yet => add it, it's now fully processed
|
||||
var viewModelBindTargets = viewModel.elements;
|
||||
|
||||
if (additionalBindings.hasOwnProperty(viewModel.name)) {
|
||||
@@ -692,7 +692,7 @@ $(function() {
|
||||
* onServerConnect below takes care of the passive login. Only once that's completed it tells
|
||||
* our DataUpdater that it's ok to trigger any callbacks in view models. On the initial
|
||||
* server connect (during first initialization) we also trigger the settings fetch and
|
||||
* binding proceedure once that's done, but only then.
|
||||
* binding procedure once that's done, but only then.
|
||||
*
|
||||
* Or, as a fancy diagram: https://gist.githubusercontent.com/foosel/0cdc3a03cf5311804271f12e87293c0c/raw/abc84fdc3b13030d70961539d9c132ae39c32085/octoprint_web_startup.txt
|
||||
*/
|
||||
@@ -706,7 +706,7 @@ $(function() {
|
||||
// passive login request.
|
||||
//
|
||||
// This is to ensure that we have no concurrent requests triggered by socket events
|
||||
// overriding each other's session during app intialization
|
||||
// overriding each other's session during app initialization
|
||||
dataUpdater.initialized();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ $(function() {
|
||||
self.defaultProfile = undefined;
|
||||
|
||||
self.destinationFilename = ko.observable();
|
||||
self.gcodeFilename = self.destinationFilename; // TODO: for backwards compatiblity, mark deprecated ASAP
|
||||
self.gcodeFilename = self.destinationFilename; // TODO: for backwards compatibility, mark deprecated ASAP
|
||||
|
||||
self.title = ko.observable();
|
||||
self.slicer = ko.observable();
|
||||
|
||||
@@ -51,7 +51,7 @@ $(function() {
|
||||
if (commandSpec.async) {
|
||||
text = gettext("The command \"%(command)s\" executed successfully");
|
||||
} else {
|
||||
text = gettext("The command \"%(command)s\" was triggered asychronously");
|
||||
text = gettext("The command \"%(command)s\" was triggered asynchronously");
|
||||
}
|
||||
|
||||
new PNotify({
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<b class="caret"></b>
|
||||
</a>
|
||||
<div id="login_dropdown_loggedout" style="padding: 15px" class="dropdown-menu" data-bind="css: {hide: loginState.loggedIn(), 'dropdown-menu': !loginState.loggedIn()}">
|
||||
<form id="loginForm" data-bind="event: {'submit': loginState.prepareLogin }">
|
||||
<form id="loginForm" data-bind="event: {'submit': loginState.prepareLogin }" onsubmit="return false; // this gets overwritten on view model bind">
|
||||
<label for="login_user">{{ _('Username') }}</label>
|
||||
<input type="text" id="login_user" name="username" data-bind="valueWithInit: loginState.loginUser" placeholder="{{ _('Username') }}" autocapitalize="none" autocorrect="off">
|
||||
<label for="login_pass">{{ _('Password') }}</label>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<div class="hide">
|
||||
<p class="row-fluid">
|
||||
<button class="btn btn-primary btn-block" type="button" data-bind="click: fakeAck, enable: isOperational() && loginState.isUser()">{{ _("Fake Acknowledgement") }}</button>
|
||||
<small class="muted">{{ _("If acknowledgements (\"ok\"s) sent by the firmware get lost due to issues with the serial communication to your printer, OctoPrint's communication with it can become stuck. If that happens, this can help. Please be advised that such occurences hint at general communication issues with your printer which will probably negatively influence your printing results and which you should therefore try to resolve!") }}</small>
|
||||
<small class="muted">{{ _("If acknowledgements (\"ok\"s) sent by the firmware get lost due to issues with the serial communication to your printer, OctoPrint's communication with it can become stuck. If that happens, this can help. Please be advised that such occurrences hint at general communication issues with your printer which will probably negatively influence your printing results and which you should therefore try to resolve!") }}</small>
|
||||
</p>
|
||||
<p class="row-fluid">
|
||||
<button class="btn btn-danger span6" type="button" data-bind="toggle: forceFancyFunctionality">{{ _('Force fancy functionality') }}</button>
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -2,7 +2,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
"""
|
||||
This module bundles commonly used utility methods or helper classes that are used in multiple places withing
|
||||
This module bundles commonly used utility methods or helper classes that are used in multiple places within
|
||||
OctoPrint's source code.
|
||||
"""
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
@@ -581,7 +581,7 @@ class MachineCom(object):
|
||||
if state == self.STATE_CLOSED_WITH_ERROR:
|
||||
return "Offline: %s" % (self.getErrorString())
|
||||
if state == self.STATE_TRANSFERING_FILE:
|
||||
return "Transfering file to SD"
|
||||
return "Transferring file to SD"
|
||||
return "Unknown State (%d)" % (self._state)
|
||||
|
||||
def getErrorString(self):
|
||||
@@ -1130,6 +1130,7 @@ class MachineCom(object):
|
||||
|
||||
def _processTemperatures(self, line):
|
||||
current_tool = self._currentTool if self._currentTool is not None else 0
|
||||
current_tool_key = "T%d" % current_tool
|
||||
maxToolNum, parsedTemps = parse_temperature_line(line, current_tool)
|
||||
|
||||
for name, hook in self._temperature_hooks.items():
|
||||
@@ -1140,13 +1141,17 @@ class MachineCom(object):
|
||||
except:
|
||||
self._logger.exception("Error while processing temperatures in {}, skipping".format(name))
|
||||
|
||||
if "T0" in parsedTemps.keys():
|
||||
if current_tool_key in parsedTemps.keys():
|
||||
shared_nozzle = self._printerProfileManager.get_current_or_default()["extruder"]["sharedNozzle"]
|
||||
for n in range(maxToolNum + 1):
|
||||
tool = "T%d" % n
|
||||
if not tool in parsedTemps.keys():
|
||||
continue
|
||||
|
||||
actual, target = parsedTemps[tool]
|
||||
if not tool in parsedTemps:
|
||||
if shared_nozzle:
|
||||
actual, target = parsedTemps[current_tool_key]
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
actual, target = parsedTemps[tool]
|
||||
self.last_temperature.set_tool(n, actual=actual, target=target)
|
||||
|
||||
# bed temperature
|
||||
@@ -1964,7 +1969,7 @@ class MachineCom(object):
|
||||
#Also skip errors with the SD card
|
||||
pass
|
||||
elif 'unknown command' in lower_line:
|
||||
#Ignore unkown command errors, it could be a typo or some missing feature
|
||||
#Ignore unknown command errors, it could be a typo or some missing feature
|
||||
pass
|
||||
elif not self.isError():
|
||||
error_text = line[6:] if lower_line.startswith("error:") else line[2:]
|
||||
|
||||
@@ -512,85 +512,3 @@ def getCodeFloat(line, code):
|
||||
except:
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
import click
|
||||
import time
|
||||
import yaml
|
||||
import sys
|
||||
|
||||
@click.command()
|
||||
@click.option("--throttle", "throttle", type=float, default=None)
|
||||
@click.option("--throttle-lines", "throttle_lines", type=int, default=None)
|
||||
@click.option("--speed-x", "speedx", type=float, default=6000)
|
||||
@click.option("--speed-y", "speedy", type=float, default=6000)
|
||||
@click.option("--speed-z", "speedz", type=float, default=300)
|
||||
@click.option("--offset", "offset", type=(float, float), multiple=True)
|
||||
@click.option("--max-t", "maxt", type=int, default=10)
|
||||
@click.option("--g90-extruder", "g90_extruder", is_flag=True)
|
||||
@click.option("--progress", "progress", is_flag=True)
|
||||
@click.argument("path", type=click.Path())
|
||||
def main(path, speedx, speedy, speedz, offset, maxt, throttle, throttle_lines, g90_extruder, progress):
|
||||
throttle_callback = None
|
||||
if throttle:
|
||||
def throttle_callback(filePos, readBytes):
|
||||
if filePos % throttle_lines == 0:
|
||||
# only apply throttle every $throttle_lines lines
|
||||
time.sleep(throttle)
|
||||
|
||||
offsets = offset
|
||||
if offsets is None:
|
||||
offsets = []
|
||||
elif isinstance(offset, tuple):
|
||||
offsets = list(offsets)
|
||||
offsets = [(0, 0)] + offsets
|
||||
if len(offsets) < maxt:
|
||||
offsets += [(0, 0)] * (maxt - len(offsets))
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
progress_callback = None
|
||||
if progress:
|
||||
def progress_callback(percentage):
|
||||
print("PROGRESS:{}".format(percentage))
|
||||
interpreter = gcode(progress_callback=progress_callback)
|
||||
|
||||
interpreter.load(path,
|
||||
speedx=speedx,
|
||||
speedy=speedy,
|
||||
offsets=offsets,
|
||||
throttle=throttle_callback,
|
||||
max_extruders=maxt,
|
||||
g90_extruder=g90_extruder)
|
||||
|
||||
print("DONE:{}s".format(time.time() - start_time))
|
||||
print("RESULTS:")
|
||||
print(yaml.safe_dump(interpreter.get_result(), default_flow_style=False, indent=" ", allow_unicode=True))
|
||||
|
||||
# os args are gained differently on win32
|
||||
try:
|
||||
from click.utils import get_os_args
|
||||
args = get_os_args()
|
||||
except ImportError:
|
||||
# for whatever reason we are running an older Click version?
|
||||
args = sys.argv[1:]
|
||||
|
||||
if len(args) >= len(sys.argv):
|
||||
# Now some ugly preprocessing of our arguments starts. We have a somewhat difficult situation on our hands
|
||||
# here if we are running under Windows and want to be able to handle utf-8 command line parameters (think
|
||||
# plugin parameters such as names or something, e.g. for the "dev plugin:new" command) while at the same
|
||||
# time also supporting sys.argv rewriting for debuggers etc (e.g. PyCharm).
|
||||
#
|
||||
# So what we try to do here is solve this... Generally speaking, sys.argv and whatever Windows returns
|
||||
# for its CommandLineToArgvW win32 function should have the same length. If it doesn't however and
|
||||
# sys.argv is shorter than the win32 specific command line arguments, obviously stuff was cut off from
|
||||
# sys.argv which also needs to be cut off of the win32 command line arguments.
|
||||
#
|
||||
# So this is what we do here.
|
||||
|
||||
# -1 because first entry is the script that was called
|
||||
sys_args_length = len(sys.argv) - 1
|
||||
|
||||
# cut off stuff from the beginning
|
||||
args = args[-1 * sys_args_length:] if sys_args_length else []
|
||||
|
||||
main(args=args, prog_name="octoprint-gcode-analysis")
|
||||
@@ -164,7 +164,7 @@ class SocketClient(object):
|
||||
If no timeout is provided, the method will block until the connection could
|
||||
be re-established.
|
||||
|
||||
If disconnect is set to ``True`` will disconnect the socket explictly
|
||||
If disconnect is set to ``True`` will disconnect the socket explicitly
|
||||
first if it is currently connected.
|
||||
|
||||
Arguments:
|
||||
|
||||
Reference in new issue
Block a user