+root_window.title("YAFFS Browser")
+mount_list_text_variable=tk.StringVar()
+
+mount_list_text_variable.set("yaffs2/")
+current_directory_dict={}
+open_windows_list=[]
+
+class editor():
+ yaffs_handle=0
+ file_editor_root =0
+ save_button=[]
+ file_contents=0
+ file_path=0
+ def save_file(self):
+ #global current_directory_dict
+ print "saving the file"
+ print self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
+ yaffs_lseek(self.yaffs_handle, 0, 0)
+ data_to_be_written=self.file_editor_text.get("1.0", tk.END)
+ print "data to be saved", data_to_be_written
+ length_of_file=len(data_to_be_written)
+ print "length of data to be written",length_of_file
+ output=yaffs_write(self.yaffs_handle,data_to_be_written , length_of_file)
+ print "output", output
+ yaffs_ftruncate(self.yaffs_handle, length_of_file)
+ yaffs_close(self.yaffs_handle)
+
+ self.yaffs_handle = yaffs_open(self.file_path,66,0666)
+ load_dir()
+
+ def __init__(self):
+ global current_directory_dict
+ x=name_list_box.curselection()
+ self.id=int(x[0])
+ self.file_editor_root =tk.Toplevel()
+ self.save_button=tk.Button(self.file_editor_root, text="save", command=self.save_file)
+ self.save_button.pack()
+
+ self.file_path=current_directory_dict[self.id]["path"]
+ print "file path", self.file_path
+ self.file_editor_root.title(current_directory_dict[self.id]["path"])
+ self.file_editor_text=tk.Text(self.file_editor_root)
+ self.yaffs_handle = yaffs_open(current_directory_dict[self.id]["path"],66,0666)
+ length_of_file=yaffs_lseek(self.yaffs_handle, 0, 2) ##seeks to the end of the file
+ yaffs_lseek(self.yaffs_handle, 0, 0)## returns the handle to the front of th file
+ self.file_contents=ctypes.create_string_buffer(length_of_file)
+ yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
+ print "file contents", self.file_contents.raw
+ self.file_editor_text.insert(tk.END, self.file_contents.raw)
+ self.file_editor_text.pack()
+ ##self.file_editor_text.bind("<Control-s>", self.save_file)
+ ##doesn't work because it can't pass "self"
+
+def load_dir():
+ global current_directory_dict
+ print "loading a new directory*******************************************************************"
+ name_list_box.delete(0, tk.END)
+ current_directory_dict=yaffs_ls(mount_list_text_variable.get())
+ print "new directory", current_directory_dict
+ ##copy directory into file box
+ for x in range(0,len(current_directory_dict)):
+ name_list_box.insert(x,(current_directory_dict[x]["inodes"]+" "+ current_directory_dict[x]["type"]+" "+ current_directory_dict[x]["size"]+" "+ current_directory_dict[x]["path"]))
+ name_list_box.grid(column=0, row=1)
+ return current_directory_dict
+
+def load_file():
+ global open_windows_list
+ open_windows_list.append(editor())
+
+def load_command(self=0):
+ global current_directory_dict
+ print "you loaded a file/dir"
+ x=name_list_box.curselection()
+ x=int(x[0])
+ print "cursor selection", x
+ print "dict", current_directory_dict
+
+ print "file inode is:", current_directory_dict[x]["inodes"]
+
+
+ print "file path is:", current_directory_dict[x]["path"]
+ if current_directory_dict[x]["type"]=="dir":
+ ##open dir
+ print "open directory"
+ mount_list_text_variable.set(current_directory_dict[x]["path"])
+ print mount_list_text_variable.get()
+ print "old directory dict", current_directory_dict
+ #current_directory_dict=load_dir()
+ load_dir()
+
+ print "new directory dict passed back"