def setUp(self): self.mojology = Mojology(config_object="mojology.tests.TestConfig") self.app = self.mojology.test_client() self.db = pymongo.Connection(TestConfig.MONGO_HOST, TestConfig.MONGO_PORT) self.coll = self.db[TestConfig.MONGO_DB][TestConfig.MONGO_COLLECTION] self.pagesize = TestConfig.MOJOLOGY_PAGESIZE self.cache = TestConfig.MOJOLOGY_COLLECTION_PREFIX self.layout = TestConfig.MOJOLOGY_LAYOUT self.coll.drop()
def setUp (self): self.mojology = Mojology (config_object = "mojology.tests.TestConfig") self.app = self.mojology.test_client () self.db = pymongo.Connection (TestConfig.MONGO_HOST, TestConfig.MONGO_PORT) self.coll = self.db[TestConfig.MONGO_DB][TestConfig.MONGO_COLLECTION] self.pagesize = TestConfig.MOJOLOGY_PAGESIZE self.cache = TestConfig.MOJOLOGY_COLLECTION_PREFIX self.layout = TestConfig.MOJOLOGY_LAYOUT self.coll.drop ()
class TestCase(unittest.TestCase): def setUp(self): self.mojology = Mojology(config_object="mojology.tests.TestConfig") self.app = self.mojology.test_client() self.db = pymongo.Connection(TestConfig.MONGO_HOST, TestConfig.MONGO_PORT) self.coll = self.db[TestConfig.MONGO_DB][TestConfig.MONGO_COLLECTION] self.pagesize = TestConfig.MOJOLOGY_PAGESIZE self.cache = TestConfig.MOJOLOGY_COLLECTION_PREFIX self.layout = TestConfig.MOJOLOGY_LAYOUT self.coll.drop() def populate(self): fp = open(os.path.join(os.path.dirname(__file__), "test_data.json")) for line in fp: j = json.loads(line, object_hook=bson.json_util.object_hook) self.coll.insert(j) def _mr(self, map_js, out): self.coll.map_reduce( map_js, "function (k, vals) { var sum = { count: 0 }; for (var i in vals) sum.count += vals[i].count; return sum; }", out=self.cache + 'mr.' + out, finalize= "function (who, res) { res.stamp = new Date(); return res; }") def do_mapreduce(self): self._mr( "function () { emit(this.%s, { count: 1 }); }" % self.layout.fields['program'], "programs") self._mr( "function () { emit(this.%s, { count: 1 }); }" % self.layout.fields['host'], "hosts") self._mr( "function () { d = new Date (this.%s*1000); d.setMinutes(0); d.setSeconds(0); emit(d.valueOf()/1000, { count: 1 }); }" % self.layout.fields['date'], "time") def tearDown(self): self.db[TestConfig.MONGO_DB][self.cache + 'mr.programs'].drop() self.db[TestConfig.MONGO_DB][self.cache + 'mr.hosts'].drop() self.db[TestConfig.MONGO_DB][self.cache + 'mr.time'].drop() self.coll.drop() self.db.disconnect()
class TestCase (unittest.TestCase): def setUp (self): self.mojology = Mojology (config_object = "mojology.tests.TestConfig") self.app = self.mojology.test_client () self.db = pymongo.Connection (TestConfig.MONGO_HOST, TestConfig.MONGO_PORT) self.coll = self.db[TestConfig.MONGO_DB][TestConfig.MONGO_COLLECTION] self.pagesize = TestConfig.MOJOLOGY_PAGESIZE self.cache = TestConfig.MOJOLOGY_COLLECTION_PREFIX self.layout = TestConfig.MOJOLOGY_LAYOUT self.coll.drop () def populate (self): fp = open (os.path.join (os.path.dirname (__file__), "test_data.json")) for line in fp: j = json.loads (line, object_hook = bson.json_util.object_hook) self.coll.insert (j) def _mr (self, map_js, out): self.coll.map_reduce (map_js, "function (k, vals) { var sum = { count: 0 }; for (var i in vals) sum.count += vals[i].count; return sum; }", out = self.cache + 'mr.' + out, finalize = "function (who, res) { res.stamp = new Date(); return res; }") def do_mapreduce (self): self._mr ("function () { emit(this.%s, { count: 1 }); }" % self.layout.fields['program'], "programs") self._mr ("function () { emit(this.%s, { count: 1 }); }" % self.layout.fields['host'], "hosts") self._mr ("function () { d = new Date (this.%s*1000); d.setMinutes(0); d.setSeconds(0); emit(d.valueOf()/1000, { count: 1 }); }" % self.layout.fields['date'], "time") def tearDown (self): self.db[TestConfig.MONGO_DB][self.cache + 'mr.programs'].drop () self.db[TestConfig.MONGO_DB][self.cache + 'mr.hosts'].drop () self.db[TestConfig.MONGO_DB][self.cache + 'mr.time'].drop () self.coll.drop () self.db.disconnect ()
## 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/>. from mojology import Mojology import os, sys from werkzeug.wsgi import DispatcherMiddleware if len (sys.argv) > 1: cfg_file = os.path.realpath (sys.argv[1]) if not os.path.exists (cfg_file): cfg_file = None else: cfg_file = os.path.realpath (os.path.join (os.path.dirname (__file__), "local_settings.py")) if not os.path.exists (cfg_file): cfg_file = None app = Mojology (config_file = cfg_file) sites = {} for site in sys.argv[2:]: sapp = Mojology (config_file = os.path.realpath (site)) if not "MOJOLOGY_SITE_ROOT" in sapp.config: raise SyntaxError, "'%s' does not set MOJOLOGY_SITE_ROOT" % site sites[sapp.config['MOJOLOGY_SITE_ROOT']] = sapp.wsgi_app app.wsgi_app = DispatcherMiddleware (app.wsgi_app, sites) app.run ()
## 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/>. from mojology import Mojology import pymongo import os cfg_file = os.path.realpath( os.path.join(os.path.dirname(__file__), "local_settings.py")) if not os.path.exists(cfg_file): cfg_file = None m = Mojology(config_file=cfg_file) conn = pymongo.Connection(m.config['MONGO_HOST'], m.config['MONGO_PORT']) db = conn[m.config['MONGO_DB']] try: db.authenticate(m.config['MONGO_USER'], m.config['MONGO_PASS']) except: pass coll = db[m.config['MONGO_COLLECTION']] cache = m.config['MOJOLOGY_COLLECTION_PREFIX'] layout = m.config['MOJOLOGY_LAYOUT'] def mr(map_js, out): coll.map_reduce( map_js,