Skip to content

Commit

Permalink
Merge pull request #196 from grycap/devel
Browse files Browse the repository at this point in the history
Init DB correctly
  • Loading branch information
micafer committed Jan 27, 2017
2 parents 790bc1d + 71d4fe0 commit a1b81bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions IM/InfrastructureList.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,27 @@ def save_data(inf_id=None):
sys.stderr.write("ERROR saving data: " + str(ex) + ".\nChanges not stored!!")

@staticmethod
def _get_data_from_db(db_url, inf_id=None):
db = DataBase(db_url)
def init_table():
""" Creates de database """
db = DataBase(Config.DATA_DB)
if db.connect():
if not db.table_exists("inf_list"):
db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER,"
" date TIMESTAMP, data LONGBLOB)")
db.close()
return {}
else:
return True
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")

return False

@staticmethod
def _get_data_from_db(db_url, inf_id=None):
if InfrastructureList.init_table():
return {}
else:
db = DataBase(db_url)
if db.connect():
inf_list = {}
if inf_id:
res = db.select("select * from inf_list where id = '%s'" % inf_id)
Expand All @@ -149,9 +161,9 @@ def _get_data_from_db(db_url, inf_id=None):

db.close()
return inf_list
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")
return {}
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")
return {}

@staticmethod
def _save_data_to_db(db_url, inf_list, inf_id=None):
Expand Down
2 changes: 2 additions & 0 deletions im_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def launch_daemon():
"""
Launch the IM daemon
"""
InfrastructureList.init_table()

if Config.XMLRCP_SSL:
# if specified launch the secure version
import ssl
Expand Down

0 comments on commit a1b81bd

Please sign in to comment.