summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2015-06-21 18:14:58 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2015-06-21 18:14:58 +0000
commit1cfcc6a13f75ff69ec6ab851a471f1939cb5f295 (patch)
tree55400e04802501961a9181b3c94d7bb7d605dc70 /contrib
parent13d57af5209744c385c6cff56fd0e2fd95eee900 (diff)
dos2unix
Diffstat (limited to 'contrib')
-rw-r--r--contrib/gnunet_pyexpect.py.in166
-rw-r--r--contrib/terminate.py.in84
2 files changed, 125 insertions, 125 deletions
diff --git a/contrib/gnunet_pyexpect.py.in b/contrib/gnunet_pyexpect.py.in
index f8b7cc88f..b03bcc557 100644
--- a/contrib/gnunet_pyexpect.py.in
+++ b/contrib/gnunet_pyexpect.py.in
@@ -1,83 +1,83 @@
-#!@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):
- env = kwargs.pop ('env', None)
- if env is None:
- env = os.environ.copy ()
- # This messes up some testcases, disable log redirection
- env.pop ('GNUNET_FORCE_LOGFILE', None)
- self.proc = subprocess.Popen (arglist, *pargs, env=env, **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.decode(), 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
+#!@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):
+ env = kwargs.pop ('env', None)
+ if env is None:
+ env = os.environ.copy ()
+ # This messes up some testcases, disable log redirection
+ env.pop ('GNUNET_FORCE_LOGFILE', None)
+ self.proc = subprocess.Popen (arglist, *pargs, env=env, **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.decode(), 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
diff --git a/contrib/terminate.py.in b/contrib/terminate.py.in
index 14c79c10d..aeaaa1501 100644
--- a/contrib/terminate.py.in
+++ b/contrib/terminate.py.in
@@ -20,45 +20,45 @@
# Utility module that implements safe process termination for W32.
# For other platforms it's equivalent to Popen.kill ()
# Requires pywin32 on W32.
-
-import sys
-import os
-import subprocess
-if os.name == 'nt':
- import win32api
- import win32process
-
-class dummyobj (object):
- pass
-
-def safe_terminate_process_by_pid (pid, code):
- if os.name == 'nt':
- p = dummyobj ()
- p._handle = win32api.OpenProcess (2 | 1024 | 8 | 32 | 16, 0, pid)
- result = safe_terminate_process (p, code)
- win32api.CloseHandle (p._handle)
- return result
- else:
- return os.kill (int (pid), SIGKILL)
-
-def safe_terminate_process (proc, code):
- if os.name == 'nt':
- cp = win32api.GetCurrentProcess ()
- result = False
- dupproc = win32api.DuplicateHandle (cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0)
- try:
- exitcode = win32process.GetExitCodeProcess (dupproc)
- if exitcode == 0x103:
- kernel32 = win32api.GetModuleHandle ("kernel32")
- exitprocess = win32api.GetProcAddress (kernel32, "ExitProcess")
- th, tid = win32process.CreateRemoteThread (dupproc, None, 0, exitprocess, code, 0)
- win32api.CloseHandle (th)
- result = True
- else:
- result = True
- # except failed to get exit code? failed to get module handle?
- finally:
- win32api.CloseHandle (dupproc)
- return result
- else:
- return proc.kill ()
+
+import sys
+import os
+import subprocess
+if os.name == 'nt':
+ import win32api
+ import win32process
+
+class dummyobj (object):
+ pass
+
+def safe_terminate_process_by_pid (pid, code):
+ if os.name == 'nt':
+ p = dummyobj ()
+ p._handle = win32api.OpenProcess (2 | 1024 | 8 | 32 | 16, 0, pid)
+ result = safe_terminate_process (p, code)
+ win32api.CloseHandle (p._handle)
+ return result
+ else:
+ return os.kill (int (pid), SIGKILL)
+
+def safe_terminate_process (proc, code):
+ if os.name == 'nt':
+ cp = win32api.GetCurrentProcess ()
+ result = False
+ dupproc = win32api.DuplicateHandle (cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0)
+ try:
+ exitcode = win32process.GetExitCodeProcess (dupproc)
+ if exitcode == 0x103:
+ kernel32 = win32api.GetModuleHandle ("kernel32")
+ exitprocess = win32api.GetProcAddress (kernel32, "ExitProcess")
+ th, tid = win32process.CreateRemoteThread (dupproc, None, 0, exitprocess, code, 0)
+ win32api.CloseHandle (th)
+ result = True
+ else:
+ result = True
+ # except failed to get exit code? failed to get module handle?
+ finally:
+ win32api.CloseHandle (dupproc)
+ return result
+ else:
+ return proc.kill ()