gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated (f2773a77d -> 2048bc328)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (f2773a77d -> 2048bc328)
Date: Tue, 22 May 2018 11:51:17 +0200

This is an automated email from the git hooks/post-receive script.

ng0 pushed a change to branch master
in repository gnunet.

    from f2773a77d gitignore flake8.log
     new 043b52f76 More flakes
     new 067f31e6e ++
     new 2048bc328 contrib/scripts/terminate.py.in: indent fixes + comments

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 contrib/scripts/terminate.py.in |  72 +++++++++-------
 src/arm/test_gnunet_arm.py.in   | 185 +++++++++++++++++++++-------------------
 src/dht/test_dht_tools.py.in    | 184 ++++++++++++++++++++-------------------
 3 files changed, 231 insertions(+), 210 deletions(-)

diff --git a/contrib/scripts/terminate.py.in b/contrib/scripts/terminate.py.in
index 4a6719f38..a1cae5605 100644
--- a/contrib/scripts/terminate.py.in
+++ b/contrib/scripts/terminate.py.in
@@ -20,45 +20,51 @@
 # Utility module that implements safe process termination for W32.
 # For other platforms it's equivalent to Popen.kill ()
 # Requires pywin32 on W32.
+# FIXME: flake8 (python3 version) says, like in many other files:
+#        sys + subprocess are unnecessary imports, not used.
 
 import sys
 import os
 import subprocess
 if os.name == 'nt':
-  import win32api
-  import win32process
+    import win32api
+    import win32process
+
 
 class dummyobj (object):
-  pass
+    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:
+        # XXX (F821): Undefined name 'SIGKILL'
+        return os.kill(int(pid), SIGKILL)
 
-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 ()
+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()
diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in
index cdd69251b..10bb58a9c 100644
--- a/src/arm/test_gnunet_arm.py.in
+++ b/src/arm/test_gnunet_arm.py.in
@@ -7,100 +7,107 @@ import re
 import subprocess
 import time
 
+# FIXME: There's too much repetition, move generally used parts into reusable 
modules.
 if os.name == "nt":
-  tmp = os.getenv ("TEMP")
+    tmp = os.getenv("TEMP")
 else:
-  tmp = "/tmp"
+    tmp = "/tmp"
 
 if os.name == 'nt':
-  st = 'gnunet-statistics.exe'
-  arm = './gnunet-arm.exe'
+    st = 'gnunet-statistics.exe'
+    arm = './gnunet-arm.exe'
 else:
-  st = 'gnunet-statistics'
-  arm = './gnunet-arm'
+    st = 'gnunet-statistics'
+    arm = './gnunet-arm'
 
 run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
-debug = os.getenv ('DEBUG')
+debug = os.getenv('DEBUG')
 if debug:
