[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] * Removed unused code from assertions.py.



commit 98358b37463e68e03060b8917db78ee4055f1189
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Thu Nov 8 08:25:00 2012 +0000

    * Removed unused code from assertions.py.
    * Deleted config.py and process.py.
---
 wtf/assertions.py |   72 ----------------------------------------------------
 wtf/config.py     |   66 -----------------------------------------------
 wtf/process.py    |   73 -----------------------------------------------------
 3 files changed, 0 insertions(+), 211 deletions(-)

diff --git a/wtf/assertions.py b/wtf/assertions.py
index 875dcf5..60d3c50 100644
--- a/wtf/assertions.py
+++ b/wtf/assertions.py
@@ -10,78 +10,6 @@
 # :copyright: 2012 Isis Lovecruft, The Tor Project Inc.
 #
 
-class ValueChecker(object):
-    """
-    A class for general purpose value checks on commandline parameters
-    passed to subclasses of :class:`twisted.python.usage.Options`.
-    """
-    default_doc = "fix me"
-
-    def __init__(self, coerce_doc=None):
-        if not coerce_doc:
-            self.coerce_doc = default_doc
-        else:
-            self.coerce_doc = coerce_doc
-
-    @classmethod
-    def port_check(cls, port,
-                   range_min=1024, range_max=65535,
-                   coerce_doc=None):
-        """
-        Check that given ports are in the allowed range for an unprivileged
-        user.
-
-        :param port:
-            The port to check.
-        :param range_min:
-            The minimum allowable port number.
-        :param range_max:
-            The minimum allowable port number.
-        :param coerce_doc:
-            The documentation string to show in the optParameters menu, see
-            :class:`twisted.python.usage.Options`.
-        """
-        if not coerce_doc:
-            coerceDoc = cls.default_doc
-
-        assert isinstance(port, int)
-        if port not in range(range_min, range_max):
-            raise ValueError("Port out of range")
-            log.err()
-
-    @staticmethod
-    def uid_check(error_message):
-        """
-        Check that we're not root. If we are, setuid(1000) to normal user if
-        we're running on a posix-based system, and if we're on Windows just
-        tell the user that we can't be run as root with the specified options
-        and then exit.
-
-        :param error_message:
-            The string to log as an error message when the uid check fails.
-        """
-        uid, gid = os.getuid(), os.getgid()
-        if uid == 0 and gid == 0:
-            log.msg(error_message)
-        if os.name == 'posix':
-            log.msg("Dropping privileges to normal user...")
-            os.setgid(1000)
-            os.setuid(1000)
-        else:
-            sys.exit(0)
-
-    @staticmethod
-    def dir_check(d):
-        """Check that the given directory exists."""
-        if not os.path.isdir(d):
-            raise ValueError("%s doesn't exist, or has wrong permissions" % d)
-
-    @staticmethod
-    def file_check(f):
-        """Check that the given file exists."""
-        if not os.path.isfile(f):
-            raise ValueError("%s does not exist, or has wrong permissions" % f)
-
 def isNewStyleClass(obj):
     """
     Check if :param:`obj` is a new-style class, which is any class
diff --git a/wtf/config.py b/wtf/config.py
deleted file mode 100644
index 25f9576..0000000
--- a/wtf/config.py
+++ /dev/null
@@ -1,66 +0,0 @@
-class ValueChecker(object):
-    """
-    A class for general purpose value checks on commandline parameters
-    passed to subclasses of :class:`twisted.python.usage.Options`.
-    """
-    def __init__(self, coerce_doc=None):
-        self.coerce_doc = coerce_doc
-
-    def port_check(self, port, range_min=1024, range_max=65535):
-        """
-        Check that given ports are in the allowed range for an unprivileged
-        user.
-
-        :param port:
-            The port to check.
-        :param range_min:
-            The minimum allowable port number.
-        :param range_max:
-            The minimum allowable port number.
-        :param coerce_doc:
-            The documentation string to show in the optParameters menu, see
-            :class:`twisted.python.usage.Options`.
-        """
-        if self.coerce_doc is not None:
-            coerceDoc = self.coerce_doc
-
-        assert type(port) is int
-        if port not in range(range_min, range_max):
-            raise ValueError("Port out of range")
-            log.err()
-
-    @staticmethod
-    def uid_check(error_message):
-        """
-        Check that we're not root. If we are, setuid(1000) to normal user if
-        we're running on a posix-based system, and if we're on Windows just
-        tell the user that we can't be run as root with the specified options
-        and then exit.
-
-        :param error_message:
-            The string to log as an error message when the uid check fails.
-        """
-        uid, gid = os.getuid(), os.getgid()
-        if uid == 0 and gid == 0:
-            log.msg(error_message)
-        if os.name == 'posix':
-            log.msg("Dropping privileges to normal user...")
-            os.setgid(1000)
-            os.setuid(1000)
-        else:
-            sys.exit(0)
-
-    @staticmethod
-    def dir_check(d):
-        """Check that the given directory exists."""
-        if not os.path.isdir(d):
-            raise ValueError("%s doesn't exist, or has wrong permissions"
-                             % d)
-
-    @staticmethod
-    def file_check(f):
-        """Check that the given file exists."""
-        if not os.path.isfile(f):
-            raise ValueError("%s does not exist, or has wrong permissions"
-                             % f)
-
diff --git a/wtf/process.py b/wtf/process.py
deleted file mode 100644
index 25d6368..0000000
--- a/wtf/process.py
+++ /dev/null
@@ -1,73 +0,0 @@
-#
-# process.py
-# ----------
-# OONI utilities for dealing with starting and stopping processes.
-#
-# :author: Isis Lovecruft
-# :version: 0.1.0-pre-alpha
-# :license: see include LICENSE file
-# :copyright: copyright (c) 2012, Isis Lovecruft, The Tor Project Inc.
-# 
-
-from twisted.internet import defer
-
-@xxxxxxxxxxxxxxxxxxxxx
-def singleton_semaphore(deferred_process_init, 
-                        callbacks=[], errbacks=[],
-                        max_inits=1):
-    """
-    Initialize a process only once, and do not return until
-    that initialization is complete. If the keyword parameter max_inits=
-    is given, run the process a maximum of that number of times.
-
-    :param deferred_process_init:
-        A deferred which returns a connected process via
-        :meth:`twisted.internet.reactor.spawnProcess`.
-    :param callbacks:
-        A list of callback functions to add to the initialized processes'
-        deferred.
-    :param errbacks:
-        A list of errback functions to add to the initialized processes'
-        deferred.
-    :param max_inits:
-        An integer specifying the maximum number of allowed
-        initializations for :param:deferred_process_init. If no maximum
-        is given, only one instance (a singleton) of the process is
-        initialized.
-    :return:
-        The final state of the :param deferred_process_init: after the
-        callback chain has completed. This should be a fully initialized
-        process connected to a :class:`twisted.internet.reactor`.
-    """
-    assert isinstance(callbacks, list)
-    assert isinstance(errbacks, list)
-    assert isinstance(max_inits, int)
-
-    for cb in callbacks:
-        deferred_process_init.addCallback(cb)
-    for eb in errbacks:
-        deferred_process_init.addErrback(eb)
-
-    only_this_many = defer.DeferredSemaphore(max_inits)
-    singleton = yield only_this_many.run(deferred_process_init)
-    defer.returnValue(singleton)
-
-class Singleton(object):
-    """
-    Generic Class for creating Singleton subclasses.
-
-    Subclass me to create a singleton class, which will only ever have one
-    instance, regardless of how many times the subclass constructor is called.
-
-    Any subclass of me should override ``init`` rather than ``__init__``,
-    because the latter is called whenever the constructor is called.
-    """
-    def __new__(cls, *args, **kwds):
-        it = cls.__dict__.get("__it__")
-        if it is not None:
-            return it
-        cls.__it__ = it = object.__new__(cls)
-        it.init(*args, **kwds)
-        return it
-    def init(self, *args, **kwds):
-        pass



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits