added two stubs: arnied.py and output_buffer.py
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 30 Nov 2015 09:14:34 +0000 (10:14 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 30 Nov 2015 09:14:34 +0000 (10:14 +0100)
arnied.py [new file with mode: 0644]
output_buffer.py [new file with mode: 0644]

diff --git a/arnied.py b/arnied.py
new file mode 100644 (file)
index 0000000..7bd6d34
--- /dev/null
+++ b/arnied.py
@@ -0,0 +1,26 @@
+""" Interface to arnied
+
+only a stub; should at least contain a set_cnf and get_cnf
+"""
+
+def set_cnf(var_name, value):
+    """ not implemented yet """
+    raise NotImplementedError()
+
+    # not good enough: implementation in autotest guest/utils/backup_utils
+
+
+def get_cnf(var_name, value):
+    """ not implemented yet """
+    raise NotImplementedError()
+
+    # not good enough: implementation in autotest guest/utils/backup_utils
+
+
+def wait_for_generate(timeout=None):
+    """ wait for generate to run/finish
+    
+    to be copied from autotest arnied_wrapper
+    """
+
+    raise NotImplementedError()
diff --git a/output_buffer.py b/output_buffer.py
new file mode 100644 (file)
index 0000000..ed45b61
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+# The software in this package is distributed under the GNU General
+# Public License version 2 (with a special exception described below).
+#
+# A copy of GNU General Public License (GPL) is included in this distribution,
+# in the file COPYING.GPL.
+#
+# As a special exception, if other files instantiate templates or use macros
+# or inline functions from this file, or you compile this file and link it
+# with other works to produce a work based on this file, this file
+# does not by itself cause the resulting work to be covered
+# by the GNU General Public License.
+#
+# However the source code for this file must still be made available
+# in accordance with section (3) of the GNU General Public License.
+#
+# This exception does not invalidate any other reasons why a work based
+# on this file might be covered by the GNU General Public License.
+
+"""
+OutputBuffer: classes to buffer line-based output
+
+.. codeauthor:: Christian Herdtweck, christian.herdtweck@intra2net.com
+"""
+
+class OutputLineBuffer:
+    """ circular buffer for text lines; saves last N lines
+    
+    can output them afterwards in correct order
+
+    public attributes (please read only!): buffer_size, n_lines
+    """
+
+    buffer_size = None
+    _buffer = None
+    _buff_idx = None
+    n_lines = None
+
+    def __init__(self, size):
+        """ initialize with N = size """
+        self.buffer_size = size
+        self._buffer = ['[no output]' for line_idx in range(size)]
+        self._buff_idx = 0
+        self.n_lines = 0
+
+    def add(self, line):
+        """ add a line to buffer -- might replace the oldest line """
+        self._buffer[self._buff_idx] = line
+        self._buff_idx = (self._buff_idx + 1) % self.buffer_size
+        self.n_lines += 1
+
+    def output(self, output_func):
+        """ run output_func(line) on last saved lines """
+        if self.n_lines >= self.buffer_size:
+            for idx in range(self._buff_idx, self.buffer_size):
+                output_func(self._buffer[idx])
+
+        for idx in range(0, self._buff_idx):
+            output_func(self._buffer[idx])
+
+
+def main():
+    """ Main function, called when running file as script
+
+    currently raises a NotImplementedError
+    """
+    raise NotImplementedError
+
+    line_buffer = OutputLineBuffer(3)
+    for output_line in proc.stdout:
+        progress_reporter.inc_current_points()
+        line_buffer.add(output_line)
+
+    proc.stdout.close()
+    return_code = proc.wait()
+
+    if return_code != 0:
+        self.logger.warning('extraction returned {0}!'.format(return_code))
+        self.logger.warning('command was: {0}'.format(' '.join(cpio)))
+        self.logger.warning('last {0} output lines:'.format(
+            min(line_buffer.buffer_size, line_buffer.n_lines)))
+        line_buffer.output(self.logger.warning)
+
+# end: function main
+
+
+if __name__ == '__main__':
+    main()