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 main(): node_num = int(sys.argv[1]) address_file = open('test_file.txt', 'r') ShMem.init(address_file, node_num) ShMem.start() address_file.close() if node_num == 0: my_file = open('test.py', 'r') file_contents = my_file.read() my_file.close() my_file = open('test_file.txt', 'r') txt_contents = my_file.read() my_file.close() inner_obj = ShMemObject() inner_obj.put_simple('python_file', file_contents) inner_obj.put_simple('text_file', txt_contents) ShMem.s_state.put_object('test', inner_obj) ShMem.Release(1) ShMem.Release(2) ShMem.Acquire(1) print '\n\n\n' print ShMem.s_state.get_diffs([0,0,0,0]) ShMem.Acquire(2) print ShMemObject.s_now print '\n\n\n' print ShMem.s_state.get_diffs([0,0,0,0]) output_py = open('output.py', 'w') output_py.write(ShMem.s_state.get('test').get('text_file')) output_py.close() output_txt = open('output.txt', 'w') output_txt.write(ShMem.s_state.get('test').get('python_file')) output_txt.close() elif node_num == 1: ShMem.Acquire(0) temp = ShMem.s_state.get('test') python_contents = temp.get('python_file') temp.put_simple('text_file', 'text') ShMem.Release(0) while 1:pass elif node_num == 2: ShMem.Acquire(0) temp = ShMem.s_state.get('test') text_contents = temp.get('text_file') temp.put_simple('python_file', 'python') ShMem.Release(0) while 1:pass
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)