Merge branch 'devel' into dev/commRefactoringNG

This commit is contained in:
Gina Häußge committed 2016-02-11 13:46:58 +01:00
commit 54bd41903b
5 files changed
+44 -61

No files matched your search

@@ -188,13 +188,12 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
octoprint=self._get_octoprint_version_string(),
pip=dict(
available=self._pip_caller.available,
command=self._pip_caller.command,
version=self._pip_caller.version_string,
install_dir=self._pip_caller.install_dir,
use_sudo=self._pip_caller.use_sudo,
use_user=self._pip_caller.use_user,
virtual_env=self._pip_caller.virtual_env,
additional_args=self._settings.get(["pip_args"])
additional_args=self._settings.get(["pip_args"]),
python=sys.executable
))
def on_api_command(self, command, data):
@@ -148,17 +148,13 @@ $(function() {
self.followDependencyLinks = ko.observable(false);
self.pipAvailable = ko.observable(false);
self.pipCommand = ko.observable();
self.pipVersion = ko.observable();
self.pipInstallDir = ko.observable();
self.pipUseUser = ko.observable();
self.pipUseSudo = ko.observable();
self.pipVirtualEnv = ko.observable();
self.pipAdditionalArgs = ko.observable();
self.pipPython = ko.observable();
self.pipUseSudoString = ko.pureComputed(function() {
return self.pipUseSudo() ? "yes" : "no";
});
self.pipUseUserString = ko.pureComputed(function() {
return self.pipUseUser() ? "yes" : "no";
});
@@ -305,19 +301,16 @@ $(function() {
self._fromPipResponse = function(data) {
self.pipAvailable(data.available);
if (data.available) {
self.pipCommand(data.command);
self.pipVersion(data.version);
self.pipInstallDir(data.install_dir);
self.pipUseUser(data.use_user);
self.pipUseSudo(data.use_sudo);
self.pipVirtualEnv(data.virtual_env);
self.pipAdditionalArgs(data.additional_args);
self.pipPython(data.python);
} else {
self.pipCommand(undefined);
self.pipVersion(undefined);
self.pipInstallDir(undefined);
self.pipUseUser(undefined);
self.pipUseSudo(undefined);
self.pipVirtualEnv(undefined);
self.pipAdditionalArgs(undefined);
}
@@ -13,19 +13,8 @@
{% endtrans %}</div>
{% endmacro %}
{% macro pluginmanager_sudopip() %}
<div class="alert alert-error" data-bind="visible: pipUseSudo()">{% trans %}
The <code>pip</code> command is configured to use <code>sudo</code>. This
is <strong>not</strong> recommended due to security reasons. It is <strong>strongly</strong>
suggested you install OctoPrint under a
<a href="https://github.com/foosel/OctoPrint/#installation">user-owned virtual environment</a>
so that the use of <code>sudo</code> is not needed for plugin management.
{% endtrans %}</div>
{% endmacro %}
{{ pluginmanager_printing() }}
{{ pluginmanager_nopip() }}
{{ pluginmanager_sudopip() }}
<div class="pull-right">
<button class="btn btn-small" data-bind="click: function() { $root.showPluginSettings(); }" title="{{ _('Plugin Configuration') }}"><i class="icon-wrench"></i></button>
@@ -76,13 +65,13 @@
<div>
<small>
<a href="#" class="muted" onclick="$(this).children('i.toggle-arrow').toggleClass('icon-caret-right icon-caret-down').parent().parent().parent().next().slideToggle('fast')">
<i class="toggle-arrow icon-caret-right"></i> Using pip at "<span data-bind="text: pipCommand"></span>", Version <span data-bind="text: pipVersion"></span>
<i class="toggle-arrow icon-caret-right"></i> Using pip of "<span data-bind="text: pipPython"></span>", Version <span data-bind="text: pipVersion"></span>
</a>
</small>
</div>
<div class="hide">
<small>
Installation directory: <span data-bind="text: pipInstallDir"></span> ("--user" flag: <span data-bind="text: pipUseUserString"></span>, sudo: <span data-bind="text: pipUseSudoString"></span>)<br />
Installation directory: <span data-bind="text: pipInstallDir"></span> ("--user" flag: <span data-bind="text: pipUseUserString"></span>)<br />
Virtual environment: <span data-bind="text: pipVirtualEnvString"></span><br />
<span data-bind="visible: pipAdditionalArgs">Additional Arguments: <span data-bind="text: pipAdditionalArgs"></span></span>
</small>
@@ -110,7 +99,6 @@
<div class="modal-body">
{{ pluginmanager_printing() }}
{{ pluginmanager_nopip() }}
{{ pluginmanager_sudopip() }}
<h4 style="position: relative">
{{ _('... from the <a href="%(url)s" target="_blank">Plugin Repository</a>', url='http://plugins.octoprint.org') }}
<div class="dropdown pull-right">
+21 -22
View File
@@ -84,35 +84,34 @@ class CommandlineCaller(object):
all_stderr = []
try:
while p.returncode is None:
line = p.stderr.readline(timeout=0.5)
if line:
line = self._preprocess_lines(line)
self._log_stderr(line)
all_stderr.append(line)
lines = p.stderr.readlines(timeout=0.5)
if lines:
lines = self._preprocess_lines(*lines)
self._log_stderr(*lines)
all_stderr += list(lines)
line = p.stdout.readline(timeout=0.5)
if line:
line = self._preprocess_lines(line)
self._log_stdout(line)
all_stdout.append(line)
lines = p.stdout.readlines(timeout=0.5)
if lines:
lines = self._preprocess_lines(*lines)
self._log_stdout(*lines)
all_stdout += list(lines)
p.commands[0].poll()
finally:
p.close()
stderr = p.stderr.text
if stderr:
split_lines = self._preprocess_lines(
stderr.split("\n"))
self._log_stderr(*split_lines)
all_stderr += split_lines
lines = p.stderr.readlines()
if lines:
lines = self._preprocess_lines(*lines)
self._log_stderr(*lines)
all_stderr += lines
stdout = p.stdout.text
if stdout:
split_lines = self._preprocess_lines(stdout.split("\n"))
self._log_stdout(*split_lines)
all_stdout += split_lines
lines = p.stdout.readlines()
if lines:
lines = self._preprocess_lines(*lines)
self._log_stdout(*lines)
all_stdout += lines
return p.returncode, all_stdout, all_stderr
@@ -122,5 +121,5 @@ class CommandlineCaller(object):
def _log_stderr(self, *lines):
self.on_log_stderr(*lines)
def _preprocess_lines(self, lines):
def _preprocess_lines(self, *lines):
return lines
+17 -13
View File
@@ -161,13 +161,9 @@ class PipCaller(CommandlineCaller):
if pip_command is None:
return
pip_command_str = pip_command
if isinstance(pip_command_str, list):
pip_command_str = " ".join(pip_command_str)
# Determine the pip version
self._logger.debug("Found pip at {}, going to figure out its version".format(pip_command_str))
self._logger.debug("Going to figure out pip's version")
pip_version, version_segment = self._get_pip_version(pip_command)
if pip_version is None:
@@ -177,7 +173,7 @@ class PipCaller(CommandlineCaller):
self._logger.error("This version of pip is known to have bugs that make it incompatible with how it needs to be used by OctoPrint. Please upgrade your pip version.")
return
self._logger.info("Version of pip \"{}\" is {}".format(pip_command_str, version_segment))
self._logger.info("Version of pip is {}".format(version_segment))
# Now figure out if pip belongs to a virtual environment and if the
# default installation directory is writable.
@@ -195,13 +191,12 @@ class PipCaller(CommandlineCaller):
ok, pip_user, pip_virtual_env, pip_install_dir = self._check_pip_setup(pip_command)
if not ok:
self._logger.error("Cannot use pip \"{}\"".format(pip_command_str))
self._logger.error("Cannot use pip")
return
self._logger.info("pip \"{}\" installs to {}, --user flag needed => {}, virtual env => {}".format(pip_command_str,
pip_install_dir,
"yes" if pip_user else "no",
"yes" if pip_virtual_env else "no"))
self._logger.info("pip installs to {}, --user flag needed => {}, virtual env => {}".format(pip_install_dir,
"yes" if pip_user else "no",
"yes" if pip_virtual_env else "no"))
self._command = pip_command
self._version = pip_version
@@ -227,7 +222,16 @@ class PipCaller(CommandlineCaller):
@classmethod
def autodetect_pip(cls):
return [sys.executable, "-m", "pip"]
commands = [[sys.executable, "-m", "pip"],
[sys.executable, "-c", "import sys; sys.argv = ['pip'] + sys.argv[1:]; import pip; pip.main()"]]
for command in commands:
p = sarge.run(command + ["--version"], stdout=sarge.Capture(), stderr=sarge.Capture())
if p.returncode == 0:
logging.getLogger(__name__).info("Using \"{}\" as command to invoke pip".format(" ".join(command)))
return command
return None
@classmethod
def to_sarge_command(cls, pip_command, *args):
@@ -363,7 +367,7 @@ class PipCaller(CommandlineCaller):
self._logger.debug("Could not detect desired output from testballoon install, got this instead: {!r}".format(data))
return False, False, False, None
def _preprocess_lines(self, lines):
def _preprocess_lines(self, *lines):
return map(self._preprocess, lines)
@staticmethod