Index: trunk/Monitoring/Watch/repo-state
===================================================================
--- trunk/Monitoring/Watch/repo-state	(revision 867)
+++ trunk/Monitoring/Watch/repo-state	(revision 871)
@@ -1,85 +1,373 @@
 #!/usr/bin/env python
 
+# --- ncurses sample 1
+
+#import curses
+#from curses import panel
+#
+#class Menu(object):
+#
+#	def __init__(self, items, stdscreen):
+#		self.window = stdscreen.subwin(0,0)
+#		self.window.keypad(1)
+#		self.panel = panel.new_panel(self.window)
+#		self.panel.hide()
+#		panel.update_panels()
+#
+#		self.position = 0
+#		self.items = items
+#		self.items.append(('exit','exit'))
+#
+#	def navigate(self, n):
+#		self.position += n
+#		if self.position < 0:
+#			self.position = 0
+#		elif self.position >= len(self.items):
+#			self.position = len(self.items)-1
+#
+#	def display(self):
+#		self.panel.top()
+#		self.panel.show()
+#		self.window.clear()
+#
+#
+#		while True:
+#			self.window.refresh()
+#			curses.doupdate()
+#			for index, item in enumerate(self.items):
+#				if index == self.position:
+#					mode = curses.A_REVERSE
+#				else:
+#					mode = curses.A_NORMAL
+#
+#				msg = '%d. %s' % (index, item[0])
+#				self.window.addstr(1+index, 1, msg, mode)
+#
+#			key = self.window.getch()
+#
+#			if key in [curses.KEY_ENTER, ord('\n')]:
+#				if self.position == len(self.items)-1:
+#					break
+#				else:
+#					self.items[self.position][1]()
+#
+#			elif key == curses.KEY_UP:
+#				self.navigate(-1)
+#
+#			elif key == curses.KEY_DOWN:
+#				self.navigate(1)
+#
+#		self.window.clear()
+#		self.panel.hide()
+#		panel.update_panels()
+#		curses.doupdate()
+#
+#
+#class MyApp(object):
+#
+#	def __init__(self, stdscreen):
+#		self.screen = stdscreen
+#		curses.curs_set(0)
+#
+#		submenu_items = [
+#				('beep', curses.beep),
+#				('flash', curses.flash)
+#				]
+#		submenu = Menu(submenu_items, self.screen)
+#
+#		main_menu_items = [
+#				('beep', curses.beep),
+#				('flash', curses.flash),
+#				('submenu', submenu.display)
+#				]
+#		main_menu = Menu(main_menu_items, self.screen)
+#		main_menu.display()
+
+#if __name__ == '__main__':
+#	curses.wrapper(MyApp)
+
+
+
+
+
+# --- ncurses sample 2
+
+# Author: Nikolai Tschacher
+# Date: 02.06.2013
+#
+#class BoxSelector:
+#    """ Originally designed for accman.py.
+#        Display options build from a list of strings in a (unix) terminal.
+#        The user can browser though the textboxes and select one with enter.
+#    """
+#    
+#    def __init__(self, L):
+#        """ Create a BoxSelector object. 
+#            L is a list of strings. Each string is used to build 
+#            a textbox.
+#        """
+#        self.L = L
+#        # Element parameters. Change them here.
+#        self.TEXTBOX_WIDTH = 50
+#        self.TEXTBOX_HEIGHT = 6
+#
+#        self.PAD_WIDTH = 400
+#        self.PAD_HEIGHT = 10000
+#        
+#    def pick(self):
+#        """ Just run this when you want to spawn the selction process. """
+#        self._init_curses()
+#        self._create_pad()
+#        
+#        windows = self._make_textboxes()
+#        picked = self._select_textbox(windows)
+#        
+#        self._end_curses()
+#        
+#        return picked
+#        
+#    def _init_curses(self):
+#        """ Inits the curses appliation """
+#        # initscr() returns a window object representing the entire screen.
+#        self.stdscr = curses.initscr()
+#        # turn off automatic echoing of keys to the screen
+#        curses.noecho()
+#        # Enable non-blocking mode. Keys are read directly, without hitting enter.
+#        curses.cbreak()
+#        # Disable the mouse cursor.
+#        curses.curs_set(0)
+#        self.stdscr.keypad(1)
+#        # Enable colorous output.
+#        curses.start_color()
+#        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
+#        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
+#        self.stdscr.bkgd(curses.color_pair(2))
+#        self.stdscr.refresh()
+#
+#    def _end_curses(self):
+#        """ Terminates the curses application. """
+#        curses.nocbreak()
+#        self.stdscr.keypad(0)
+#        curses.echo()
+#        curses.endwin()
+#        
+#    def _create_pad(self):
+#        """ Creates a big self.pad to place the textboxes in. """
+#        self.pad = curses.newpad(self.PAD_HEIGHT, self.PAD_WIDTH)
+#        self.pad.box()
+#        
+#    def _make_textboxes(self):
+#        """ Build the textboxes in the pad center and put them in the 
+#            horizontal middle of the pad. """
+#        # Get the actual screensize.
+#        maxy, maxx = self.stdscr.getmaxyx()
+#        
+#        windows = []
+#        i = 1
+#        for s in self.L:
+#            windows.append(self.pad.derwin(self.TEXTBOX_HEIGHT,
+#                    self.TEXTBOX_WIDTH, i, self.PAD_WIDTH//2-self.TEXTBOX_WIDTH//2))
+#            i += self.TEXTBOX_HEIGHT
+#            
+#        for k in range(len(windows)):
+#            windows[k].box()
+#            windows[k].addstr(4, 4, '0x{0:X} - {1}'.format(k, self.L[k]))
+#            
+#        return windows
+#
+#    def _center_view(self, window):
+#        """ Centers and aligns the view according to the window argument given. 
+#            Returns the (y, x) coordinates of the centered window. """
+#        # The refresh() and noutrefresh() methods of a self.pad require 6 arguments
+#        # to specify the part of the self.pad to be displayed and the location on
+#        # the screen to be used for the display. The arguments are pminrow,
+#        # pmincol, sminrow, smincol, smaxrow, smaxcol; the p arguments refer
+#        # to the upper left corner of the self.pad region to be displayed and the
+#        # s arguments define a clipping box on the screen within which the
+#        # self.pad region is to be displayed.
+#        cy, cx = window.getbegyx()
+#        maxy, maxx = self.stdscr.getmaxyx()
+#        self.pad.refresh(cy, cx, 1, maxx//2 - self.TEXTBOX_WIDTH//2, maxy-1, maxx-1)
+#        return (cy, cx)
+#        
+#    def _select_textbox(self, windows):
+#        # See at the root textbox.
+#        topy, topx = self._center_view(windows[0])
+#        
+#        current_selected = 0
+#        last = 1
+#        top_textbox = windows[0]
+#        
+#        while True:
+#            # Highligth the selected one, the last selected textbox should
+#            # become normal again.
+#            windows[current_selected].bkgd(curses.color_pair(1))
+#            windows[last].bkgd(curses.color_pair(2))
+#            
+#            # While the textbox can be displayed on the page with the current 
+#            # top_textbox, don't alter the view. When this becomes impossible, 
+#            # center the view to last displayable textbox on the previous view.
+#            maxy, maxx = self.stdscr.getmaxyx()
+#            cy, cx = windows[current_selected].getbegyx()
+#            
+#            # The current window is to far down. Switch the top textbox.
+#            if ((topy + maxy - self.TEXTBOX_HEIGHT) <= cy):
+#                top_textbox = windows[current_selected]
+#            
+#            # The current window is to far up. There is a better way though...
+#            if topy >= cy + self.TEXTBOX_HEIGHT:
+#                top_textbox = windows[current_selected]
+#            
+#            if last != current_selected:
+#                last = current_selected
+#                
+#            topy, topx = self._center_view(top_textbox)
+#            
+#            c = self.stdscr.getch()
+#            
+#            # Vim like KEY_UP/KEY_DOWN with j(DOWN) and k(UP).
+#            if c == ord('j'):
+#                if current_selected >= len(windows)-1:
+#                    current_selected = 0 # wrap around.
+#                else:
+#                    current_selected += 1
+#            elif c == ord('k'):
+#                if current_selected <= 0:
+#                    current_selected = len(windows)-1 # wrap around.
+#                else:
+#                    current_selected -= 1
+#            elif c == ord('q'): # Quit without selecting.
+#                break
+#            # At hitting enter, return the index of the selected list element.
+#            elif c == curses.KEY_ENTER or c == 10:
+#                return int(current_selected)
+#
+#
+#if __name__ == '__main__':
+#    # As simple as that.
+#    L = [
+#         'I wish I was a wizard',
+#         'Sometimes it all just makes sense',
+#         'This string is here because I need it',
+#         'Being or not being!',
+#         'Python is worse then PHP ;)',
+#         'a -> b <=> if a then b'
+#        ]
+#        
+#    choice = BoxSelector(L).pick()
+#    print('[+] Your choice was "{0}"'.format(L[choice]))
+
+
+
+
+
+
+
+# --- ncurses sample 3
+
+
+
+import sys
 import curses
