[CRIU] [PATCH 10/10] p.haul: move _fileobj_wrap to util.py
Nikita Spiridonov
nspiridonov at odin.com
Fri Oct 9 10:11:42 PDT 2015
Move _fileobj_wrap class to util.py and remove underscore from its
name.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
phaul/images.py | 22 ++--------------------
phaul/util.py | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/phaul/images.py b/phaul/images.py
index ed01031..11b3dbb 100644
--- a/phaul/images.py
+++ b/phaul/images.py
@@ -32,24 +32,6 @@ class opendir:
def fileno(self):
return self._dirfd
-class _fileobj_wrap:
- """Helper class provides read/write interface for socket object
-
- Current helper class wrap recv/send socket methods in read/write interface.
- This functionality needed to workaround some problems of socket.makefile
- method for sockets constructed from numerical file descriptors passed
- through command line arguments.
- """
-
- def __init__(self, sk):
- self.__sk = sk
-
- def read(self, size=0x10000):
- return self.__sk.recv(size)
-
- def write(self, str):
- self.__sk.send(str)
-
class untar_thread(threading.Thread):
def __init__(self, sk, tdir):
threading.Thread.__init__(self)
@@ -58,7 +40,7 @@ class untar_thread(threading.Thread):
def run(self):
try:
- tf = tarfile.open(mode="r|", fileobj=_fileobj_wrap(self.__sk))
+ tf = tarfile.open(mode="r|", fileobj=util.fileobj_wrap(self.__sk))
tf.extractall(self.__dir)
tf.close()
except:
@@ -66,7 +48,7 @@ class untar_thread(threading.Thread):
class img_tar:
def __init__(self, sk, dirname):
- self.__tf = tarfile.open(mode="w|", fileobj=_fileobj_wrap(sk))
+ self.__tf = tarfile.open(mode="w|", fileobj=util.fileobj_wrap(sk))
self.__dir = dirname
def add(self, img, path = None):
diff --git a/phaul/util.py b/phaul/util.py
index 1bfd6d1..2a66de4 100644
--- a/phaul/util.py
+++ b/phaul/util.py
@@ -3,6 +3,24 @@ import fcntl
import errno
import logging
+class fileobj_wrap:
+ """Helper class provides read/write interface for socket object
+
+ Current helper class wrap recv/send socket methods in read/write interface.
+ This functionality needed to workaround some problems of socket.makefile
+ method for sockets constructed from numerical file descriptors passed
+ through command line arguments.
+ """
+
+ def __init__(self, sk):
+ self.__sk = sk
+
+ def read(self, size=0x10000):
+ return self.__sk.recv(size)
+
+ def write(self, str):
+ self.__sk.send(str)
+
class net_dev:
def __init__(self, name=None, pair=None, link=None):
self.name = name
--
1.7.1
More information about the CRIU
mailing list