Index: trunk/Monitoring/smon/__init__.py
===================================================================
--- trunk/Monitoring/smon/__init__.py	(revision 866)
+++ trunk/Monitoring/smon/__init__.py	(revision 871)
@@ -11,2 +11,7 @@
 # @license        CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE)
 ##################################
+
+
+# HACK
+import sys
+sys.path.append("/home/jripsl/snapshot/Monitoring")
Index: trunk/Monitoring/smon/local_repo.py
===================================================================
--- trunk/Monitoring/smon/local_repo.py	(revision 866)
+++ trunk/Monitoring/smon/local_repo.py	(revision 871)
@@ -14,4 +14,6 @@
 import sys
 import sqlite3
+
+import types
 
 _conn=None
@@ -39,6 +41,29 @@
 
 def create_tables():
+
 	_conn.execute("create table simulation (id INTEGER PRIMARY KEY, name TEXT)")
+	_conn.execute("create unique index idx_simulation on simulation (name)")
+
 	_conn.execute("create table message (id INTEGER PRIMARY KEY, simulation_id TEXT)") # TODO: check how to use INT datatype for simulation_id column
+
+def populate_tables_with_sample():
+
+	rows = [('SIMU-001',),
+			('SIMU-002',),
+			('SIMU-003',),]
+	_conn.executemany('INSERT INTO simulation (name) VALUES (?)', rows)
+
+def retrieve_simulations():
+	li=[]
+	c=_conn.cursor()
+
+	c.execute("select name,id from simulation")
+
+	rs=c.fetchone()
+	while rs is not None:
+		li.append(types.Simulation(name=rs[0],id=rs[1]))
+		rs=c.fetchone()
+
+	return li
 
 def retrieve_simulation(name):
@@ -52,5 +77,5 @@
 		raise Exception()
 
-	return smon.types.Simulation(id=rs[1])
+	return types.Simulation(id=rs[1])
     
 def delete_simulation(simulation):
@@ -72,5 +97,5 @@
 	rs=c.fetchone()
 	while rs is not None:
-		li.append(smon.types.Message(id=rs[0]))
+		li.append(types.Message(id=rs[0]))
 		rs=c.fetchone()
 
@@ -93,3 +118,3 @@
 		raise Exception()
 
-	return smon.types.Message(id=rs[0])
+	return types.Message(id=rs[0])
Index: trunk/Monitoring/smon/repo_io.py
===================================================================
--- trunk/Monitoring/smon/repo_io.py	(revision 866)
+++ trunk/Monitoring/smon/repo_io.py	(revision 871)
@@ -31,237 +31,5 @@
 
 
-# -- methods -- #
-
-def init():
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.connect()
-	elif mode==CSTE_MODE_REMOTE_REPO:
-		_CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer"
-		prodiguer_shared.connect(_CONNECTION)
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR004 - incorrect mode")
-
-def free():
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.close()
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		#prodiguer_shared.close()
-		pass
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR009 - incorrect mode")
-
-def test():
-	repo.create_message("test2", 2, "bla2")
-	commit()
-
-	repo.update_simulation_status('1pctCO22', 'ERROR')
-	commit()
-
-	repo.create_message("test3", 3, "bla3")
-	rollback()
-
-def commit():
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.commit()
-	elif mode==CSTE_MODE_REMOTE_REPO:
-		elixir.session.commit()
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR002 - incorrect mode")
-
-def rollback():
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.rollback()
-	elif mode==CSTE_MODE_REMOTE_REPO:
-		elixir.session.rollback()
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR003 - incorrect mode")
-
-def retrieve_simulation(name):
-	simulation=None
-
-	if mode==CSTE_MODE_LOCAL_REPO:
-		simulation=repo.retrieve_simulation(name)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		s=repo.retrieve_simulation(name)
-
-		# process return values
-		simulation=smon.types.Simulation(exec_start_date=s.ExecutionStartDate,exec_end_date=s.ExecutionEndDate,status=s.ExecutionState) # ExecutionState example: EXECUTION_STATE_RUNNING, EXECUTION_STATE_SET..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR014 - incorrect mode")
-
-	return simulation
-
-def delete_simulation(name):
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.delete_simulation(name)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.delete_simulation(name)
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR015 - incorrect mode")
-
-def create_simulation(simulation):
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.create_simulation(simulation)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.create_simulation(activity)
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR016 - incorrect mode")
-
-def update_simulation_status(simulation):
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.update_simulation_status(simulation)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.update_simulation_status(name)
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR017 - incorrect mode")
-
-def retrieve_messages(simulation):
-	message=None
-
-	if mode==CSTE_MODE_LOCAL_REPO:
-		message=repo.retrieve_messages(simulation)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.retrieve_messages(name)
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR018 - incorrect mode")
-
-	return message
-
-def delete_messages(simulation):
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.delete_messages(name)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.delete_messages(name)
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR019 - incorrect mode")
-
-def create_message(message):
-	if mode==CSTE_MODE_LOCAL_REPO:
-		repo.create_message(message)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.create_message()
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR020 - incorrect mode")
-
-def retrieve_last_message(simulation):
-	message=None
-
-	if mode==CSTE_MODE_LOCAL_REPO:
-		message=repo.retrieve_last_message(simulation)
-	elif mode==CSTE_MODE_REMOTE_REPO:
-
-		# prepare args
-		# ..
-
-		# execute
-		repo.retrieve_last_message(simulation)
-
-		# process return values
-		# ..
-
-	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
-		pass
-	else:
-		raise Exception("ERR021 - incorrect mode")
-
-	return message
-
-
-# --- higher level methods --- #
-
-def get_running_simulations():
-	running_simulation=[]
-
-	for s in retrieve_simulation():
-		if s.status=="running":
-			running_simulation.append(s)
-			
-	return running_simulation
-
-
-# --- module init --- #
+# --- module static initialization --- #
 
 CSTE_MODE_LOCAL_REPO="local_repo"
