1 """
2 DataBase interface
3
4 Using mongoDB
5
6 @copyright: (c) 2011 hackmeeting U{http://sindominio.net/hackmeeting}
7 @author: Ruben Pollan
8 @organization: hackmeeting U{http://sindominio.net/hackmeeting}
9 @contact: meskio@sindominio.net
10 @license:
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the Do What The Fuck You Want To
13 Public License, Version 2, as published by Sam Hocevar. See
14 U{http://sam.zoy.org/projects/COPYING.WTFPL} for more details.
15 """
16
17 import pymongo
18 import logging
19
20
22 """
23 Database class
24
25 It is a singleton class, so any instantion of it will get the global
26 database.
27 """
28
29 __ = {}
30
33
34 - def connect(self, host, port, name):
35 """
36 Connect to a mongoDB database
37
38 That method must be call before any use of the database
39 @type name: string
40 @param name: database name
41 """
42 logging.info(_("[core] connect to database"))
43 self.__['conn'] = pymongo.Connection(host, port)
44 self.__['db'] = self.__['conn'][name]
45
47 """
48 Get a database collection
49
50 @type coll: string
51 @param coll: coll name
52 @returns: mongoDb collection
53 """
54 return self.__['db'][coll]
55
57 """
58 Get the core collection
59
60 The collection use by the core of emma
61 @returns: mongoDb collection
62 """
63 return self.collection('core')
64