plainbox:session:storage: add windows support

This patch extends the generic save/load methods to handle windows on
python3.3 or newer. Windows-specific code is similar to the existing
python3.2 code (where we don't use the *at() family of functions) with
the notable difference of using binary mode and using os.replace()
instead of os.rename() which annoyingly enough doesn't allow us to
replace an existing file (but os.replace() does)

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:session:storage: improve save/load code

This patch applies some improvements made in the Windows-specific
version of the code to Unix variants of those methods.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:ctrl: make POSIX-specific imports optional

This patch makes plainbox.impl.ctrl importable on windows that lacks the
posix and grp modules. It still doesn't all us to use any of the
execution controllers on Windows but at least moves towards that option.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:ctrl: allow os.symlink() to fail on Windows

This patch allows Windows to vocally ignore all os.symlink() calls that
make up the construction of the execution environment (aka symlink
nest). This is not a good solution but it allows jobs that don't need
custom commands to work okay.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:ctrl: add support for user jobs on Windows

This patch adds support for running simple shell jobs on Windows.
Running as another user is not supported. Only jobs that advertise
windows support (by having the win32 flag set) can be started on
Windows.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:runner: add hacky windows support

This patch adds a pretty hacky windows support. It should be cleaned up
once all the execution controllers come from the device object and never
have to be guessed by all the code around.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:runner: fail gracefully on windows

This patch changes the JobRunner to fail gracefully by returning the
OUTCOME_NOT_SUPPORTED result when none of the execution controllers is
capable of running the requested job.

This change affects a private method that is unfortunately called by two
other places, the oldcli module in checkbox-ng (deprecated, will be
removed soon) and the script command that should be soon rewritten on
top of SessionManager alone. None of those places handle LookupError
that can be raised when the current device cannot execute a given job.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:commands:run: allow SessionPeekHelper.peek() to fail

This patch fixes a possible crash in 'plainbox run' that might happen if
the session data is corrupted in a way that would cause problems for the
peek machinery. This can happen if the gzip stream is damaged, for
example.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:providers:stubbox: add win.pxu

This patch adds a windows-specific unit file which defines a simple
"pass" style shell job that is suitable for running on Windows.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:device: fix _discover_windows()

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:device: fix sys.platform checks for linux2

This patch fixes python3.2 support that returns 'linux2' for
sys.platform.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>