X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fstorage%2Falchemy.py;h=e9f96dd6875f42ea4962f8e36cfd63fdf51e41a8;hb=1cc8e9613cab8b5b22478de369f259e591c54e6d;hp=ead5219df37c47330869bc3296c4c28f5693994d;hpb=6f0a757c5adf47b4d222cec09514dcd688b93457;p=sfa.git diff --git a/sfa/storage/alchemy.py b/sfa/storage/alchemy.py index ead5219d..e9f96dd6 100644 --- a/sfa/storage/alchemy.py +++ b/sfa/storage/alchemy.py @@ -4,13 +4,12 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import Column, Integer, String -from sqlalchemy.orm import relationship, backref from sqlalchemy import ForeignKey from sfa.util.sfalogging import logger # this module is designed to be loaded when the configured db server is reachable -# OTOH persistentobjs can be loaded from anywhere including the client-side +# OTOH model can be loaded from anywhere including the client-side class Alchemy: @@ -25,21 +24,23 @@ class Alchemy: # we indeed have /var/lib/pgsql/data/postgresql.conf where # this setting is unset, it might be an angle to tweak that if need be # try a unix socket first - omitting the hostname does the trick - unix_desc = "postgresql+psycopg2://%s:%s@:%s/%s"%\ + unix_url = "postgresql+psycopg2://%s:%s@:%s/%s"%\ (config.SFA_DB_USER,config.SFA_DB_PASSWORD,config.SFA_DB_PORT,dbname) # the TCP fallback method - tcp_desc = "postgresql+psycopg2://%s:%s@%s:%s/%s"%\ + tcp_url = "postgresql+psycopg2://%s:%s@%s:%s/%s"%\ (config.SFA_DB_USER,config.SFA_DB_PASSWORD,config.SFA_DB_HOST,config.SFA_DB_PORT,dbname) - for engine_desc in [ unix_desc, tcp_desc ] : + for url in [ unix_url, tcp_url ] : try: - self.engine = create_engine (engine_desc) + logger.debug("Trying db URL %s"%url) + self.engine = create_engine (url) self.check() + self.url=url return except: pass self.engine=None - raise Exception,"Could not connect to database" - + raise Exception,"Could not connect to database %s as %s with psycopg2"%(dbname,config.SFA_DB_USER) + # expects boolean True: debug is ON or False: debug is OFF def debug (self, echo): @@ -59,23 +60,6 @@ class Alchemy: self._session.close() self._session=None - def commit (self): - self.session().commit() - - def insert (self, stuff, commit=False): - if isinstance (stuff,list): - self.session().add_all(stuff) - else: - self.session().add(obj) - - # for compat with the previous PostgreSQL stuff - def update (self, record): - self.commit() - - def remove (self, record): - self.delete(record) - self.commit() - #################### from sfa.util.config import Config