[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Start defining the models of OONIB
commit 939973f15d39804bc3d62360a622436faf41430f
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date: Tue Nov 6 19:06:13 2012 +0100
Start defining the models of OONIB
* Create runner for OONIB
---
oonib/report/models.py | 122 ++++++++++++++++++++++++++++++++++++++++++++++++
oonib/runner.py | 25 ++++++++++
2 files changed, 147 insertions(+), 0 deletions(-)
diff --git a/oonib/report/models.py b/oonib/report/models.py
new file mode 100644
index 0000000..ddf79a3
--- /dev/null
+++ b/oonib/report/models.py
@@ -0,0 +1,122 @@
+__all__ = ['Report', 'TestHelperTMP']
+from storm.twisted.transact import transact
+from storm.locals import *
+
+from oonib.report.db import getStore, transactor
+
+def generateReportID():
+ size = 100
+ report_id = ''.join(random.choice(string.ascii_letters) for x in range(size))
+ return report_id
+
+class OModel(object):
+
+ transactor = transactor
+
+ def getStore(self):
+ return Store(database)
+
+ @transact
+ def create(self, query):
+ store = Store(database)
+ store.execute(query)
+ store.commit()
+
+ @transact
+ def save(self):
+ store = getStore()
+ store.add(self)
+ store.commit()
+
+class Report(OModel):
+ """
+ This represents an OONI Report as stored in the database.
+
+ report_id: this is generated by the backend and is used by the client to
+ reference a previous report and append to it. It should be
+ treated as a shared secret between the probe and backend.
+
+ software_name: this indicates the name of the software performing the test
+ (this will default to ooniprobe)
+
+ software_version: this is the version number of the software running the
+ test.
+
+ test_name: the name of the test on which the report is being created.
+
+ test_version: indicates the version of the test
+
+ progress: what is the current progress of the report. This allows clients
+ to report event partial reports up to a certain percentage of
+ progress. Once the report is complete progress will be 100.
+
+ content: what is the content of the report. If the current progress is less
+ than 100 we should append to the YAML data structure that is
+ currently stored in such field.
+ """
+ __storm_table__ = 'reports'
+
+ createQuery = "CREATE TABLE " + __storm_table__ +\
+ "(id INTEGER PRIMARY KEY, report_id VARCHAR, software_name VARCHAR,"\
+ "software_version VARCHAR, test_name VARCHAR, test_version VARCHAR,"\
+ "progress VARCHAR, content VARCHAR)"
+
+
+ id = Int(primary=True)
+
+ report_id = Unicode()
+
+ software_name = Unicode()
+ software_version = Unicode()
+ test_name = Unicode()
+ test_version = Unicode()
+ progress = Int()
+
+ content = Unicode()
+
+ @transact
+ def new(report):
+ store = self.getStore()
+
+ print "Creating new report %s" % report
+
+ report_id = generateReportID()
+ new_report = models.Report()
+ new_report.report_id = unicode(report_id)
+
+ new_report.software_name = report['software_name']
+ new_report.software_version = report['software_version']
+ new_report.test_name = report['test_name']
+ new_report.test_version = report['test_version']
+ new_report.progress = report['progress']
+
+ if 'content' in report:
+ new_report.content = report['content']
+
+ print "Report: %s" % report
+
+ store.add(new_report)
+ try:
+ store.commit()
+ except:
+ store.close()
+
+ defer.returnValue({'backend_version': backend_version, 'report_id':
+ report_id})
+
+
+class TestHelperTMP(OModel):
+ __storm_table__ = 'testhelpertmp'
+
+ createQuery = "CREATE TABLE " + __storm_table__ +\
+ "(id INTEGER PRIMARY KEY, report_id VARCHAR, test_helper VARCHAR,"\
+ " client_ip VARCHAR, creation_time VARCHAR)"
+
+ id = Int(primary=True)
+
+ report_id = Unicode()
+
+ test_helper = Unicode()
+ client_ip = Unicode()
+
+ creation_time = Date()
diff --git a/oonib/runner.py b/oonib/runner.py
new file mode 100644
index 0000000..febef46
--- /dev/null
+++ b/oonib/runner.py
@@ -0,0 +1,25 @@
+"""
+In here we define a runner for the oonib backend system.
+We are just extending the
+
+"""
+
+from twisted.application import service, internet, app
+from twisted.python.runtime import platformType
+
+from ooni.utils import log
+
+class OBaseRunner():
+ pass
+
+if platformType == "win32":
+ from twisted.scripts._twistw import ServerOptions, \
+ WindowsApplicationRunner
+
+ OBaseRunner = WindowsApplicationRunner
+else:
+ from twisted.scripts._twistd_unix import ServerOptions, \
+ UnixApplicationRunner
+ OBaseRunner = UnixApplicationRunner
+
+OBaseRunner.loggerFactory = log.LoggerFactory
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits