[Pkg-privacy-commits] [onionshare] 153/256: Move OnionShare object into its own file, so __init__ is just CLI logic

Ulrike Uhlig ulrike at moszumanska.debian.org
Fri May 26 12:53:31 UTC 2017


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

ulrike pushed a commit to branch master
in repository onionshare.

commit 9f43b7298c354366f854f5e3a0062b17a8891403
Author: Micah Lee <micah at micahflee.com>
Date:   Mon Apr 17 19:28:51 2017 -0700

    Move OnionShare object into its own file, so __init__ is just CLI logic
---
 onionshare/__init__.py   | 68 ++++------------------------------------
 onionshare/onionshare.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 62 deletions(-)

diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index 4c99622..4340b50 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -18,71 +18,11 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-import os, sys, time, argparse, shutil, socket, threading
+import os, sys, time, argparse, threading
 
 from . import strings, helpers, web
 from .onion import *
-
-class OnionShare(object):
-    """
-    OnionShare is the main application class. Pass in options and run
-    start_onion_service and it will do the magic.
-    """
-    def __init__(self, onion, debug=False, local_only=False, stay_open=False):
-        # The Onion object
-        self.onion = onion
-
-        self.hidserv_dir = None
-        self.onion_host = None
-        self.stealth = None
-
-        # files and dirs to delete on shutdown
-        self.cleanup_filenames = []
-
-        # debug mode
-        if debug:
-            web.debug_mode()
-
-        # do not use tor -- for development
-        self.local_only = local_only
-
-        # automatically close when download is finished
-        self.stay_open = stay_open
-
-    def set_stealth(self, stealth):
-        self.stealth = stealth
-        self.onion.stealth = stealth
-
-    def start_onion_service(self):
-        """
-        Start the onionshare onion service.
-        """
-        self.port = helpers.get_available_port(17600, 17650)
-
-        if self.local_only:
-            self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
-            return
-
-        self.onion_host = self.onion.start_onion_service(self.port)
-
-        if self.stealth:
-            self.auth_string = self.onion.auth_string
-
-    def cleanup(self):
-        """
-        Shut everything down and clean up temporary files, etc.
-        """
-        # cleanup files
-        for filename in self.cleanup_filenames:
-            if os.path.isfile(filename):
-                os.remove(filename)
-            elif os.path.isdir(filename):
-                shutil.rmtree(filename)
-        self.cleanup_filenames = []
-
-        # cleanup the onion
-        if self.onion:
-            self.onion.cleanup()
+from .onionshare import OnionShare
 
 
 def main(cwd=None):
@@ -144,6 +84,10 @@ def main(cwd=None):
         print("")
         sys.exit()
 
+    # Debug mode?
+    if debug:
+        web.debug_mode()
+
     # Prepare files to share
     print(strings._("preparing_files"))
     web.set_file_info(filenames)
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
new file mode 100644
index 0000000..71189fe
--- /dev/null
+++ b/onionshare/onionshare.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+"""
+OnionShare | https://onionshare.org/
+
+Copyright (C) 2017 Micah Lee <micah at micahflee.com>
+
+This program 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 3 of the License, or
+(at your option) any later version.
+
+This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import os, shutil
+
+from . import helpers
+
+class OnionShare(object):
+    """
+    OnionShare is the main application class. Pass in options and run
+    start_onion_service and it will do the magic.
+    """
+    def __init__(self, onion, debug=False, local_only=False, stay_open=False):
+        # The Onion object
+        self.onion = onion
+
+        self.hidserv_dir = None
+        self.onion_host = None
+        self.stealth = None
+
+        # files and dirs to delete on shutdown
+        self.cleanup_filenames = []
+
+        # do not use tor -- for development
+        self.local_only = local_only
+
+        # automatically close when download is finished
+        self.stay_open = stay_open
+
+    def set_stealth(self, stealth):
+        self.stealth = stealth
+        self.onion.stealth = stealth
+
+    def start_onion_service(self):
+        """
+        Start the onionshare onion service.
+        """
+        self.port = helpers.get_available_port(17600, 17650)
+
+        if self.local_only:
+            self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
+            return
+
+        self.onion_host = self.onion.start_onion_service(self.port)
+
+        if self.stealth:
+            self.auth_string = self.onion.auth_string
+
+    def cleanup(self):
+        """
+        Shut everything down and clean up temporary files, etc.
+        """
+        # cleanup files
+        for filename in self.cleanup_filenames:
+            if os.path.isfile(filename):
+                os.remove(filename)
+            elif os.path.isdir(filename):
+                shutil.rmtree(filename)
+        self.cleanup_filenames = []
+
+        # cleanup the onion
+        if self.onion:
+            self.onion.cleanup()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list