[tor-commits] [oonib/master] Normalize pluralization, use sha256 for input name

art at torproject.org art at torproject.org
Wed Sep 11 09:13:52 UTC 2013


commit 7d753791abef68c3cbbaf390b7ae92c01f1a56a8
Author: aagbsn <aagbsn at extc.org>
Date:   Sun Aug 18 23:11:05 2013 +0200

    Normalize pluralization, use sha256 for input name
    
    Use the same pluralization semantics as the /deck api,
    and use sha256 hexdigest filename as specified in oonib.md
---
 oonib.conf.example       |    2 +-
 oonib/api.py             |    6 +++---
 oonib/input/api.py       |   10 ++++++++++
 oonib/input/handlers.py  |   41 +++++++++++++++++++++++++++++++++++++++++
 oonib/inputs/api.py      |   10 ----------
 oonib/inputs/handlers.py |   41 -----------------------------------------
 6 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/oonib.conf.example b/oonib.conf.example
index 36df0e3..977b5dc 100644
--- a/oonib.conf.example
+++ b/oonib.conf.example
@@ -1,7 +1,7 @@
 main:
     report_dir: data/reports/
     archive_dir: data/archive/
-    inputs_dir: data/inputs/
+    input_dir: data/inputs/
     deck_dir: data/decks/
     policy_file: data/policy.yaml
     bouncer_file: data/bouncer.yaml
diff --git a/oonib/api.py b/oonib/api.py
index 775c4ad..384b949 100644
--- a/oonib/api.py
+++ b/oonib/api.py
@@ -2,7 +2,7 @@ from cyclone import web
 
 from oonib.deck.api import deckAPI
 from oonib.report.api import reportAPI
-from oonib.inputs.api import inputsAPI
+from oonib.input.api import inputAPI
 from oonib.policy.api import policyAPI
 from oonib.bouncer.api import bouncerAPI
 
@@ -11,8 +11,8 @@ from oonib import config
 ooniBackendAPI = []
 ooniBackendAPI += reportAPI
 
-if config.main.inputs_dir:
-    ooniBackendAPI += inputsAPI
+if config.main.input_dir:
+    ooniBackendAPI += inputAPI
 
 if config.main.deck_dir:
     ooniBackendAPI += deckAPI
diff --git a/oonib/input/__init__.py b/oonib/input/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/oonib/input/api.py b/oonib/input/api.py
new file mode 100644
index 0000000..88d85a2
--- /dev/null
+++ b/oonib/input/api.py
@@ -0,0 +1,10 @@
+from cyclone import web
+from oonib.input import handlers
+from oonib import config
+
+inputAPI = [
+    (r"/input", handlers.InputListHandler),
+    (r"/input/([a-f0-9]{64})", handlers.InputDescHandler),
+    (r"/input/([a-f0-9]{64})/file$", web.StaticFileHandler, {"path":
+        config.main.input_dir}),
+]
diff --git a/oonib/input/handlers.py b/oonib/input/handlers.py
new file mode 100644
index 0000000..3ab0ea0
--- /dev/null
+++ b/oonib/input/handlers.py
@@ -0,0 +1,41 @@
+import glob
+import json
+import os
+
+import yaml
+
+from oonib.handlers import OONIBHandler
+
+from oonib import config
+
+class InputDescHandler(OONIBHandler):
+    def get(self, inputID):
+        #XXX return the input descriptor
+        # see oonib.md in ooni-spec
+        bn = os.path.basename(inputID) + ".desc"
+        try:
+            f = open(os.path.join(config.main.input_dir, bn))
+            a = {}
+            inputDesc = yaml.safe_load(f)
+            a['id'] = inputID
+            a['name'] = inputDesc['name']
+            a['description'] = inputDesc['description']
+            self.write(json.dumps(a))
+        except Exception:
+            log.err("No Input Descriptor found for id %s" % inputID) 
+
+class InputListHandler(OONIBHandler):
+    def get(self):
+        path = os.path.abspath(config.main.input_dir) + "/*.desc"
+        inputnames = map(os.path.basename, glob.iglob(path))
+        inputList = []
+        for inputname in inputnames:
+            f = open(os.path.join(config.main.input_dir, inputname))
+            d = yaml.safe_load(f)
+            inputList.append({
+                'id': inputname,
+                'name': d['name'],
+                'description': d['description']
+            })
+            f.close()
+        self.write(json.dumps(inputList))
diff --git a/oonib/inputs/__init__.py b/oonib/inputs/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/oonib/inputs/api.py b/oonib/inputs/api.py
deleted file mode 100644
index bfcf076..0000000
--- a/oonib/inputs/api.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from cyclone import web
-from oonib.inputs import handlers
-from oonib import config
-
-inputsAPI = [
-    (r"/inputs", handlers.InputsListHandler),
-    (r"/inputs/([a-f0-9]{64})", handlers.InputsDescHandler),
-    (r"/inputs/([a-f0-9]{64})/file$", web.StaticFileHandler, {"path":
-        config.main.inputs_dir}),
-]
diff --git a/oonib/inputs/handlers.py b/oonib/inputs/handlers.py
deleted file mode 100644
index 373e275..0000000
--- a/oonib/inputs/handlers.py
+++ /dev/null
@@ -1,41 +0,0 @@
-import glob
-import json
-import os
-
-import yaml
-
-from oonib.handlers import OONIBHandler
-
-from oonib import config
-
-class InputsDescHandler(OONIBHandler):
-    def get(self, inputID):
-        #XXX return the input descriptor
-        # see oonib.md in ooni-spec
-        bn = os.path.basename(inputID) + ".desc"
-        try:
-            f = open(os.path.join(config.main.inputs_dir, bn))
-            a = {}
-            inputDesc = yaml.safe_load(f)
-            a['id'] = inputID
-            a['name'] = inputDesc['name']
-            a['description'] = inputDesc['description']
-            self.write(json.dumps(a))
-        except Exception:
-            log.err("No Input Descriptor found for id %s" % inputID) 
-
-class InputsListHandler(OONIBHandler):
-    def get(self):
-        path = os.path.abspath(config.main.inputs_dir) + "/*.desc"
-        inputnames = map(os.path.basename, glob.iglob(path))
-        inputList = []
-        for inputname in inputnames:
-            f = open(os.path.join(config.main.inputs_dir, inputname))
-            d = yaml.safe_load(f)
-            inputList.append({
-                'id': inputname,
-                'name': d['name'],
-                'description': d['description']
-            })
-            f.close()
-        self.write(json.dumps(inputList))





More information about the tor-commits mailing list