svn merge -r 12308:13112 https://svn.planet-lab.org/svn/Monitor/branches/2.0/
[monitor.git] / monitor / database / info / __init__.py
1 try:
2         import pkg_resources
3         pkg_resources.require("SQLAlchemy>=0.4.9")
4         pkg_resources.require("Elixir>=0.4.0")
5         ## NOTE!!!!!!
6         # with this line enabled, other models cannot import this file.
7         # it results in the wrong metadata value being loaded, I think.
8         #from turbogears.database import metadata, mapper
9
10         #import pkg_resources
11         #pkg_resources.require("SQLObject>=0.7.1")
12         #from turbogears.database import PackageHub, AutoConnectHub
13         #from turbogears import config
14         #uri = config.get("sqlobject.dburi")
15         #from sqlobject import connectionForURI,sqlhub
16         #sqlhub.processConnection = connectionForURI(uri)
17
18 except:
19         # NOTE:  this try, will allow external modules to import the model without
20         # requring the turbogears garbage.
21         import traceback
22         print traceback.print_exc()
23         pass
24
25 from elixir import Entity, Field, OneToMany, ManyToOne, ManyToMany
26 from elixir import options_defaults, using_options, setup_all
27 from elixir import String, Unicode, Integer, DateTime
28 options_defaults['autosetup'] = False
29 # NOTE: due to the module path length, this is required.
30 options_defaults['shortnames'] = True
31
32 from monitor.database.dborm import mon_metadata, mon_session
33 __metadata__ = mon_metadata
34 __session__  = mon_session
35
36 def findby_or_create(cls, if_new_set={}, **kwargs):
37         result = cls.get_by(**kwargs)
38         if not result:
39                 result = cls(**kwargs)
40                 result.set(**if_new_set)
41         return result
42 Entity.findby_or_create = classmethod(findby_or_create)
43
44 from monitor.database.info.action import *
45 from monitor.database.info.findbad import *
46 from monitor.database.info.history import *
47 from monitor.database.info.plc import *
48 setup_all()