-  run_arm += [debug.split (' ')]
-
-def cleanup ():
-  shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True)
-
-def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
-  if want_stdo:
-    stdo = subprocess.PIPE
-  else:
-    stdo = None
-  if want_stde:
-    stde = subprocess.PIPE
-  else:
-    stde = None
-  p = subprocess.Popen (args, stdout = stdo, stderr = stde)
-  stdo, stde = p.communicate ()
-  if not nofail:
-    if p.returncode != 0:
-      sys.exit (p.returncode)
-  return (p.returncode, stdo, stde)
-
-def fail (result):
-  print (result)
-  r_arm (['-e'], want_stdo = False)
-  sys.exit (1)
-
-
-def end_arm_failer (command, rc, stdo, stde, normal):
-  if normal:
-    if rc != 0:
-      fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format 
(command, stdo, stde))
-  else:
-    if rc == 0:
-      fail ("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format (command, stdo, stde))
-
-def print_only_failer (command, rc, stdo, stde, normal):
-  if normal:
-    if rc != 0:
-      print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format 
(command, stdo, stde))
-      sys.exit (1)
-  else:
-    if rc == 0:
-      print ("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format (command, stdo, stde))
-      sys.exit (1)
-
-
-def r_something (to_run, extra_args, failer = None, normal = True, **kw):
-  rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, want_stde = 
True, **kw)
-  if failer is not None:
-    failer (to_run + extra_args, rc, stdo, stde, normal)
-  return (rc, stdo, stde)
-
-def r_arm (extra_args, **kw):
-  return r_something (run_arm, extra_args, **kw)
-
-cleanup ()
-
-print ("TEST: Bad argument checking...", end='')
-r_arm (['-x'], normal = False, failer = print_only_failer)
-print ("PASS")
-
-print ("TEST: Start ARM...", end='')
-r_arm (['-s'], failer = print_only_failer)
-time.sleep (1)
-print ("PASS")
-
-print ("TEST: Start another service...", end='')
-r_arm (['-i', 'resolver'], failer = end_arm_failer)
-time.sleep (1)
-print ("PASS")
-
-print ("TEST: Stop a service...", end='')
-r_arm (['-k', 'resolver'], failer = end_arm_failer)
-time.sleep (1)
-print ("PASS")
-
-print ("TEST: Stop ARM...", end='')
-r_arm (['-e'], failer = print_only_failer)
-time.sleep (1)
-print ("PASS")
-
-cleanup ()
+    run_arm += [debug.split(' ')]
+
+
+def cleanup():
+    shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True)
+
+
+def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
+    if want_stdo:
+        stdo = subprocess.PIPE
+    else:
+        stdo = None
+    if want_stde:
+        stde = subprocess.PIPE
+    else:
+        stde = None
+    p = subprocess.Popen(args, stdout=stdo, stderr=stde)
+    stdo, stde = p.communicate()
+    if not nofail:
+        if p.returncode != 0:
+            sys.exit(p.returncode)
+    return (p.returncode, stdo, stde)
+
+
+def fail(result):
+    print(result)
+    r_arm(['-e'], want_stdo=False)
+    sys.exit(1)
+
+
+def end_arm_failer(command, rc, stdo, stde, normal):
+    if normal:
+        if rc != 0:
+            fail("FAIL: error running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+    else:
+        if rc == 0:
+            fail("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+
+
+def print_only_failer(command, rc, stdo, stde, normal):
+    if normal:
+        if rc != 0:
+            print("FAIL: error running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+            sys.exit(1)
+    else:
+        if rc == 0:
+            print("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+            sys.exit(1)
+
+
+def r_something(to_run, extra_args, failer=None, normal=True, **kw):
+    rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, want_stde=True, 
**kw)
+    if failer is not None:
+        failer(to_run + extra_args, rc, stdo, stde, normal)
+    return (rc, stdo, stde)
+
+
+def r_arm(extra_args, **kw):
+    return r_something(run_arm, extra_args, **kw)
+
+
+cleanup()
+
+print("TEST: Bad argument checking...", end='')
+r_arm(['-x'], normal=False, failer=print_only_failer)
+print("PASS")
+
+print("TEST: Start ARM...", end='')
+r_arm(['-s'], failer=print_only_failer)
+time.sleep(1)
+print("PASS")
+
+print("TEST: Start another service...", end='')
+r_arm(['-i', 'resolver'], failer=end_arm_failer)
+time.sleep(1)
+print("PASS")
+
+print("TEST: Stop a service...", end='')
+r_arm(['-k', 'resolver'], failer=end_arm_failer)
+time.sleep(1)
+print("PASS")
+
+print("TEST: Stop ARM...", end='')
+r_arm(['-e'], failer=print_only_failer)
+time.sleep(1)
+print("PASS")
+
+cleanup()
diff --git a/src/dht/test_dht_tools.py.in b/src/dht/test_dht_tools.py.in
index 2d4ab9adc..05582cbd0 100644
--- a/src/dht/test_dht_tools.py.in
+++ b/src/dht/test_dht_tools.py.in
@@ -21,105 +21,113 @@ import subprocess
 import time
 import tempfile
 
-os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"];
+os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"]
 
 if os.name == "nt":
-  tmp = os.getenv ("TEMP")
+    tmp = os.getenv("TEMP")
 else:
-  tmp = "/tmp"
+    tmp = "/tmp"
 
 if os.name == 'nt':
-  get = './gnunet-dht-get.exe'
-  put = './gnunet-dht-put.exe'
-  arm = 'gnunet-arm.exe'
+    get = './gnunet-dht-get.exe'
+    put = './gnunet-dht-put.exe'
+    arm = 'gnunet-arm.exe'
 else:
-  get = './gnunet-dht-get'
-  put = './gnunet-dht-put'
-  arm = 'gnunet-arm'
+    get = './gnunet-dht-get'
+    put = './gnunet-dht-put'
+    arm = 'gnunet-arm'
 
 cfgfile = 'test_dht_api_peer1.conf'
-  
 run_get = [get, '-c', cfgfile]
 run_put = [put, '-c', cfgfile]
 run_arm = [arm, '-c', cfgfile]
-debug = os.getenv ('DEBUG')
+debug = os.getenv('DEBUG')
 if debug:
-  run_arm += [debug.split (' ')]
-
-def cleanup (exitcode):
-  sys.exit (exitcode)
-
-def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
-  if want_stdo:
-    stdo = subprocess.PIPE
-  else:
-    stdo = None
-  if want_stde:
-    stde = subprocess.PIPE
-  else:
-    stde = None
-  p = subprocess.Popen (args, stdout = stdo, stderr = stde)
-  stdo, stde = p.communicate ()
-  if not nofail:
-    if p.returncode != 0:
-      sys.exit (p.returncode)
-  return (p.returncode, stdo, stde)
-
-def fail (result):
-  print (result)
-  r_arm (['-e'], want_stdo = False)
-  cleanup (1)
-
-def r_something (to_run, extra_args, failer = None, normal = True, **kw):
-  rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, **kw)
-  if failer is not None:
-    failer (to_run + extra_args, rc, stdo, stde, normal)
-  return (rc, stdo, stde)
-
-def r_arm (extra_args, **kw):
-  return r_something (run_arm, extra_args, **kw)
-
-def r_get (extra_args, **kw):
-  return r_something (run_get, extra_args, **kw)
-
-def r_put (extra_args, **kw):
-  return r_something (run_put, extra_args, **kw)
-
-def end_arm_failer (command, rc, stdo, stde, normal):
-  if normal:
-    if rc != 0:
-      fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format 
(command, stdo, stde))
-  else:
-    if rc == 0:
-      fail ("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format (command, stdo, stde))
-
-def print_only_failer (command, rc, stdo, stde, normal):
-  if normal:
-    if rc != 0:
-      print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format 
(command, stdo, stde))
-      cleanup (1)
-  else:
-    if rc == 0:
-      print ("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format (command, stdo, stde))
-      cleanup (1)
-
-
-print ("TEST: Starting ARM...", end='')
-r_arm (['-s'], failer = end_arm_failer, want_stdo = False, want_stde = False)
-print ("PASS")
-time.sleep (1)
-
-print ("TEST: Testing put...", end='')
-r_put (['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer = end_arm_failer)
-print ("PASS")
-time.sleep (1)
-
-print ("TEST: Testing get...", end='')
-rc, stdo, stde = r_get (['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo 
= True, failer = end_arm_failer)
-stdo = stdo.replace ('\r', '').splitlines ()
+    run_arm += [debug.split(' ')]
+
+
+def cleanup(exitcode):
+    sys.exit(exitcode)
+
+
+def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
+    if want_stdo:
+        stdo = subprocess.PIPE
+    else:
+        stdo = None
+    if want_stde:
+        stde = subprocess.PIPE
+    else:
+        stde = None
+    p = subprocess.Popen(args, stdout=stdo, stderr=stde)
+    stdo, stde = p.communicate()
+    if not nofail:
+        if p.returncode != 0:
+            sys.exit(p.returncode)
+    return (p.returncode, stdo, stde)
+
+
+def fail(result):
+    print(result)
+    r_arm(['-e'], want_stdo=False)
+    cleanup(1)
+
+
+def r_something(to_run, extra_args, failer=None, normal=True, **kw):
+    rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, **kw)
+    if failer is not None:
+        failer(to_run + extra_args, rc, stdo, stde, normal)
+    return (rc, stdo, stde)
+
+
+def r_arm(extra_args, **kw):
+    return r_something(run_arm, extra_args, **kw)
+
+
+def r_get(extra_args, **kw):
+    return r_something(run_get, extra_args, **kw)
+
+
+def r_put(extra_args, **kw):
+    return r_something(run_put, extra_args, **kw)
+
+
+def end_arm_failer(command, rc, stdo, stde, normal):
+    if normal:
+        if rc != 0:
+            fail("FAIL: error running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+    else:
+        if rc == 0:
+            fail("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+
+
+def print_only_failer(command, rc, stdo, stde, normal):
+    if normal:
+        if rc != 0:
+            print("FAIL: error running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+            cleanup(1)
+    else:
+        if rc == 0:
+            print("FAIL: expected error while running {}\nCommand output 
was:\n{}\n{}".format(command, stdo, stde))
+            cleanup(1)
+
+
+print("TEST: Starting ARM...", end='')
+r_arm(['-s'], failer=end_arm_failer, want_stdo=False, want_stde=False)
+print("PASS")
+time.sleep(1)
+
+print("TEST: Testing put...", end='')
+r_put(['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer=end_arm_failer)
+print("PASS")
+time.sleep(1)
+
+print("TEST: Testing get...", end='')
+rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], 
want_stdo=True, failer=end_arm_failer)
+stdo = stdo.replace('\r', '').splitlines()
 expect = "Result 0, type 8:\ntestdata".splitlines()
-if len (stdo) != 2 or len (expect) != 2 or stdo[0] != expect[0] or stdo[1] != 
expect[1]:
-  fail ("output `{}' differs from expected `{}'".format (stdo, expect))
-print ("PASS")
+if len(stdo) != 2 or len(expect) != 2 or stdo[0] != expect[0] or stdo[1] != 
expect[1]:
+    fail("output `{}' differs from expected `{}'".format(stdo, expect))
+print("PASS")
 
-r_arm (['-e', '-d'], failer = print_only_failer)
+r_arm(['-e', '-d'], failer=print_only_failer)

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]