diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2015-06-21 18:14:58 +0000 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2015-06-21 18:14:58 +0000 |
commit | 1cfcc6a13f75ff69ec6ab851a471f1939cb5f295 (patch) | |
tree | 55400e04802501961a9181b3c94d7bb7d605dc70 /contrib | |
parent | 13d57af5209744c385c6cff56fd0e2fd95eee900 (diff) | |
download | gnunet-1cfcc6a13f75ff69ec6ab851a471f1939cb5f295.tar.gz gnunet-1cfcc6a13f75ff69ec6ab851a471f1939cb5f295.zip |
dos2unix
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/gnunet_pyexpect.py.in | 166 | ||||
-rw-r--r-- | contrib/terminate.py.in | 84 |
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 @@ | |||
1 | #!@PYTHON@ | 1 | #!@PYTHON@ |
2 | # This file is part of GNUnet. | 2 | # This file is part of GNUnet. |
3 | # (C) 2010 Christian Grothoff (and other contributing authors) | 3 | # (C) 2010 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | # by the Free Software Foundation; either version 2, or (at your |
8 | # option) any later version. | 8 | # option) any later version. |
9 | # | 9 | # |
10 | # GNUnet is distributed in the hope that it will be useful, but | 10 | # GNUnet is distributed in the hope that it will be useful, but |
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | # General Public License for more details. | 13 | # General Public License for more details. |
14 | # | 14 | # |
15 | # You should have received a copy of the GNU General Public License | 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 | 16 | # along with GNUnet; see the file COPYING. If not, write to the |
17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | # Boston, MA 02111-1307, USA. | 18 | # Boston, MA 02111-1307, USA. |
19 | # | 19 | # |
20 | # Testcase for gnunet-peerinfo | 20 | # Testcase for gnunet-peerinfo |
21 | from __future__ import print_function | 21 | from __future__ import print_function |
22 | import os | 22 | import os |
23 | import re | 23 | import re |
24 | import subprocess | 24 | import subprocess |
25 | import sys | 25 | import sys |
26 | import shutil | 26 | import shutil |
27 | import time | 27 | import time |
28 | 28 | ||
29 | class pexpect (object): | 29 | class pexpect (object): |
30 | def __init__ (self): | 30 | def __init__ (self): |
31 | super (pexpect, self).__init__ () | 31 | super (pexpect, self).__init__ () |
32 | 32 | ||
33 | def spawn (self, stdin, arglist, *pargs, **kwargs): | 33 | def spawn (self, stdin, arglist, *pargs, **kwargs): |
34 | env = kwargs.pop ('env', None) | 34 | env = kwargs.pop ('env', None) |
35 | if env is None: | 35 | if env is None: |
36 | env = os.environ.copy () | 36 | env = os.environ.copy () |
37 | # This messes up some testcases, disable log redirection | 37 | # This messes up some testcases, disable log redirection |
38 | env.pop ('GNUNET_FORCE_LOGFILE', None) | 38 | env.pop ('GNUNET_FORCE_LOGFILE', None) |
39 | self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs) | 39 | self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs) |
40 | if self.proc is None: | 40 | if self.proc is None: |
41 | print ("Failed to spawn a process {0}".format (arglist)) | 41 | print ("Failed to spawn a process {0}".format (arglist)) |
42 | sys.exit (1) | 42 | sys.exit (1) |
43 | if stdin is not None: | 43 | if stdin is not None: |
44 | self.stdo, self.stde = self.proc.communicate (stdin) | 44 | self.stdo, self.stde = self.proc.communicate (stdin) |
45 | else: | 45 | else: |
46 | self.stdo, self.stde = self.proc.communicate () | 46 | self.stdo, self.stde = self.proc.communicate () |
47 | return self.proc | 47 | return self.proc |
48 | 48 | ||
49 | def expect (self, s, r, flags=0): | 49 | def expect (self, s, r, flags=0): |
50 | stream = self.stdo if s == 'stdout' else self.stde | 50 | stream = self.stdo if s == 'stdout' else self.stde |
51 | if isinstance (r, str): | 51 | if isinstance (r, str): |
52 | if r == "EOF": | 52 | if r == "EOF": |
53 | if len (stream) == 0: | 53 | if len (stream) == 0: |
54 | return True | 54 | return True |
55 | else: | 55 | else: |
56 | print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream))) | 56 | print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream))) |
57 | sys.exit (2) | 57 | sys.exit (2) |
58 | raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r)) | 58 | raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r)) |
59 | m = r.search (stream.decode(), flags) | 59 | m = r.search (stream.decode(), flags) |
60 | if not m: | 60 | if not m: |
61 | print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream)) | 61 | print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream)) |
62 | sys.exit (2) | 62 | sys.exit (2) |
63 | stream = stream[m.end ():] | 63 | stream = stream[m.end ():] |
64 | if s == 'stdout': | 64 | if s == 'stdout': |
65 | self.stdo = stream | 65 | self.stdo = stream |
66 | else: | 66 | else: |
67 | self.stde = stream | 67 | self.stde = stream |
68 | return m | 68 | return m |
69 | 69 | ||
70 | def read (self, s, size=-1): | 70 | def read (self, s, size=-1): |
71 | stream = self.stdo if s == 'stdout' else self.stde | 71 | stream = self.stdo if s == 'stdout' else self.stde |
72 | result = "" | 72 | result = "" |
73 | if size < 0: | 73 | if size < 0: |
74 | result = stream | 74 | result = stream |
75 | new_stream = "" | 75 | new_stream = "" |
76 | else: | 76 | else: |
77 | result = stream[0:size] | 77 | result = stream[0:size] |
78 | new_stream = stream[size:] | 78 | new_stream = stream[size:] |
79 | if s == 'stdout': | 79 | if s == 'stdout': |
80 | self.stdo = new_stream | 80 | self.stdo = new_stream |
81 | else: | 81 | else: |
82 | self.stde = new_stream | 82 | self.stde = new_stream |
83 | return result | 83 | 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 @@ | |||
20 | # Utility module that implements safe process termination for W32. | 20 | # Utility module that implements safe process termination for W32. |
21 | # For other platforms it's equivalent to Popen.kill () | 21 | # For other platforms it's equivalent to Popen.kill () |
22 | # Requires pywin32 on W32. | 22 | # Requires pywin32 on W32. |
23 | 23 | ||
24 | import sys | 24 | import sys |
25 | import os | 25 | import os |
26 | import subprocess | 26 | import subprocess |
27 | if os.name == 'nt': | 27 | if os.name == 'nt': |
28 | import win32api | 28 | import win32api |
29 | import win32process | 29 | import win32process |
30 | 30 | ||
31 | class dummyobj (object): | 31 | class dummyobj (object): |
32 | pass | 32 | pass |
33 | 33 | ||
34 | def safe_terminate_process_by_pid (pid, code): | 34 | def safe_terminate_process_by_pid (pid, code): |
35 | if os.name == 'nt': | 35 | if os.name == 'nt': |
36 | p = dummyobj () | 36 | p = dummyobj () |
37 | p._handle = win32api.OpenProcess (2 | 1024 | 8 | 32 | 16, 0, pid) | 37 | p._handle = win32api.OpenProcess (2 | 1024 | 8 | 32 | 16, 0, pid) |
38 | result = safe_terminate_process (p, code) | 38 | result = safe_terminate_process (p, code) |
39 | win32api.CloseHandle (p._handle) | 39 | win32api.CloseHandle (p._handle) |
40 | return result | 40 | return result |
41 | else: | 41 | else: |
42 | return os.kill (int (pid), SIGKILL) | 42 | return os.kill (int (pid), SIGKILL) |
43 | 43 | ||
44 | def safe_terminate_process (proc, code): | 44 | def safe_terminate_process (proc, code): |
45 | if os.name == 'nt': | 45 | if os.name == 'nt': |
46 | cp = win32api.GetCurrentProcess () | 46 | cp = win32api.GetCurrentProcess () |
47 | result = False | 47 | result = False |
48 | dupproc = win32api.DuplicateHandle (cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0) | 48 | dupproc = win32api.DuplicateHandle (cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0) |
49 | try: | 49 | try: |
50 | exitcode = win32process.GetExitCodeProcess (dupproc) | 50 | exitcode = win32process.GetExitCodeProcess (dupproc) |
51 | if exitcode == 0x103: | 51 | if exitcode == 0x103: |
52 | kernel32 = win32api.GetModuleHandle ("kernel32") | 52 | kernel32 = win32api.GetModuleHandle ("kernel32") |
53 | exitprocess = win32api.GetProcAddress (kernel32, "ExitProcess") | 53 | exitprocess = win32api.GetProcAddress (kernel32, "ExitProcess") |
54 | th, tid = win32process.CreateRemoteThread (dupproc, None, 0, exitprocess, code, 0) | 54 | th, tid = win32process.CreateRemoteThread (dupproc, None, 0, exitprocess, code, 0) |
55 | win32api.CloseHandle (th) | 55 | win32api.CloseHandle (th) |
56 | result = True | 56 | result = True |
57 | else: | 57 | else: |
58 | result = True | 58 | result = True |
59 | # except failed to get exit code? failed to get module handle? | 59 | # except failed to get exit code? failed to get module handle? |
60 | finally: | 60 | finally: |
61 | win32api.CloseHandle (dupproc) | 61 | win32api.CloseHandle (dupproc) |
62 | return result | 62 | return result |
63 | else: | 63 | else: |
64 | return proc.kill () | 64 | return proc.kill () |