Re: [PATCH 6/8] host side for barebox remote control

2016-01-18 Thread Jan Lübbe
On So, 2016-01-17 at 17:07 -0800, Andrey Smirnov wrote:
> >
> > Signed-off-by: Jan Lübbe 
> > Signed-off-by: Sascha Hauer 
> 
> With fixes above,
> 
> Tested-by: Andrey Smirnov 

These fixes look fine,

Acked-by: Jan Lübbe 
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 6/8] host side for barebox remote control

2016-01-17 Thread Andrey Smirnov
One more time sans HTML

On Fri, Jan 8, 2016 at 3:13 AM, Sascha Hauer  wrote:
> From: Jan Luebbe 
>
> This contains the host tool for barebox remote control. It is written in
> Phython with its own implementation of the RATP protocol. Currently this
> is a very simple tool which needs more work, but the code can also be
> used as a library.
>
> Example output:
>
> console: '.  '
> console: '.. '
> console: 'dev'
> console: 'env'
> console: 'mnt'
> console: '\n'
> Result: BBPacketCommandReturn(exit_code=0)



I have the following fix-ups for this patch:

-8<---

From 6c89443301b0064aa424501da242dc7dfd29f3bb Mon Sep 17 00:00:00 2001
From: Andrey Smirnov 
Date: Sun, 17 Jan 2016 15:58:03 -0800
Subject: [PATCH] fixup! host side for barebox remote control

remote needs to have __init__.py file in order to be valid python module

Signed-off-by: Andrey Smirnov 
---
 scripts/remote/__init__.py | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 scripts/remote/__init__.py

diff --git a/scripts/remote/__init__.py b/scripts/remote/__init__.py
new file mode 100644
index 000..e69de29
--
2.5.0

->8---

-8<---

From 61f5d56ea0ec9eb2bc87defb15751c51173ea003 Mon Sep 17 00:00:00 2001
From: Andrey Smirnov 
Date: Sun, 17 Jan 2016 16:54:41 -0800
Subject: [PATCH] fixup! host side for barebox remote control

Add a call to os.path.expanduser so that paths starting with '~' would
be handled correctly

Signed-off-by: Andrey Smirnov 
---
 scripts/remote/ratpfs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/remote/ratpfs.py b/scripts/remote/ratpfs.py
index 0333bf7..91ca044 100644
--- a/scripts/remote/ratpfs.py
+++ b/scripts/remote/ratpfs.py
@@ -59,7 +59,7 @@ class RatpFSServer(object):
 def __init__(self, path=None):
 self.path = path
 if path:
-self.path = os.path.abspath(path)
+self.path = os.path.abspath(os.path.expanduser(path))
 self.next_handle = 1  # 0 is invalid
 self.files = {}
 self.mounted = False
--
2.5.0

->8---

-8<---

From b7a202a5cb53bdc52eb54fcdf808919519467001 Mon Sep 17 00:00:00 2001
From: Andrey Smirnov 
Date: Sun, 17 Jan 2016 16:03:28 -0800
Subject: [PATCH] fixup! host side for barebox remote control

'event' variable is not really used anywhere

Signed-off-by: Andrey Smirnov 
---
 scripts/remote/main.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/scripts/remote/main.py b/scripts/remote/main.py
index 9350151..bd30472 100644
--- a/scripts/remote/main.py
+++ b/scripts/remote/main.py
@@ -95,8 +95,7 @@ def handle_console(args):
 cons.start()
 try:
 while True:
-event = queue.get(block=True)
-src, data = event
+src, data = queue.get(block=True)
 if src == cons:
 if data is None:  # shutdown
 cons.join()
--
2.5.0

->8---


>
> Signed-off-by: Jan Lübbe 
> Signed-off-by: Sascha Hauer 

With fixes above,

Tested-by: Andrey Smirnov 


> ---
>  scripts/bbremote  |   3 +
>  scripts/remote/controller.py  | 173 ++
>  scripts/remote/main.py| 169 +
>  scripts/remote/messages.py| 154 +
>  scripts/remote/missing.py |  28 ++
>  scripts/remote/ratp.py| 773 
> ++
>  scripts/remote/ratpfs.py  | 189 +++
>  scripts/remote/threadstdio.py |  47 +++
>  8 files changed, 1536 insertions(+)
>  create mode 100755 scripts/bbremote
>  create mode 100644 scripts/remote/controller.py
>  create mode 100644 scripts/remote/main.py
>  create mode 100644 scripts/remote/messages.py
>  create mode 100644 scripts/remote/missing.py
>  create mode 100644 scripts/remote/ratp.py
>  create mode 100644 scripts/remote/ratpfs.py
>  create mode 100644 scripts/remote/threadstdio.py
>
> diff --git a/scripts/bbremote b/scripts/bbremote
> new file mode 100755
> index 000..bc5351d
> --- /dev/null
> +++ b/scripts/bbremote
> @@ -0,0 +1,3 @@
> +#!/usr/bin/env python2
> +
> +import remote.main
> diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py
> new file mode 100644
> index 000..a7257ec
> --- /dev/null
> +++ b/scripts/remote/controller.py
> @@ -0,0 +1,173 @@
> +#!/usr/bin/env python2
> +# -*- coding: utf-8 -*-
> +
> +from __future__ import absolute_import, division, print_function
> +
> +import struct
> +import logging
> +import sys
> +import os
> +from threading import Thread
> +from Queue import Queue, Empty
> +from .ratpfs import RatpFSServer
> +from .messages import *
> +from .ratp import RatpError
> +
> +try:
> +from time import monotonic
> +except:
> +from .missing import monotonic
> +
> +
> +

