def dir2shmem(currentDir): # files = [ f for f in listdir(currentDir) if isfile(join(currentDir,f)) ] # print files allindir = os.listdir(currentDir) # print allindir # result = [currentDir] # dirs = list(set(allindir) - set(files)) result = ShMemObject() for a in allindir: if currentDir != "./" and currentDir != "../": a = currentDir + "/" + a else: a = currentDir + a if isfile(a): f = open(a, "rb") bytes = f.read() bytes = base64.b64encode(bytes) # CHANGE THIS TO WRITE FILE BYTES TO SHMEM OBJECT result.put_simple(a, bytes) else: result.put_object(a, dir2shmem(a)) # result = result + [dir2shmem(a)] # print "returning " + str(result) return result
def testPutGet(self): file_var = open('test_file.txt', 'r') ShMem.init(file_var, 0) file_var.close() ShMem.start(False) self.assertEqual(ShMemObject.s_now, [1,0,0,0]) first_obj = ShMemObject() first_obj.put_simple('Yale', 'University') ShMem.s_state.put_object('name', first_obj) # Make sure that gets work properly. temp = ShMem.s_state.get('name') self.assertEqual(first_obj, temp) self.failUnless(temp.get('Yale') == 'University') # Increment time. Timestamp.LocalIncrement(ShMemObject.s_now) # Make sure that we actually managed to change the time. self.assertEqual(Timestamp.CompareTimestamps(ShMemObject.s_now, [2,0,0,0]), Comparison.EQUAL) first_obj.put_simple('CS', 'Watson') # The timestamp of the object we previously inserted should not # change. yale_timestamp = first_obj.m_timestamps['Yale'] self.assertEqual(Timestamp.CompareTimestamps(yale_timestamp, [1,0,0,0]), Comparison.EQUAL) # The newly inserted item must have the right timestamp. cs_timestamp = first_obj.m_timestamps['CS'] self.assertEqual(Timestamp.CompareTimestamps(cs_timestamp, [2,0,0,0]), Comparison.EQUAL) # Make sure that 'name's timestamp has changed to the right value. name_timestamp = ShMem.s_state.m_timestamps['name'] self.assertEqual(Timestamp.CompareTimestamps(name_timestamp, [2,0,0,0]), Comparison.EQUAL) # Change s_now arbitratily. ShMemObject.s_now = [2,2,0,0] # Make sure that timestamps work properly when we're nesting objects. second_obj = ShMemObject() second_obj.put_simple('gah', 'blah') first_obj.put_object('second', second_obj) self.assertEqual(Timestamp.CompareTimestamps(name_timestamp, [2,2,0,0]), Comparison.EQUAL)
def standardInit(self): file_var = open('test_file.txt', 'r') ShMem.init(file_var, 0) file_var.close() ShMem.start(False) first_obj = ShMemObject() first_obj.put_simple('Yale', 'University') ShMem.s_state.put_object('name', first_obj) # Increment time. Timestamp.LocalIncrement(ShMemObject.s_now) first_obj.put_simple('CS', 'Watson') # Change s_now arbitratily. ShMemObject.s_now = [2,2,0,0] # Make sure that timestamps work properly when we're nesting objects. second_obj = ShMemObject() second_obj.put_simple('gah', 'blah') first_obj.put_object('second', second_obj)