@@ -283,5 +51,244 @@
 
 
-# note that by putting init() call here, it will only be called when first imported by the first import statement
-init()
-
+
+
+
+
+# -- methods -- #
+
+def init():
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.connect()
+	elif mode==CSTE_MODE_REMOTE_REPO:
+		_CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer"
+		prodiguer_shared.connect(_CONNECTION)
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR004 - incorrect mode")
+
+def free():
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.free()
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		#prodiguer_shared.close()
+		pass
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR009 - incorrect mode")
+
+def populate_tables_with_sample():
+	repo.populate_tables_with_sample()
+
+def retrieve_simulations():
+	return repo.retrieve_simulations()
+
+def test():
+	repo.create_message("test2", 2, "bla2")
+	commit()
+
+	repo.update_simulation_status('1pctCO22', 'ERROR')
+	commit()
+
+	repo.create_message("test3", 3, "bla3")
+	rollback()
+
+def commit():
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.commit()
+	elif mode==CSTE_MODE_REMOTE_REPO:
+		elixir.session.commit()
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR002 - incorrect mode")
+
+def rollback():
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.rollback()
+	elif mode==CSTE_MODE_REMOTE_REPO:
+		elixir.session.rollback()
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR003 - incorrect mode")
+
+def retrieve_simulation(name):
+	simulation=None
+
+	if mode==CSTE_MODE_LOCAL_REPO:
+		simulation=repo.retrieve_simulation(name)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		s=repo.retrieve_simulation(name)
+
+		# process return values
+		simulation=smon.types.Simulation(exec_start_date=s.ExecutionStartDate,exec_end_date=s.ExecutionEndDate,status=s.ExecutionState) # ExecutionState example: EXECUTION_STATE_RUNNING, EXECUTION_STATE_SET..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR014 - incorrect mode")
+
+	return simulation
+
+def delete_simulation(name):
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.delete_simulation(name)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.delete_simulation(name)
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR015 - incorrect mode")
+
+def create_simulation(simulation):
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.create_simulation(simulation)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.create_simulation(activity)
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR016 - incorrect mode")
+
+def update_simulation_status(simulation):
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.update_simulation_status(simulation)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.update_simulation_status(name)
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR017 - incorrect mode")
+
+def retrieve_messages(simulation):
+	message=None
+
+	if mode==CSTE_MODE_LOCAL_REPO:
+		message=repo.retrieve_messages(simulation)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.retrieve_messages(name)
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR018 - incorrect mode")
+
+	return message
+
+def delete_messages(simulation):
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.delete_messages(name)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.delete_messages(name)
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR019 - incorrect mode")
+
+def create_message(message):
+	if mode==CSTE_MODE_LOCAL_REPO:
+		repo.create_message(message)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.create_message()
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR020 - incorrect mode")
+
+def retrieve_last_message(simulation):
+	message=None
+
+	if mode==CSTE_MODE_LOCAL_REPO:
+		message=repo.retrieve_last_message(simulation)
+	elif mode==CSTE_MODE_REMOTE_REPO:
+
+		# prepare args
+		# ..
+
+		# execute
+		repo.retrieve_last_message(simulation)
+
+		# process return values
+		# ..
+
+	elif mode==CSTE_MODE_REMOTE_REPO_STUB:
+		pass
+	else:
+		raise Exception("ERR021 - incorrect mode")
+
+	return message
+
+
+# --- higher level methods --- #
+
+def get_running_simulations():
+	running_simulation=[]
+
+	for s in retrieve_simulation():
+		if s.status=="running":
+			running_simulation.append(s)
+			
+	return running_simulation
+
+