-from curses import panel
-
-class Menu(object):
-
-	def __init__(self, items, stdscreen):
-		self.window = stdscreen.subwin(0,0)
-		self.window.keypad(1)
-		self.panel = panel.new_panel(self.window)
-		self.panel.hide()
-		panel.update_panels()
-
-		self.position = 0
-		self.items = items
-		self.items.append(('exit','exit'))
-
-	def navigate(self, n):
-		self.position += n
-		if self.position < 0:
-			self.position = 0
-		elif self.position >= len(self.items):
-			self.position = len(self.items)-1
-
-	def display(self):
-		self.panel.top()
-		self.panel.show()
-		self.window.clear()
-
-
-		while True:
-			self.window.refresh()
-			curses.doupdate()
-			for index, item in enumerate(self.items):
-				if index == self.position:
-					mode = curses.A_REVERSE
-				else:
-					mode = curses.A_NORMAL
-
-				msg = '%d. %s' % (index, item[0])
-				self.window.addstr(1+index, 1, msg, mode)
-
-			key = self.window.getch()
-
-			if key in [curses.KEY_ENTER, ord('\n')]:
-				if self.position == len(self.items)-1:
-					break
-				else:
-					self.items[self.position][1]()
-
-			elif key == curses.KEY_UP:
-				self.navigate(-1)
-
-			elif key == curses.KEY_DOWN:
-				self.navigate(1)
-
-		self.window.clear()
-		self.panel.hide()
-		panel.update_panels()
-		curses.doupdate()
-
-
-class MyApp(object):
-
-	def __init__(self, stdscreen):
-		self.screen = stdscreen
-		curses.curs_set(0)
-
-		submenu_items = [
-				('beep', curses.beep),
-				('flash', curses.flash)
-				]
-		submenu = Menu(submenu_items, self.screen)
-
-		main_menu_items = [
-				('beep', curses.beep),
-				('flash', curses.flash),
-				('submenu', submenu.display)
-				]
-		main_menu = Menu(main_menu_items, self.screen)
-		main_menu.display()
-
-if __name__ == '__main__':
-	curses.wrapper(MyApp)
+#import pprint
+
+# line below is to include "smon" package in the search path
+sys.path.append("/home/jripsl/snapshot/Monitoring")
+
+from smon import repo_io
+import smon.types
+
+
+repo_io.init() # open DB connection
+
+repo_io.populate_tables_with_sample()
+
+simulations=repo_io.retrieve_simulations()
+
+mylines = ["Line {0} ".format(id)*3 for id in range(1,11)]
+
+
+def main(stdscr):
+  hlines = begin_y = begin_x = 5 ; wcols = 10
+  # calculate total content size
+  padhlines = len(mylines)
+  padwcols = 0
+  for line in mylines:
+    if len(line) > padwcols: padwcols = len(line)
+  padhlines += 2 ; padwcols += 2 # allow border
+  #stdscr.addstr("padhlines "+str(padhlines)+" padwcols "+str(padwcols)+"; ")
+  # both newpad and subpad are <class '_curses.curses window'>:
+  mypadn = curses.newpad(padhlines, padwcols)
+  mypads = stdscr.subpad(padhlines, padwcols, begin_y, begin_x+padwcols+4)
+  #stdscr.addstr(str(type(mypadn))+" "+str(type(mypads)) + "\n")
+  mypadn.scrollok(1)
+  mypadn.idlok(1)
+  mypads.scrollok(1)
+  mypads.idlok(1)
+
+  mypadn.border(0) # first ...
+  mypads.border(0) # ... border
+
+  for line in mylines:
+    mypadn.addstr(padhlines-1,1, line)
+    mypadn.scroll(1)
+    mypads.addstr(padhlines-1,1, line)
+    mypads.scroll(1)
+
+  mypadn.border(0) # second ...
+  mypads.border(0) # ... border
+
+  # refresh parent first, to render the texts on top
+  #~ stdscr.refresh()
+
+  # refresh the pads next
+  mypadn.refresh(0,0, begin_y,begin_x, begin_y+hlines, begin_x+padwcols)
+  mypads.refresh()
+  mypads.touchwin()
+  mypadn.touchwin()
+  stdscr.touchwin() # no real effect here
+  #stdscr.refresh() # not here! overwrites newpad!
+  mypadn.getch()
+  # even THIS command erases newpad!
+  # (unless stdscr.refresh() previously):
+  stdscr.getch()
+
+curses.wrapper(main)
+
+
+
+
+repo_io.free() # close DB connection
+
+
+
+
+
+
+
+
+
+# --- urwid sample 1
+
+#import urwid
+#
+#txt = urwid.Text(u"Hello World")
+#fill = urwid.Filler(txt, 'top')
+#loop = urwid.MainLoop(fill)
+#loop.run()
+
+
+# --- urwid sample 2
+
+#import urwid
+#
+#def show_or_exit(key):
+#    if key in ('q', 'Q'):
+#        raise urwid.ExitMainLoop()
+#    txt.set_text(repr(key))
+#
+#txt = urwid.Text(u"Hello World")
+#fill = urwid.Filler(txt, 'top')
+#loop = urwid.MainLoop(fill, unhandled_input=show_or_exit)
+#loop.run()
+
Index: trunk/Monitoring/Watch/watch
===================================================================
--- trunk/Monitoring/Watch/watch	(revision 867)
+++ trunk/Monitoring/Watch/watch	(revision 871)
@@ -29,15 +29,4 @@
 import smon.types
 
