commit 683bbc695af313e1eba36bd3d9698eec17fca8cb Author: Arturo Filastò art@fuffa.org Date: Fri Aug 16 21:38:24 2013 +0200
Get the thing to actually start.
Misc bugfixes and retested the requirements.txt --- oonib/__init__.py | 63 +++++++++++++++++++++++++++++++++++++++++++++ oonib/api.py | 19 ++++---------- oonib/bouncer/handlers.py | 4 ++- oonib/deck/handlers.py | 2 +- oonib/handlers.py | 7 +++++ oonib/inputs/api.py | 2 +- oonib/inputs/handlers.py | 2 +- oonib/policy/handlers.py | 2 +- oonib/report/handlers.py | 4 +-- oonib/runner.py | 14 ++++------ requirements.txt | 20 +------------- 11 files changed, 89 insertions(+), 50 deletions(-)
diff --git a/oonib/__init__.py b/oonib/__init__.py new file mode 100644 index 0000000..54d3006 --- /dev/null +++ b/oonib/__init__.py @@ -0,0 +1,63 @@ +""" +In here we shall keep track of all variables and objects that should be +instantiated only once and be common to pieces of GLBackend code. +""" + +__version__ = '0.9.1' + +__all__ = ['Storage', 'randomStr'] + +import string +import random + +class Storage(dict): + """ + A Storage object is like a dictionary except `obj.foo` can be used + in addition to `obj['foo']`. + + >>> o = Storage(a=1) + >>> o.a + 1 + >>> o['a'] + 1 + >>> o.a = 2 + >>> o['a'] + 2 + >>> del o.a + >>> o.a + None + """ + def __getattr__(self, key): + try: + return self[key] + except KeyError, k: + return None + + def __setattr__(self, key, value): + self[key] = value + + def __delattr__(self, key): + try: + del self[key] + except KeyError, k: + raise AttributeError, k + + def __repr__(self): + return '<Storage ' + dict.__repr__(self) + '>' + + def __getstate__(self): + return dict(self) + + def __setstate__(self, value): + for (k, v) in value.items(): + self[k] = v + +def randomStr(length, num=True): + """ + Returns a random a mixed lowercase, uppercase, alfanumerical (if num True) + string long length + """ + chars = string.ascii_lowercase + string.ascii_uppercase + if num: + chars += string.digits + return ''.join(random.choice(chars) for x in range(length)) diff --git a/oonib/api.py b/oonib/api.py index ce682fc..48c2e1e 100644 --- a/oonib/api.py +++ b/oonib/api.py @@ -1,31 +1,22 @@ -from cyclone import web - from oonib.deck.api import deckAPI +from oonib.report.api import reportAPI from oonib.inputs.api import inputsAPI from oonib.policy.api import policyAPI from oonib.bouncer.api import bouncerAPI
from oonib import config
-class OONIBHandler(web.RequestHandler): - pass - -class OONIBError(web.HTTPError): - pass - oonibAPI = [] oonibAPI += reportAPI
-if config.inputs_dir: +if config.main.inputs_dir: oonibAPI += inputsAPI
-if config.deck_dir: +if config.main.deck_dir: oonibAPI += deckAPI
-if config.policy_file: +if config.main.policy_file: oonibAPI += policyAPI
-if config.bouncer_file: +if config.main.bouncer_file: oonibAPI += bouncerAPI - - diff --git a/oonib/bouncer/__init__.py b/oonib/bouncer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oonib/bouncer/handlers.py b/oonib/bouncer/handlers.py index f2249dd..90651b0 100644 --- a/oonib/bouncer/handlers.py +++ b/oonib/bouncer/handlers.py @@ -1,4 +1,6 @@ -class BouncerQueryHandler(web.RequestHandler): +from oonib.handlers import OONIBHandler + +class BouncerQueryHandler(OONIBHandler): def get(self): #XXX unused pass diff --git a/oonib/deck/__init__.py b/oonib/deck/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oonib/deck/handlers.py b/oonib/deck/handlers.py index 97b390a..edbe361 100644 --- a/oonib/deck/handlers.py +++ b/oonib/deck/handlers.py @@ -1,4 +1,4 @@ -from oonib.api import OONIBHandler +from oonib.handlers import OONIBHandler
class DeckDescHandler(OONIBHandler): def get(self, deckID): diff --git a/oonib/handlers.py b/oonib/handlers.py new file mode 100644 index 0000000..62496ce --- /dev/null +++ b/oonib/handlers.py @@ -0,0 +1,7 @@ +from cyclone import web + +class OONIBHandler(web.RequestHandler): + pass + +class OONIBError(web.HTTPError): + pass diff --git a/oonib/inputs/__init__.py b/oonib/inputs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oonib/inputs/api.py b/oonib/inputs/api.py index 53342ae..d74c23c 100644 --- a/oonib/inputs/api.py +++ b/oonib/inputs/api.py @@ -1,5 +1,5 @@ from cyclone import web -from oonib.input import handlers +from oonib.inputs import handlers from oonib import config
inputsAPI = [ diff --git a/oonib/inputs/handlers.py b/oonib/inputs/handlers.py index 5391881..a1ed80d 100644 --- a/oonib/inputs/handlers.py +++ b/oonib/inputs/handlers.py @@ -1,4 +1,4 @@ -from oonib.api import OONIBHandler +from oonib.handlers import OONIBHandler
from oonib import config
diff --git a/oonib/policy/__init__.py b/oonib/policy/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oonib/policy/handlers.py b/oonib/policy/handlers.py index ee6f089..7544cf9 100644 --- a/oonib/policy/handlers.py +++ b/oonib/policy/handlers.py @@ -1,4 +1,4 @@ -from oonib.api import OONIBHandler +from oonib.handlers import OONIBHandler
from oonib import config import json diff --git a/oonib/report/__init__.py b/oonib/report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oonib/report/handlers.py b/oonib/report/handlers.py index 681d7d1..05949e6 100644 --- a/oonib/report/handlers.py +++ b/oonib/report/handlers.py @@ -3,7 +3,7 @@ import string import time import yaml
-from oonib.api import OONIBHandler +from oonib.handlers import OONIBHandler
from datetime import datetime from oonib import randomStr, otime, config, log @@ -12,8 +12,6 @@ from twisted.internet import fdesc, reactor class MissingField(Exception): pass
-from oonib import randomStr -from oonib import otime class InvalidRequestField(Exception): pass
diff --git a/oonib/runner.py b/oonib/runner.py index 3bb064e..10f2bef 100644 --- a/oonib/runner.py +++ b/oonib/runner.py @@ -21,10 +21,6 @@ from txtorcon import TCPHiddenServiceEndpoint, TorConfig from txtorcon import launch_tor
from oonib.report.api import reportAPI -from oonib.deck.api import deckAPI -from oonib.inputs.api import inputsAPI -from oonib.policy.api import policyAPI -from oonib.bouncer.api import bouncerAPI from oonib.api import oonibAPI
from oonib import oonibackend @@ -47,11 +43,6 @@ def setupCollector(tor_process_protocol): print("Exposed collector Tor hidden service on httpo://%s" % port.onion_uri)
- tempfile.tempdir = os.path.join(_repo_dir, 'tmp') - if not os.path.isdir(tempfile.gettempdir()): - os.makedirs(tempfile.gettempdir()) - _temp_dir = tempfile.mkdtemp() - torconfig = TorConfig(tor_process_protocol.tor_protocol) public_port = 80 # XXX there is currently a bug in txtorcon that prevents data_dir from @@ -70,6 +61,11 @@ def startTor(): def updates(prog, tag, summary): print("%d%%: %s" % (prog, summary))
+ tempfile.tempdir = os.path.join(_repo_dir, 'tmp') + if not os.path.isdir(tempfile.gettempdir()): + os.makedirs(tempfile.gettempdir()) + _temp_dir = tempfile.mkdtemp() + torconfig = TorConfig() torconfig.SocksPort = config.main.socks_port if config.main.tor2webmode: diff --git a/requirements.txt b/requirements.txt index 08fd114..d7921fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,22 +1,4 @@ --i https://pypi.python.org/packages -## -## The above line replaces pip's default package index, and this line is -## removed from the .requirements.travis file, due to its incompatibility -## with the '--use-mirrors' option that TravisCI recommends. -## -## The URLs in this file which have been commented out are due to a design -## problem in pip-1.3.0, where it ships with a default package index of -## 'https://pypi.python.org/simple', which though *it* was over SSL as -## promised, it still crawled the links on a module's PyPI page, which contains -## arbitrary links, such as project homepages, created by the PyPI maintainer -## of the module. see -## -## https://github.com/TheTorProject/ooni-backend/pull/1#discussion_r4084881 for -## a detailed description of the problem, and why these links may still be -## useful until pip is updated again. -## -PyYAML>=3.10 -#https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.10.tar.gz#md5=74c9... +PyYaml Twisted>=12.2.0 #https://pypi.python.org/packages/source/T/Twisted/Twisted-13.0.0.tar.bz2#md5... cyclone>=1.1
tor-commits@lists.torproject.org