aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/Makefile.am14
-rw-r--r--contrib/__init__.py0
-rw-r--r--contrib/gnunet_pyexpect.py.in78
3 files changed, 85 insertions, 7 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index e4b92bb2e..57dba1a53 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -7,7 +7,7 @@ timeout_watchdog_SOURCES = \
7endif 7endif
8 8
9noinst_SCRIPTS = \ 9noinst_SCRIPTS = \
10 gnunet_pyexpect/gnunet_pyexpect.py 10 gnunet_pyexpect.py
11 11
12dist_pkgdata_DATA = \ 12dist_pkgdata_DATA = \
13 gnunet-logo-color.png \ 13 gnunet-logo-color.png \
@@ -18,15 +18,15 @@ EXTRA_DIST = \
18 hostlist.cgi \ 18 hostlist.cgi \
19 hostlist.php \ 19 hostlist.php \
20 report.sh \ 20 report.sh \
21 gnunet_pyexpect/__init__.py \ 21 __init__.py \
22 gnunet_pyexpect/gnunet_pyexpect.py.in 22 gnunet_pyexpect.py.in
23 23
24do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' 24do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
25 25
26gnunet_pyexpect/gnunet_pyexpect.py: gnunet_pyexpect/gnunet_pyexpect.py.in Makefile 26gnunet_pyexpect.py: gnunet_pyexpect.py.in Makefile
27 $(do_subst) < $(srcdir)/gnunet_pyexpect/gnunet_pyexpect.py.in > gnunet_pyexpect/gnunet_pyexpect.py 27 $(do_subst) < $(srcdir)/gnunet_pyexpect.py.in > gnunet_pyexpect.py
28 chmod +x gnunet_pyexpect/gnunet_pyexpect.py 28 chmod +x gnunet_pyexpect.py
29 chmod +x gnunet_pyexpect/__init__.py 29 chmod +x __init__.py
30 30
31 31
32# init_gnunet_redhat \ 32# init_gnunet_redhat \
diff --git a/contrib/__init__.py b/contrib/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/contrib/__init__.py
diff --git a/contrib/gnunet_pyexpect.py.in b/contrib/gnunet_pyexpect.py.in
new file mode 100644
index 000000000..15d19fe5a
--- /dev/null
+++ b/contrib/gnunet_pyexpect.py.in
@@ -0,0 +1,78 @@
1#!@PYTHON@
2# This file is part of GNUnet.
3# (C) 2010 Christian Grothoff (and other contributing authors)
4#
5# GNUnet is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published
7# by the Free Software Foundation; either version 2, or (at your
8# option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with GNUnet; see the file COPYING. If not, write to the
17# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18# Boston, MA 02111-1307, USA.
19#
20# Testcase for gnunet-peerinfo
21from __future__ import print_function
22import os
23import re
24import subprocess
25import sys
26import shutil
27import time
28
29class pexpect (object):
30 def __init__ (self):
31 super (pexpect, self).__init__ ()
32
33 def spawn (self, stdin, arglist, *pargs, **kwargs):
34 self.proc = subprocess.Popen (arglist, *pargs, **kwargs)
35 if self.proc is None:
36 print ("Failed to spawn a process {0}".format (arglist))
37 sys.exit (1)
38 if stdin is not None:
39 self.stdo, self.stde = self.proc.communicate (stdin)
40 else:
41 self.stdo, self.stde = self.proc.communicate ()
42 return self.proc
43
44 def expect (self, s, r, flags=0):
45 stream = self.stdo if s == 'stdout' else self.stde
46 if isinstance (r, str):
47 if r == "EOF":
48 if len (stream) == 0:
49 return True
50 else:
51 print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream)))
52 sys.exit (2)
53 raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r))
54 m = r.search (stream, flags)
55 if not m:
56 print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream))
57 sys.exit (2)
58 stream = stream[m.end ():]
59 if s == 'stdout':
60 self.stdo = stream
61 else:
62 self.stde = stream
63 return m
64
65 def read (self, s, size=-1):
66 stream = self.stdo if s == 'stdout' else self.stde
67 result = ""
68 if size < 0:
69 result = stream
70 new_stream = ""
71 else:
72 result = stream[0:size]
73 new_stream = stream[size:]
74 if s == 'stdout':
75 self.stdo = new_stream
76 else:
77 self.stde = new_stream
78 return result