-"""
-Code list reminder
-
-0000 (la simulation dÃ©marre)
-1000 (le job d'une simulation dÃ©marre)
-2000 (PushStack)
-3000 (PopStack OK)
-9000 (PopStack NOK)
-9999 (FATAL)
-"""
-
 class Mail():
 
@@ -129,9 +118,9 @@
 	@classmethod
 	def start(cls):
-		pass
+		repo_io.init() # open DB connection
 
 	@classmethod
 	def stop(cls):
-		pass
+		repo_io.free() # close DB connection
 
 	@classmethod
@@ -174,5 +163,5 @@
 
 				# debug
-				print " [x] Received %s" % field
+				#print " [x] Received %s" % field
 
 				splitted_field=field.split(":")
@@ -185,5 +174,5 @@
 
 			# debug
-			print " [x] Received %s (encoded)" % l__tmp_dic["body"]
+			#print " [x] Received %s (encoded)" % l__tmp_dic["body"]
 
 			
@@ -194,31 +183,49 @@
 			# debug
 			#print " [x] Received %s" % raw_msg
-			print " [x] Received %s (uudecoded)" % base64_decoded_msg 
 			#print " [x] Received %s (uudecoded)" % base64_decoded_msg 
-
-
+			#print " [x] Received %s (uudecoded)" % base64_decoded_msg 
+
+
+			# message deserialization 
 			message=None
 			try:
