[Pkg-anonymity-tools] [onionshare] 21/140: refactored cleanup handlers to use a queue, so they will work with the GUI

Ulrike Uhlig u-guest at moszumanska.debian.org
Mon Sep 29 20:33:43 UTC 2014


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

u-guest pushed a commit to branch master
in repository onionshare.

commit 0bc778437d1d4fd6d7e14d744402fc3c08e6484f
Author: Micah Lee <micah at micahflee.com>
Date:   Tue Aug 26 15:44:44 2014 -0700

    refactored cleanup handlers to use a queue, so they will work with the GUI
---
 onionshare/onionshare.py         | 31 ++++++++++++++++++++-----------
 onionshare_gui/onionshare_gui.py |  2 +-
 setup/onionshare-launcher.py     |  2 +-
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index d370fd3..5e6be87 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, mimetypes, hmac
+import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, mimetypes, hmac, shutil
 from itertools import izip
 
 from stem.control import Controller
@@ -92,6 +92,22 @@ def add_request(type, path, data=None):
       'data': data
     })
 
+cleanup_q = Queue.Queue()
+def register_cleanup_handler(directory):
+    global cleanup_q
+    def handler(signum = None, frame = None):
+        shutil.rmtree(directory)
+    cleanup_q.put(handler)
+
+def execute_cleanup_handlers():
+    global cleanup_q
+    try:
+        while True:
+            handler = cleanup_q.get(False)
+            handler()
+    except Queue.Empty:
+        pass
+
 def human_readable_filesize(b):
     thresh = 1024.0
     if b < thresh:
@@ -305,16 +321,6 @@ def tails_root():
         while True:
             time.sleep(1)
 
-def register_cleanup_handler(directory):
-    import signal
-    import shutil
-    def handler(signum = None, frame = None):
-        shutil.rmtree(directory)
-        sys.exit()
-    for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
-        signal.signal(sig, handler)
-
-
 def main():
     load_strings()
     tails_root()
@@ -383,5 +389,8 @@ def main():
     app.run(port=port)
     print '\n'
 
+    # shutdown
+    execute_cleanup_handlers()
+
 if __name__ == '__main__':
     main()
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index 8f7f280..36081b8 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -373,7 +373,7 @@ def main():
 
     # clean up when app quits
     def shutdown():
-        pass
+        onionshare.execute_cleanup_handlers()
     app.connect(app, QtCore.SIGNAL("aboutToQuit()"), shutdown)
 
     # launch the gui
diff --git a/setup/onionshare-launcher.py b/setup/onionshare-launcher.py
index 83bf628..14803cb 100644
--- a/setup/onionshare-launcher.py
+++ b/setup/onionshare-launcher.py
@@ -1,5 +1,5 @@
 from __future__ import division
-import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, random, functools, logging, ctypes, hmac
+import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, random, functools, logging, ctypes, hmac, shutil
 from itertools import izip
 import stem, stem.control, flask
 from PyQt4 import QtCore, QtGui

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/onionshare.git



More information about the Pkg-anonymity-tools mailing list