Beispiel #1
0
    def PumpActivityState(self, state_pickle):
        state_pickle = str(state_pickle)
        #logging.info('I JUST RECEIVED PICKLE TYPE: %r - %s (PumpActivityState)', type(state_pickle), state_pickle)
        if len(state_pickle) == 0:
            logging.debug(
                'JokeMachineSession.ReceiveActivityState() -> empty state_pickle - creating empty state'
            )
            activity_state = JokeMachineState().test_data()
        else:
            logging.debug(
                'JokeMachineSession.ReceiveActivityState() -> Unpickling state from remote'
            )
            activity_state = JokeMachineState.loads(state_pickle)
        Globals.set_activity_state(activity_state)

        # refresh activity ui
        Globals.JokeMachineActivity.refresh()
        logging.debug('Finished receiving state')
Beispiel #2
0
 def JokeMachineState(self):
     if not self.__activity_state:
         # Okay - When app is not run from Journal activity.read_file() is never
         # called, which means we never call Globals.set_activity_state so we
         # create a default state here:
         logging.debug('Globals.JokeMachineState() - creating default data')
         self.__activity_state = JokeMachineState().test_data(
         )  # TODO - implement JokeMachineState.new()
     return self.__activity_state
Beispiel #3
0
    def read_file(self, file_path):
        '''Callback to resume activity state from Journal'''
        logging.debug('Reading file from datastore via Journal: %s' %
                      file_path)
        f = open(file_path, 'r')
        pickle = f.read()
        if len(pickle) == 0:
            logging.debug(
                'Activity.read_file() -> Journal has empty pickle - creating empty state'
            )
            activity_state = JokeMachineState().test_data()
        else:
            logging.debug('Unpickling state from Journal')
            activity_state = JokeMachineState.loads(pickle)
        f.close()

        # set Globals.ActivityState
        Globals.set_activity_state(activity_state)
Beispiel #4
0
 def PumpActivityState(self, state_pickle):
   state_pickle = str(state_pickle)
   #logging.info('I JUST RECEIVED PICKLE TYPE: %r - %s (PumpActivityState)', type(state_pickle), state_pickle)
   if len(state_pickle) == 0:
     logging.debug('JokeMachineSession.ReceiveActivityState() -> empty state_pickle - creating empty state')
     activity_state = JokeMachineState().test_data()
   else:
     logging.debug('JokeMachineSession.ReceiveActivityState() -> Unpickling state from remote')
     activity_state = JokeMachineState.loads(state_pickle)
   Globals.set_activity_state(activity_state) 
   
   # refresh activity ui
   Globals.JokeMachineActivity.refresh()
   logging.debug('Finished receiving state')    
  def read_file(self, file_path):
    '''Callback to resume activity state from Journal'''
    logging.debug('Reading file from datastore via Journal: %s' % file_path)
    f = open(file_path, 'r')
    pickle = f.read()
    if len(pickle) == 0:
      logging.debug('Activity.read_file() -> Journal has empty pickle - creating empty state')
      activity_state = JokeMachineState().test_data()
    else:
      logging.debug('Unpickling state from Journal')
      activity_state = JokeMachineState.loads(pickle)
    f.close()

    # set Globals.ActivityState
    Globals.set_activity_state(activity_state) 
Beispiel #6
0
#

# dump properties on persistent objects
def dump(obj, indent="  "):
    print indent + str(obj)
    for name, prop in obj.__properties__:
        value = prop.fget(obj)
        print indent + name, "=", value  # , ' "' + prop.__doc__ + '"'
        if value.__class__ is list:
            for item in value:
                dump(item, indent + "  ")

    print indent + "is_dirty =", obj.__dirty__


state = JokeMachineState()
state = state.test_data()
dump(state)
print "\n========================================================================\n"
pickle = state.dumps()
j = JokeMachineState.loads(pickle)
jokebook = j.jokebooks[0]
jokebook.owner = "new owner"
dump(j)


sys.exit()


joke = Joke()
Beispiel #7
0
#

import sys
sys.path.append('..')

from persistence.jokemachinestate import JokeMachineState


def dump(obj, indent='  '):
    print indent + str(obj)
    for name, prop in obj.__properties__:
        value = prop.fget(obj)
        print indent + name, '=', value  #, ' "' + prop.__doc__ + '"'
        if value.__class__ is list:
            for item in value:
                dump(item, indent + '  ')

    print indent + 'is_dirty =', obj.__dirty__


state = JokeMachineState().test_data()

print state.jokebooks
print state.next_jokebook_id

#[max(joke.id) for joke in self.__jokes]

#pickle = state.dumps()
#new_state = JokeMachineState.loads(pickle)
#dump(new_state)
Beispiel #8
0

# dump properties on persistent objects
def dump(obj, indent='  '):
    print indent + str(obj)
    for name, prop in obj.__properties__:
        value = prop.fget(obj)
        print indent + name, '=', value  #, ' "' + prop.__doc__ + '"'
        if value.__class__ is list:
            for item in value:
                dump(item, indent + '  ')

    print indent + 'is_dirty =', obj.__dirty__


state = JokeMachineState()
state = state.test_data()
dump(state)
print "\n========================================================================\n"
pickle = state.dumps()
j = JokeMachineState.loads(pickle)
jokebook = j.jokebooks[0]
jokebook.owner = 'new owner'
dump(j)

sys.exit()

joke = Joke()

print 'Joke.id.doc: ', Joke.id.__doc__
print 'Joke.joke_text.doc: ', Joke.text.__doc__