-				# body deserialization 
 				JSON_msg=json.loads(base64_decoded_msg)
 				message=smon.types.Message(JSON_msg)      # all JSON object members will be available in smon.types.Message object
 
-				if "file" in l__tmp_dic:
-
-					# base64 decode file
-					base64_decoded_file=base64.b64decode(l__tmp_dic["file"])
-
-					# add into msg
-					message.file=base64_decoded_file
-
+
+
+			except Exception,e:
+				print "ERR009 - exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg)
+
+				#traceback.print_exc()
+				#raise
+
+
+
+			# manage config-card file which is attached to the "0000" type message (this file is base64 encoded and need to be unencoded)
+			#
+			if "file" in l__tmp_dic:
+
+				# base64 decode file
+				base64_decoded_file=base64.b64decode(l__tmp_dic["file"])
+
+				# add as msg attribute
+				message.file=base64_decoded_file
+
+
+
+			# execute actions
+			try:
 				# message code based action
-				Actions.execActions(message)
-
+				#Actions.execActions(message)
+				pass
 			except Exception,e:
-				print "Exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg)
-
-				#traceback.print_exc()
+				print "ERR019 - exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg)
+
+				traceback.print_exc()
 
 				raise
+
+
 
 		self.channel.basic_consume(callback, queue='myqueue', no_ack=True)
