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 length_of_file=len(data_to_be_written)
31 print "length of data to be written",length_of_file
32 output=yaffs_write(self.yaffs_handle,data_to_be_written , length_of_file)
33 print "output", output
34 yaffs_ftruncate(self.yaffs_handle, length_of_file)
35 yaffs_close(self.yaffs_handle)
37 self.yaffs_handle = yaffs_open(self.file_path,66,0666)
41 global current_directory_dict
42 x=name_list_box.curselection()
44 self.file_editor_root =tk.Toplevel()
45 self.save_button=tk.Button(self.file_editor_root, text="save", command=self.save_file)
46 self.save_button.pack()
48 self.file_path=current_directory_dict[self.id]["path"]
49 print "file path", self.file_path
50 self.file_editor_root.title(current_directory_dict[self.id]["path"])
51 self.file_editor_text=tk.Text(self.file_editor_root)
52 self.yaffs_handle = yaffs_open(current_directory_dict[self.id]["path"],66,0666)
53 length_of_file=yaffs_lseek(self.yaffs_handle, 0, 2) ##seeks to the end of the file
54 yaffs_lseek(self.yaffs_handle, 0, 0)## returns the handle to the front of th file
55 self.file_contents=ctypes.create_string_buffer(length_of_file)
56 yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
57 print "file contents", self.file_contents.raw
58 self.file_editor_text.insert(tk.END, self.file_contents.raw)
59 self.file_editor_text.pack()
60 ##self.file_editor_text.bind("<Control-s>", self.save_file)
61 ##doesn't work because it can't pass "self"
64 global current_directory_dict
65 print "loading a new directory*******************************************************************"
66 name_list_box.delete(0, tk.END)
67 current_directory_dict=yaffs_ls(mount_list_text_variable.get())
68 print "new directory", current_directory_dict
69 ##copy directory into file box
70 for x in range(0,len(current_directory_dict)):
71 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"]))
72 name_list_box.grid(column=0, row=1)
73 return current_directory_dict
76 global open_windows_list
77 open_windows_list.append(editor())
79 def load_command(self=0):
80 global current_directory_dict
81 print "you loaded a file/dir"
82 x=name_list_box.curselection()
84 print "cursor selection", x
85 print "dict", current_directory_dict
87 print "file inode is:", current_directory_dict[x]["inodes"]
90 print "file path is:", current_directory_dict[x]["path"]
91 if current_directory_dict[x]["type"]=="dir":
93 print "open directory"
94 mount_list_text_variable.set(current_directory_dict[x]["path"])
95 print mount_list_text_variable.get()
96 print "old directory dict", current_directory_dict
97 #current_directory_dict=load_dir()
100 print "new directory dict passed back"
102 elif current_directory_dict[x]["type"]=="file" :
108 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
110 def back_a_directory(self=0):
111 x=len(mount_list_text_variable.get())
112 string=mount_list_text_variable.get()
114 #print "length of path", x
115 #print "string been sorted:", string
116 for i in range(0, x):
119 #print "slash found at:", i
122 ##slashes_id.sort() not needed because the list is already in acending order
123 ##print "sorted",slashes_id
125 string=string[0: slashes_id[len(slashes_id)-2]+1]
127 mount_list_text_variable.set(string)
138 if dname[-1] != "/": dname = dname + "/"
139 dc = yaffs_opendir(dname)
141 sep = yaffs_readdir(dc)
145 fullname = dname + se.d_name
146 st = yaffs_stat_struct()
147 result = yaffs_stat(fullname,byref(st))
148 perms = st.st_mode & 0777
149 isFile = True if st.st_mode & 0x8000 else False
150 isDir = True if st.st_mode & 0x4000 else False
153 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
155 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/"})
158 # ls_dict.append( "Other ("+hex(st.st_mode)+") "+se.d_ino, hex(perms)+ fullname)
159 sep = yaffs_readdir(dc)
163 print "Could not open directory"
168 toolbar_frame=tk.Frame(root_window)
169 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
170 button_open.grid(column=0, row=0)
171 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
172 button_back.grid(column=1, row=0)
173 toolbar_frame.grid(row=0, column=0, columnspan=3)
175 def delete_selected(selected_dir=0):
177 print"using current_directory_dict"
178 global current_directory_dict
179 x=name_list_box.curselection()
181 print current_directory_dict[x]["type"]
182 if current_directory_dict[x]["type"]=="file":
183 path=current_directory_dict[x]["path"]
185 output=yaffs_unlink(path)
186 print "unlinking output:", output
187 elif current_directory_dict[x]["type"]=="dir":
188 path=current_directory_dict[x]["path"]
189 inside_dir=yaffs_ls(path)
190 print "files and folder inside dir", inside_dir
191 print "len of dir", len(inside_dir)
192 if inside_dir!=[]: ##if the dir is not empty
193 ## remove stuff in dir
194 for i in range(0,len(inside_dir)):
195 print "calling self*****"
196 delete_selected(inside_dir[i])
198 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
199 print "removing:", path
200 output=yaffs_rmdir(path)
201 print "rmdir output:", output
203 print "using passed dir"
204 print "dir passed", selected_dir
205 current_directory_dict =selected_dir
207 print "after copying", current_directory_dict
208 print current_directory_dict["type"]
209 if current_directory_dict["type"]=="file":
210 path=current_directory_dict["path"]
212 output=yaffs_unlink(path)
213 print "unlinking output:", output
214 elif current_directory_dict["type"]=="dir":
215 path=current_directory_dict["path"]
216 inside_dir=yaffs_ls(path)
217 print "files and folder inside dir", inside_dir
218 print "len of dir", len(inside_dir)
219 if inside_dir!=[]: ##if the dir is not empty
220 ## remove stuff in dir
221 for i in range(0,len(inside_dir)):
222 print "calling self*****"
223 delete_selected(inside_dir[i])
225 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
226 print "removing:", path
227 output=yaffs_rmdir(path)
228 print "rmdir output:", output
239 def open_the_file(self):
240 global mount_list_text_variable
241 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
242 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
243 yaffs_close(yaffs_handle)
244 self.new_file_window.destroy()
249 self.new_file_window.destroy()
251 global mount_list_text_variable
252 self.new_file_window =tk.Toplevel(takefocus=True)
253 path_frame=tk.Frame(self.new_file_window)
254 path_label=tk.Label(path_frame, text="file path")
255 path_label.pack(side=tk.LEFT)
257 text.set(mount_list_text_variable.get())
258 print "############################",mount_list_text_variable.get()
259 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
260 self.path_entry_box.pack(side=tk.RIGHT)
262 button_frame=tk.Frame(self.new_file_window)
263 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
264 create_button.pack(side=tk.LEFT)
265 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
266 cancel_button.pack(side=tk.RIGHT)
272 def create_the_folder(self):
273 global mount_list_text_variable
274 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
275 yaffs_mkdir(self.path_entry_box.get(),0666)
276 self.new_folder_window.destroy()
282 self.new_folder_window.destroy()
284 global mount_list_text_variable
285 self.new_folder_window =tk.Toplevel(takefocus=True)
286 path_frame=tk.Frame(self.new_folder_window)
287 path_label=tk.Label(path_frame, text="directory path")
288 path_label.pack(side=tk.LEFT)
290 text.set(mount_list_text_variable.get())
291 print "############################",mount_list_text_variable.get()
292 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
293 self.path_entry_box.pack(side=tk.RIGHT)
295 button_frame=tk.Frame(self.new_folder_window)
296 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
297 create_button.pack(side=tk.LEFT)
298 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
299 cancel_button.pack(side=tk.RIGHT)
305 ##mount list entry box init
306 mount_list_frame=tk.Frame(root_window)
307 mount_list_label=tk.Label(mount_list_frame, text="mount list")
308 mount_list_label.pack(side=tk.RIGHT)
310 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
311 mount_list_entry_box.pack(side=tk.RIGHT)
312 mount_list_frame.grid(row=1, column=0, columnspan=2)
315 list_frame=tk.Frame(root_window)
316 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=50)
320 name_list_box.bind("<Double-Button-1>", load_command)
322 browser_menu_bar=tk.Menu(root_window)
323 browser_file_menu=tk.Menu(browser_menu_bar)
325 browser_file_menu.add_command(label="Reload", command=load_dir)
326 #browser_file_menu.add_command(label="Open")
327 #browser_file_menu.add_command(label="Save")
328 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
329 root_window.config(menu=browser_menu_bar)
332 browser_edit_menu=tk.Menu(browser_menu_bar)
334 browser_edit_menu.add_command(label="New File", command=new_file)
335 browser_edit_menu.add_command(label="New Folder", command=new_folder)
336 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
337 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
344 root_window.mainloop()
346 print"unmounting yaffs:", yaffs_unmount("yaffs2/")