Dont assign restore tasks to stateless clients; improve logs
[ladish.git] / pylash / test.py
blob5f103563d0ecb8c7a08c15358ed17ac21bf68178
1 #!/usr/bin/env python
3 # This file shows example usage of python bindings for LASH
4 # As such code here is public domain you can use it as you wish and in
5 # particular use this code as template for adding LASH support to your program.
8 import sys
9 import time
10 import lash
12 def lash_check_events(lash_client):
13 event = lash.lash_get_event(lash_client)
15 while event:
16 print repr(event)
18 event_type = lash.lash_event_get_type(event)
19 if event_type == lash.LASH_Quit:
20 print "LASH ordered quit."
21 return False
22 elif event_type == lash.LASH_Save_File:
23 print "LASH ordered to save data in directory %s" % lash.lash_event_get_string(event)
24 lash.lash_send_event(lash_client, event)
25 elif event_type == lash.LASH_Save_Data_Set:
26 print "LASH ordered to save data"
27 lash.lash_send_event(lash_client, event)
28 elif event_type == lash.LASH_Restore_Data_Set:
29 print "LASH ordered to restore data"
30 lash.lash_event_destroy(event)
31 elif event_type == lash.LASH_Restore_File:
32 print "LASH ordered to restore data from directory %s" % lash.lash_event_get_string(event)
33 lash.lash_event_destroy(event)
34 else:
35 print "Got unhandled LASH event, type " + str(event_type)
36 lash.lash_event_destroy(event)
37 return True
39 event = lash.lash_get_event(lash_client)
41 return True
43 # sys.argv is modified by this call
44 lash_client = lash.init(sys.argv, "pylash test", lash.LASH_Config_Data_Set | lash.LASH_Terminal)
46 print "Successfully connected to LASH server at " + lash.lash_get_server_name(lash_client)
48 # Send our client name to server
49 lash_event = lash.lash_event_new_with_type(lash.LASH_Client_Name)
50 lash.lash_event_set_string(lash_event, "pylash test")
51 lash.lash_send_event(lash_client, lash_event)
53 # loop until we receive quit order from LASH server
54 while lash_check_events(lash_client):
55 time.sleep(1)