Index: trunk/Monitoring/libIGCM_mock/libIGCM_mock.sh
===================================================================
--- trunk/Monitoring/libIGCM_mock/libIGCM_mock.sh	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/libIGCM_mock.sh	(revision 871)
@@ -18,10 +18,12 @@
 # init
 
-stack_file=$1
 send_msg_cmd="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg"
-scenario_dir=scenario
+g__stackfile=
+g__scenario_dir=scenario
 g__mode="scenario"
-g__stackfile=
-g__scenario_file=
+g__scenariofile=
+g__dryrun=0
+g__confirm=0
+g__delay=1 # delay between message
 
 # func
@@ -47,8 +49,11 @@
 
 OPTIONS:
+   -h              this help
    -f              set stack file
    -l              print scenarios list 
-   -m              set mode (if missing, "scenario" mode is used)
-   -s              set scenario
+   -m              set MODE
+                   MODE may be "scenario", "stackfile" or "purge"
+                   default mode is "scenario"
+   -s              set scenario file
 
 EXAMPLES:
@@ -74,5 +79,5 @@
 	echo "Scenarios list:"
 	echo ""
-	ls -1 $scenario_dir
+	ls -1 $g__scenario_dir
 	echo ""
 	exit 2
@@ -87,7 +92,11 @@
 # parse args
 
-while getopts 'f:hlm:s:' OPTION
+while getopts 'cdf:hlm:s:' OPTION
 do
   case $OPTION in
+  c)    g__confirm="1"
+        ;;
+  d)    g__dryrun="1"
+        ;;
   f)    g__stackfile="$OPTARG"
         ;;
@@ -98,14 +107,14 @@
   m)    g__mode="$OPTARG"
         ;;
-  s)    l__scenario_file="$OPTARG"
-
-		if [[ "$l__scenario_file" =~ "*/*" ]]; then
+  s)    l__scenariofile="$OPTARG"
+
+		if [[ "$l__scenariofile" =~ "*/*" ]]; then
 			# full/relative path was given with the filename
 
-			g__scenario_file="$l__scenario_file"
+			g__scenariofile="$l__scenariofile"
 		else
 			# only the filename was given
 
-			g__scenario_file="$scenario_dir/$l__scenario_file"
+			g__scenariofile="$g__scenario_dir/$l__scenariofile"
 		fi
 
@@ -120,44 +129,117 @@
 
 	# check
-	if [ ! -f "$g__scenario_file" ]; then
+	if [ ! -f "$g__scenariofile" ]; then
 		msg "LIBIGCM-MOCK-ERR003" "scenario file not found"
 		exit 1
 	fi
 