[PATCH 6/8] host side for barebox remote control

2016-01-08 Thread Sascha Hauer
From: Jan Luebbe 

This contains the host tool for barebox remote control. It is written in
Phython with its own implementation of the RATP protocol. Currently this
is a very simple tool which needs more work, but the code can also be
used as a library.

Example output:

console: '.  '
console: '.. '
console: 'dev'
console: 'env'
console: 'mnt'
console: '\n'
Result: BBPacketCommandReturn(exit_code=0)

Signed-off-by: Jan Lübbe 
Signed-off-by: Sascha Hauer 
---
 scripts/bbremote  |   3 +
 scripts/remote/controller.py  | 173 ++
 scripts/remote/main.py| 169 +
 scripts/remote/messages.py| 154 +
 scripts/remote/missing.py |  28 ++
 scripts/remote/ratp.py| 773 ++
 scripts/remote/ratpfs.py  | 189 +++
 scripts/remote/threadstdio.py |  47 +++
 8 files changed, 1536 insertions(+)
 create mode 100755 scripts/bbremote
 create mode 100644 scripts/remote/controller.py
 create mode 100644 scripts/remote/main.py
 create mode 100644 scripts/remote/messages.py
 create mode 100644 scripts/remote/missing.py
 create mode 100644 scripts/remote/ratp.py
 create mode 100644 scripts/remote/ratpfs.py
 create mode 100644 scripts/remote/threadstdio.py

diff --git a/scripts/bbremote b/scripts/bbremote
new file mode 100755
index 000..bc5351d
--- /dev/null
+++ b/scripts/bbremote
@@ -0,0 +1,3 @@
+#!/usr/bin/env python2
+
+import remote.main
diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py
new file mode 100644
index 000..a7257ec
--- /dev/null
+++ b/scripts/remote/controller.py
@@ -0,0 +1,173 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, print_function
+
+import struct
+import logging
+import sys
+import os
+from threading import Thread
+from Queue import Queue, Empty
+from .ratpfs import RatpFSServer
+from .messages import *
+from .ratp import RatpError
+
+try:
+from time import monotonic
+except:
+from .missing import monotonic
+
+
+def unpack(data):
+p_type, = struct.unpack("!H", data[:2])
+logging.debug("unpack: %r data=%r", p_type, repr(data))
+if p_type == BBType.command:
+logging.debug("received: command")
+return BBPacketCommand(raw=data)
+elif p_type == BBType.command_return:
+logging.debug("received: command_return")
+return BBPacketCommandReturn(raw=data)
+elif p_type == BBType.consolemsg:
+logging.debug("received: consolemsg")
+return BBPacketConsoleMsg(raw=data)
+elif p_type == BBType.ping:
+logging.debug("received: ping")
+return BBPacketPing(raw=data)
+elif p_type == BBType.pong:
+logging.debug("received: pong")
+return BBPacketPong(raw=data)
+elif p_type == BBType.getenv_return:
+logging.debug("received: getenv_return")
+return BBPacketGetenvReturn(raw=data)
+elif p_type == BBType.fs:
+logging.debug("received: fs")
+return BBPacketFS(raw=data)
+elif p_type == BBType.fs_return:
+logging.debug("received: fs_return")
+return BBPacketFSReturn(raw=data)
+else:
+logging.debug("received: UNKNOWN")
+return BBPacket(raw=data)
+
+
+class Controller(Thread):
+def __init__(self, conn):
+Thread.__init__(self)
+self.daemon = True
+self.conn = conn
+self.fsserver = None
+self.rxq = None
+self.conn.connect(timeout=5.0)
+self._txq = Queue()
+self._stop = False
+self.fsserver = RatpFSServer()
+
+def _send(self, bbpkt):
+self.conn.send(bbpkt.pack())
+
+def _handle(self, bbpkt):
+if isinstance(bbpkt, BBPacketConsoleMsg):
+os.write(sys.stdout.fileno(), bbpkt.text)
+elif isinstance(bbpkt, BBPacketPong):
+print("pong",)
+elif isinstance(bbpkt, BBPacketFS):
+if self.fsserver != None:
+self._send(self.fsserver.handle(bbpkt))
+
+def _expect(self, bbtype, timeout=1.0):
+if timeout is not None:
+limit = monotonic()+timeout
+while timeout is None or limit > monotonic():
+pkt = self.conn.recv(0.1)
+if not pkt:
+continue
+bbpkt = unpack(pkt)
+if isinstance(bbpkt, bbtype):
+return bbpkt
+else:
+self._handle(bbpkt)
+
+def export(self, path):
+self.fsserver = RatpFSServer(path)
+
+def ping(self):
+self._send(BBPacketPing())
+r = self._expect(BBPacketPong)
+logging.info("Ping: %r", r)
+if not r:
+return 1
+else:
+print("pong")
+return 0
+
+def command(self, cmd):
+self._send(BBPacketCommand(cmd=cmd))
+r = self._expect(BBPacketCommandReturn, timeout=None)
+logging.info("Command: %r", r)
+return r.exit_code
+
+def geten