summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-05 21:22:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-05 21:22:35 +0000
commitab81cb16f400110163530a6eaf967224296b99aa (patch)
treee888382f9eb692a59e233840391b02a3e9834353 /contrib
parent573dd922c52054488ef436f97955e965b806c8de (diff)
moving pyexpect, dummy init (missing from patch)
Diffstat (limited to 'contrib')
-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 = \
endif
noinst_SCRIPTS = \
- gnunet_pyexpect/gnunet_pyexpect.py
+ gnunet_pyexpect.py
dist_pkgdata_DATA = \
gnunet-logo-color.png \
@@ -18,15 +18,15 @@ EXTRA_DIST = \
hostlist.cgi \
hostlist.php \
report.sh \
- gnunet_pyexpect/__init__.py \
- gnunet_pyexpect/gnunet_pyexpect.py.in
+ __init__.py \
+ gnunet_pyexpect.py.in
do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
-gnunet_pyexpect/gnunet_pyexpect.py: gnunet_pyexpect/gnunet_pyexpect.py.in Makefile
- $(do_subst) < $(srcdir)/gnunet_pyexpect/gnunet_pyexpect.py.in > gnunet_pyexpect/gnunet_pyexpect.py
- chmod +x gnunet_pyexpect/gnunet_pyexpect.py
- chmod +x gnunet_pyexpect/__init__.py
+gnunet_pyexpect.py: gnunet_pyexpect.py.in Makefile
+ $(do_subst) < $(srcdir)/gnunet_pyexpect.py.in > gnunet_pyexpect.py
+ chmod +x gnunet_pyexpect.py
+ chmod +x __init__.py
# 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 @@
+#!@PYTHON@
+# This file is part of GNUnet.
+# (C) 2010 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# Testcase for gnunet-peerinfo
+from __future__ import print_function
+import os
+import re
+import subprocess
+import sys
+import shutil
+import time
+
+class pexpect (object):
+ def __init__ (self):
+ super (pexpect, self).__init__ ()
+
+ def spawn (self, stdin, arglist, *pargs, **kwargs):
+ self.proc = subprocess.Popen (arglist, *pargs, **kwargs)
+ if self.proc is None:
+ print ("Failed to spawn a process {0}".format (arglist))
+ sys.exit (1)
+ if stdin is not None:
+ self.stdo, self.stde = self.proc.communicate (stdin)
+ else:
+ self.stdo, self.stde = self.proc.communicate ()
+ return self.proc
+
+ def expect (self, s, r, flags=0):
+ stream = self.stdo if s == 'stdout' else self.stde
+ if isinstance (r, str):
+ if r == "EOF":
+ if len (stream) == 0:
+ return True
+ else:
+ print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream)))
+ sys.exit (2)
+ raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r))
+ m = r.search (stream, flags)
+ if not m:
+ print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream))
+ sys.exit (2)
+ stream = stream[m.end ():]
+ if s == 'stdout':
+ self.stdo = stream
+ else:
+ self.stde = stream
+ return m
+
+ def read (self, s, size=-1):
+ stream = self.stdo if s == 'stdout' else self.stde
+ result = ""
+ if size < 0:
+ result = stream
+ new_stream = ""
+ else:
+ result = stream[0:size]
+ new_stream = stream[size:]
+ if s == 'stdout':
+ self.stdo = new_stream
+ else:
+ self.stde = new_stream
+ return result