-	N=0
-	while read LINE ; do
-
-		N=$((N+1))
+	while read LINE <&3; do
+
+		# debug
+		#echo $LINE
 
 		l__JSON_msg_buf=
-
-		# process fields (split on " " delimiter)
-		for field in "$LINE"; do
-			arr=(${LINE//=/ }) # process key/value (split on "=" delimiter)
-			key=${arr[0]}
-			val=${arr[1]}
-
-			# base64 encoding
+		N=1
+		fields_arr=(${LINE// / }) # process fields (split on " " delimiter)
+		for FIELD in "${fields_arr[@]}"; do
+
+			# debug 
+			#echo $FIELD
+
+
+			field_arr=(${FIELD//=/ }) # process key/value (split on "=" delimiter)
+			key=${field_arr[0]}
+
+
+			# HACK
+			if [ "$key" = "file" ]; then
+				# special processing for "file" key (base64 encoding)
+
+				l__configcard_file="/home/jripsl/snapshot/Monitoring/sample/${field_arr[1]}"
+
+				# check
+				if [ ! -f "$l__configcard_file" ]; then
+					msg "LIBIGCM-MOCK-ERR004" "config-card file not found ($l__configcard_file)"
+					exit 1
+				fi
+
+				val=$( cat $l__configcard_file | base64 -w 0 )
+
+			else
+				val=${field_arr[1]}
+			fi
+
 
 			# append to JSON message buffer
-			l__JSON_msg_buf=$l__JSON_msg_buf
-
+			if [ "$N" -gt "1" ]; then
+
+				l__JSON_msg_buf="$l__JSON_msg_buf,\"$key\":\"$val\""
+			else
+				# first field
+
+				l__JSON_msg_buf="\"$key\":\"$val\""
+			fi
+
+
+			N=$((N+1))
 		done
 
+		# enclose
+		l__JSON_msg_buf="{""$l__JSON_msg_buf""}"
+
+		# debug
+		#echo $l__JSON_msg_buf
+
 		# message base64 encoding
-
-
-		#callname=$(echo $line | awk -F" " '{print $4}' )
+		l__JSON_msg_buf_encoded=$( echo $l__JSON_msg_buf | base64 -w 0 )
+
+		# debug
+		#echo $l__JSON_msg_buf_encoded
+		#echo $send_msg_cmd -h localhost -p 5672 -b "$l__JSON_msg_buf_encoded"
 
 		# send AMQP message
-		#$send_msg_cmd localhost 5672 string "$callname"
-		echo
-
-	done < $g__scenario_file
+		if [ "$g__dryrun" = "1" ]; then
+
+			echo $send_msg_cmd -h localhost -p 5672 -b "$l__JSON_msg_buf"
+
+
+			# debug
+			#
+			# uncomment line below (and comment line above) to output only the encoded message
+			# 
+			# it can then be unencoded for debug purpose (message encoding level, not config-card encoding) using command below
+			# ./libIGCM_mock.sh -s start_simu__stop_simu -d | base64 -d | less
+			# 
+			# 
+			#echo $l__JSON_msg_buf_encoded
+
+		else
+			$send_msg_cmd -h localhost -p 5672 -b "$l__JSON_msg_buf_encoded"
+		fi
+
+
+
+
+		if [ "$g__confirm" = "1" ]; then
+			read -p "Press enter for next message" bla
+		else
+			sleep $g__delay
+		fi
+
+
+
+		# debug
+		#break
+
+	done 3<$g__scenariofile
+
+elif [ "$g__mode" = "purge" ]; then
+
+	:
 
 elif [ "$g__mode" = "stackfile" ]; then
 
 	# check
-	if [ ! -f $stack_file ]; then
+	if [ ! -f $g__stackfile ]; then
 		msg "LIBIGCM-MOCK-ERR001" "file not found"
 		exit 1
@@ -165,5 +247,5 @@
 
 	IFS=$'\n'
-	for line in $(cat $stack_file); do
+	for line in $(cat $g__stackfile); do
 		#echo $line | awk -F" " '{print $4}'
 		callname=$(echo $line | awk -F" " '{print $4}' )
Index: trunk/Monitoring/libIGCM_mock/scenario/start_simu__fatal_error__stop_simu
===================================================================
--- trunk/Monitoring/libIGCM_mock/scenario/start_simu__fatal_error__stop_simu	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/scenario/start_simu__fatal_error__stop_simu	(revision 871)
@@ -1,3 +1,3 @@
-simuid=simu-001 jobid=job-001 code=0000 file=./sample/config.card.base64
+simuid=simu-001 jobid=job-001 code=0000 file=config.card.base64
 simuid=simu-001 jobid=job-001 code=1000
 simuid=simu-001 jobid=job-001 code=2000
Index: trunk/Monitoring/libIGCM_mock/scenario/start_simu__nonfatal_errors__stop_simu
===================================================================
--- trunk/Monitoring/libIGCM_mock/scenario/start_simu__nonfatal_errors__stop_simu	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/scenario/start_simu__nonfatal_errors__stop_simu	(revision 871)
@@ -1,3 +1,3 @@
-simuid=simu-001 jobid=job-001 code=0000 file=./sample/config.card.base64
+simuid=simu-001 jobid=job-001 code=0000 file=config.card.base64
 simuid=simu-001 jobid=job-001 code=1000
 simuid=simu-001 jobid=job-001 code=2000
Index: trunk/Monitoring/libIGCM_mock/scenario/start_simu__simu_killed
===================================================================
--- trunk/Monitoring/libIGCM_mock/scenario/start_simu__simu_killed	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/scenario/start_simu__simu_killed	(revision 871)
@@ -1,3 +1,3 @@
-simuid=simu-001 jobid=job-001 code=0000 file=./sample/config.card.base64
+simuid=simu-001 jobid=job-001 code=0000 file=config.card.base64
 simuid=simu-001 jobid=job-001 code=1000
 simuid=simu-001 jobid=job-001 code=2000
Index: trunk/Monitoring/libIGCM_mock/scenario/start_simu__simu_segfault
===================================================================
--- trunk/Monitoring/libIGCM_mock/scenario/start_simu__simu_segfault	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/scenario/start_simu__simu_segfault	(revision 871)
@@ -1,3 +1,3 @@
-simuid=simu-001 jobid=job-001 code=0000 file=./sample/config.card.base64
+simuid=simu-001 jobid=job-001 code=0000 file=config.card.base64
 simuid=simu-001 jobid=job-001 code=1000
 simuid=simu-001 jobid=job-001 code=2000
Index: trunk/Monitoring/libIGCM_mock/scenario/start_simu__start_second_simu_with_same_name
===================================================================
--- trunk/Monitoring/libIGCM_mock/scenario/start_simu__start_second_simu_with_same_name	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/scenario/start_simu__start_second_simu_with_same_name	(revision 871)
@@ -1,3 +1,3 @@
-simuid=simu-001 jobid=job-001 code=0000 file=./sample/config.card.base64
+simuid=simu-001 jobid=job-001 code=0000 file=config.card.base64
 simuid=simu-001 jobid=job-001 code=1000
 simuid=simu-001 jobid=job-001 code=2000
Index: trunk/Monitoring/libIGCM_mock/scenario/start_simu__stop_simu
===================================================================
--- trunk/Monitoring/libIGCM_mock/scenario/start_simu__stop_simu	(revision 867)
+++ trunk/Monitoring/libIGCM_mock/scenario/start_simu__stop_simu	(revision 871)
@@ -1,3 +1,3 @@
-simuid=simu-001 jobid=job-001 code=0000 file=./sample/config.card.base64
+simuid=simu-001 jobid=job-001 code=0000 file=config.card.base64
 simuid=simu-001 jobid=job-001 code=1000
 simuid=simu-001 jobid=job-001 code=2000
Index: trunk/Monitoring/smon/__init__.py
===================================================================
--- trunk/Monitoring/smon/__init__.py	(revision 867)
+++ 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 867)
+++ 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 867)
+++ 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
+
+
