10 root_window.title("YAFFS Browser")
11 mount_list_text_variable=tk.StringVar()
13 mount_list_text_variable.set("yaffs2/")
14 current_directory_dict={}
24 #global current_directory_dict
25 print "saving the file"
26 print self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
27 yaffs_lseek(self.yaffs_handle, 0, 0)
28 data_to_be_written=self.file_editor_text.get("1.0", tk.END)
29 print "data to be saved", data_to_be_written
30 x=len(data_to_be_written)
31 print "length of data to be written",x
32 output=yaffs_write(self.yaffs_handle,data_to_be_written , x)
33 print "output", output
34 yaffs_close(self.yaffs_handle)
35 self.yaffs_handle = yaffs_open(self.file_path,66,0666)
38 global current_directory_dict
39 x=name_list_box.curselection()
41 self.file_editor_root =tk.Toplevel()
42 self.save_button=tk.Button(self.file_editor_root, text="save", command=self.save_file)
43 self.save_button.pack()
45 self.file_path=current_directory_dict[self.id]["path"]
46 print "file path", self.file_path
47 self.file_editor_root.title(current_directory_dict[self.id]["path"])
48 self.file_editor_text=tk.Text(self.file_editor_root)
49 self.yaffs_handle = yaffs_open(current_directory_dict[self.id]["path"],66,0666)
50 length_of_file=yaffs_lseek(self.yaffs_handle, 0, 2) ##seeks to the end of the file
51 yaffs_lseek(self.yaffs_handle, 0, 0)## returns the handle to the front of th file
52 self.file_contents=ctypes.create_string_buffer(length_of_file)
53 yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
54 print "file contents", self.file_contents.raw
55 self.file_editor_text.insert(tk.END, self.file_contents.raw)
56 self.file_editor_text.pack()
60 global current_directory_dict
61 print "loading a new directory*******************************************************************"
62 name_list_box.delete(0, tk.END)
63 current_directory_dict=yaffs_ls(mount_list_text_variable.get())
64 print "new directory", current_directory_dict
65 ##copy directory into file box
66 for x in range(0,len(current_directory_dict)):
67 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"]))
68 name_list_box.grid(column=0, row=1)
69 return current_directory_dict
71 print file_editor_text.get(0, end)
74 global open_windows_list
75 open_windows_list.append(editor())
81 # file_editor_text.insert(0, "this is a text box\n")
82 #use file_editor_text_box.get(0, END) to retreve text
84 def load_command(self=0):
85 global current_directory_dict
86 print "you loaded a file/dir"
87 x=name_list_box.curselection()
89 print "cursor selection", x
90 print "dict", current_directory_dict
92 print "file inode is:", current_directory_dict[x]["inodes"]
95 print "file path is:", current_directory_dict[x]["path"]
96 if current_directory_dict[x]["type"]=="dir":
98 print "open directory"
99 mount_list_text_variable.set(current_directory_dict[x]["path"])
100 print mount_list_text_variable.get()
101 print "old directory dict", current_directory_dict
102 current_directory_dict=load_dir()
103 print "new directory dict passed back"
105 elif current_directory_dict[x]["type"]=="file" :
111 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
113 def back_a_directory(self=0):
114 x=len(mount_list_text_variable.get())
115 string=mount_list_text_variable.get()
117 #print "length of path", x
118 #print "string been sorted:", string
119 for i in range(0, x):
122 #print "slash found at:", i
125 ##slashes_id.sort() not needed because the list is already in acending order
126 ##print "sorted",slashes_id
128 string=string[0: slashes_id[len(slashes_id)-2]+1]
130 mount_list_text_variable.set(string)
141 if dname[-1] != "/": dname = dname + "/"
142 dc = yaffs_opendir(dname)
144 sep = yaffs_readdir(dc)
148 fullname = dname + se.d_name
149 st = yaffs_stat_struct()
150 result = yaffs_stat(fullname,byref(st))
151 perms = st.st_mode & 0777
152 isFile = True if st.st_mode & 0x8000 else False
153 isDir = True if st.st_mode & 0x4000 else False
156 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
158 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/"})
161 # ls_dict.append( "Other ("+hex(st.st_mode)+") "+se.d_ino, hex(perms)+ fullname)
162 sep = yaffs_readdir(dc)
166 print "Could not open directory"
172 toolbar_frame=tk.Frame(root_window)
173 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
174 button_open.grid(column=0, row=0)
175 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
176 button_back.grid(column=1, row=0)
177 toolbar_frame.grid(row=0, column=0, columnspan=3)
181 ##mount list entry box init
182 mount_list_frame=tk.Frame(root_window)
183 mount_list_label=tk.Label(mount_list_frame, text="mount list")
184 mount_list_label.pack(side=tk.RIGHT)
186 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
187 mount_list_entry_box.pack(side=tk.RIGHT)
188 mount_list_frame.grid(row=1, column=0, columnspan=2)
193 list_frame=tk.Frame(root_window)
197 name_list_box=tk.Listbox(list_frame,exportselection=0, height=20, width=30)
201 #print "current_dir_dict", current_directory_dict
206 name_list_box.bind("<Double-Button-1>", load_command)
211 root_window.mainloop()
212 yaffs_unmount("yaffs2/")