8 yaffs_mount("/yaffs2/")
10 root_window.title("YAFFS Browser")
11 mount_list_text_variable=tk.StringVar()
13 mount_list_text_variable.set("/yaffs2/")
14 current_directory_dict={}
26 target_path=self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
27 target_path=target_path[0:len(target_path)-1]
28 new_path=self.file_path
29 print "creating a symlink \n target:##", target_path, "##"
30 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
31 if target_file_exists>=0:
32 ##file exists,create symlink
33 print "target file exist, creating symlink"
34 yaffs_unlink(new_path)
35 output=yaffs_symlink(target_path, new_path)
36 print "yaffs symlink output=", output
37 self.file_editor_root.destroy()
40 print "target file does not exist, cannot create symlink"
42 #global current_directory_dict
43 print "saving the file"
44 print self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
45 yaffs_lseek(self.yaffs_handle, 0, 0)
46 data_to_be_written=self.file_editor_text.get("1.0", tk.END)
47 print "data to be saved", data_to_be_written
48 length_of_file=len(data_to_be_written)
49 print "length of data to be written",length_of_file
50 output=yaffs_write(self.yaffs_handle,data_to_be_written , length_of_file)
51 print "output", output
52 yaffs_ftruncate(self.yaffs_handle, length_of_file)
53 yaffs_close(self.yaffs_handle)
54 self.yaffs_handle = yaffs_open(self.file_path,66,0666)
57 def __init__(self, isLink=0):
58 global current_directory_dict
59 x=name_list_box.curselection()
61 self.file_editor_root =tk.Toplevel()
62 self.save_button=tk.Button(self.file_editor_root, text="save", command=self.save_file)
63 self.save_button.pack(fill=tk.BOTH)
65 self.file_path=current_directory_dict[self.id]["path"]
66 print "file path", self.file_path
67 self.file_editor_root.title(current_directory_dict[self.id]["path"])
68 self.file_editor_text=tk.Text(self.file_editor_root)
69 self.yaffs_handle = yaffs_open(current_directory_dict[self.id]["path"],66,0666)
70 length_of_file=yaffs_lseek(self.yaffs_handle, 0, 2) ##seeks to the end of the file
71 yaffs_lseek(self.yaffs_handle, 0, 0)## returns the handle to the front of th file
72 print "length of file to be opened:", length_of_file
74 print "opening symlink"
75 self.file_contents=ctypes.create_string_buffer(1000)
76 yaffs_readlink(self.file_path,self.file_contents,1000)
80 self.file_contents=ctypes.create_string_buffer(length_of_file)
81 yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
82 print "file contents", self.file_contents.raw
83 self.file_editor_text.insert(tk.END, self.file_contents.raw)
84 self.file_editor_text.pack(fill=tk.BOTH)
85 ##self.file_editor_text.bind("<Control-s>", self.save_file)
86 ##doesn't work because it can't pass "self"
89 global current_directory_dict
90 print "loading a new directory*******************************************************************"
91 name_list_box.delete(0, tk.END)
92 current_directory_dict=yaffs_ls(mount_list_text_variable.get())
93 print "new directory", current_directory_dict
94 ##copy directory into file box
95 for x in range(0,len(current_directory_dict)):
96 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"]+" "+current_directory_dict[x]["extra_data"]))
97 name_list_box.grid(column=0, row=1)
98 return current_directory_dict
100 def load_file(link=0):
101 global open_windows_list
102 open_windows_list.append(editor(link))
104 def load_command(self=0):
105 global current_directory_dict
106 print "you loaded a file/dir/link"
107 x=name_list_box.curselection()
109 print "cursor selection", x
110 print "dict", current_directory_dict
112 print "file inode is:", current_directory_dict[x]["inodes"]
115 print "file path is:", current_directory_dict[x]["path"]
116 if current_directory_dict[x]["type"]=="dir":
118 print "open directory"
119 mount_list_text_variable.set(current_directory_dict[x]["path"])
120 print mount_list_text_variable.get()
121 print "old directory dict", current_directory_dict
122 #current_directory_dict=load_dir()
125 print "new directory dict passed back"
127 elif current_directory_dict[x]["type"]=="file" :
131 elif current_directory_dict[x]["type"]=="link":
132 print "loading a symlink"
134 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
136 def back_a_directory(self=0):
137 x=len(mount_list_text_variable.get())
138 string=mount_list_text_variable.get()
140 #print "length of path", x
141 #print "string been sorted:", string
142 for i in range(0, x):
145 #print "slash found at:", i
148 ##slashes_id.sort() not needed because the list is already in acending order
149 ##print "sorted",slashes_id
151 string=string[0: slashes_id[len(slashes_id)-2]+1]
153 mount_list_text_variable.set(string)
164 if dname[-1] != "/": dname = dname + "/"
165 dc = yaffs_opendir(dname)
167 sep = yaffs_readdir(dc)
171 fullname = dname + se.d_name
172 st = yaffs_stat_struct()
173 result = yaffs_lstat(fullname,byref(st))
174 perms = st.st_mode & 0777
175 ftype = st.st_mode & yaffs_S_IFMT
176 isFile = True if ftype == yaffs_S_IFREG else False
177 isDir = True if ftype == yaffs_S_IFDIR else False
178 isSymlink= True if ftype == yaffs_S_IFLNK else False
181 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname,"extra_data":""})
182 print "file st.st_mode:", st.st_mode
185 print "dir st.st_mode:", st.st_mode
187 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/", "extra_data":""})
189 print "symlink st.st_mode:", st.st_mode
190 file_contents=ctypes.create_string_buffer(30)
191 yaffs_readlink(fullname,file_contents,30)
192 string=repr(file_contents.value)
193 print "len of str", len(string)
196 print "string", string, "###"
198 ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname, "extra_data":"> "+string})
201 print "unknown st.st_mode:", st.st_mode
202 ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname,"extra_data":""})
203 sep = yaffs_readdir(dc)
207 print "Could not open directory"
212 toolbar_frame=tk.Frame(root_window)
213 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
214 button_open.grid(column=0, row=0)
215 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
216 button_back.grid(column=1, row=0)
217 toolbar_frame.grid(row=0, column=0, columnspan=3)
219 def delete_selected(selected_dir=0):
221 print"using current_directory_dict"
222 global current_directory_dict
223 x=name_list_box.curselection()
225 print current_directory_dict[x]["type"]
226 if current_directory_dict[x]["type"]=="file":
227 path=current_directory_dict[x]["path"]
229 output=yaffs_unlink(path)
230 print "unlinking output:", output
231 elif current_directory_dict[x]["type"]=="dir":
232 path=current_directory_dict[x]["path"]
233 inside_dir=yaffs_ls(path)
234 print "files and folder inside dir", inside_dir
235 print "len of dir", len(inside_dir)
236 if inside_dir!=[]: ##if the dir is not empty
237 ## remove stuff in dir
238 for i in range(0,len(inside_dir)):
239 print "calling self*****"
240 delete_selected(inside_dir[i])
242 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
243 print "removing:", path
244 output=yaffs_rmdir(path)
245 print "rmdir output:", output
247 print "using passed dir"
248 print "dir passed", selected_dir
249 current_directory_dict =selected_dir
251 print "after copying", current_directory_dict
252 print current_directory_dict["type"]
253 if current_directory_dict["type"]=="file":
254 path=current_directory_dict["path"]
256 output=yaffs_unlink(path)
257 print "unlinking output:", output
258 elif current_directory_dict["type"]=="dir":
259 path=current_directory_dict["path"]
260 inside_dir=yaffs_ls(path)
261 print "files and folder inside dir", inside_dir
262 print "len of dir", len(inside_dir)
263 if inside_dir!=[]: ##if the dir is not empty
264 ## remove stuff in dir
265 for i in range(0,len(inside_dir)):
266 print "calling self*****"
267 delete_selected(inside_dir[i])
269 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
270 print "removing:", path
271 output=yaffs_rmdir(path)
272 print "rmdir output:", output
283 def open_the_file(self):
284 global mount_list_text_variable
285 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
286 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
287 yaffs_close(yaffs_handle)
288 self.new_file_window.destroy()
293 self.new_file_window.destroy()
295 global mount_list_text_variable
296 self.new_file_window =tk.Toplevel(takefocus=True)
297 path_frame=tk.Frame(self.new_file_window)
298 path_label=tk.Label(path_frame, text="file path")
299 path_label.pack(side=tk.LEFT)
301 text.set(mount_list_text_variable.get())
302 print "############################",mount_list_text_variable.get()
303 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
304 self.path_entry_box.pack(side=tk.RIGHT)
306 button_frame=tk.Frame(self.new_file_window)
307 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
308 create_button.pack(side=tk.LEFT)
309 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
310 cancel_button.pack(side=tk.RIGHT)
316 def create_the_folder(self):
317 global mount_list_text_variable
318 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
319 yaffs_mkdir(self.path_entry_box.get(),0666)
320 self.new_folder_window.destroy()
326 self.new_folder_window.destroy()
328 global mount_list_text_variable
329 self.new_folder_window =tk.Toplevel(takefocus=True)
330 path_frame=tk.Frame(self.new_folder_window)
331 path_label=tk.Label(path_frame, text="directory path")
332 path_label.pack(side=tk.LEFT)
334 text.set(mount_list_text_variable.get())
335 print "############################",mount_list_text_variable.get()
336 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
337 self.path_entry_box.pack(side=tk.RIGHT)
339 button_frame=tk.Frame(self.new_folder_window)
340 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
341 create_button.pack(side=tk.LEFT)
342 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
343 cancel_button.pack(side=tk.RIGHT)
352 def create_the_symlink(self):
353 global mount_list_text_variable
354 ##check the symlink's target is a file.
355 target_path=self.target_text.get()
356 new_path=self.new_text.get()
357 print "creating a symlink \n target:", target_path
358 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
359 if target_file_exists>=0:
360 ##file exists,create symlink
361 print "target file exist, creating symlink"
362 yaffs_symlink(target_path, new_path)
363 self.new_file_window.destroy()
365 ##file does not exist
366 print "target file does not exist, cannot create symlink"
371 self.new_file_window.destroy()
373 global mount_list_text_variable
374 self.new_file_window =tk.Toplevel(takefocus=True)
375 target_frame=tk.Frame(self.new_file_window)
376 target_label=tk.Label(target_frame, text="target")
377 target_label.pack(side=tk.LEFT)
378 self.target_text=tk.StringVar()
379 self.target_text.set(mount_list_text_variable.get())
380 #print "############################",mount_list_text_variable.get()
381 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
382 self.target_entry_box.pack(side=tk.RIGHT)
385 new_frame=tk.Frame(self.new_file_window)
386 new_label=tk.Label(new_frame, text="file path")
387 new_label.pack(side=tk.LEFT)
388 self.new_text=tk.StringVar()
389 self.new_text.set(mount_list_text_variable.get())
390 #print "############################",mount_list_text_variable.get()
391 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
392 self.new_entry_box.pack(side=tk.RIGHT)
395 button_frame=tk.Frame(self.new_file_window)
396 create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
397 create_button.pack(side=tk.LEFT)
398 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
399 cancel_button.pack(side=tk.RIGHT)
404 class new_hardlink():
409 def create_the_hardlink(self):
410 global mount_list_text_variable
411 ##check the symlink's target is a file.
412 target_path=self.target_text.get()
413 new_path=self.new_text.get()
414 print "creating a hardlink \n target:", target_path
415 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
416 if target_file_exists>=0:
417 ##file exists,create symlink
418 print "target file exist, creating hardlink"
419 yaffs_link(target_path, new_path)
420 self.new_file_window.destroy()
422 ##file does not exist
423 print "target file does not exist, cannot create hardlink"
428 self.new_file_window.destroy()
430 global mount_list_text_variable
431 self.new_file_window =tk.Toplevel(takefocus=True)
432 target_frame=tk.Frame(self.new_file_window)
433 target_label=tk.Label(target_frame, text="target")
434 target_label.pack(side=tk.LEFT)
435 self.target_text=tk.StringVar()
436 self.target_text.set(mount_list_text_variable.get())
437 #print "############################",mount_list_text_variable.get()
438 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
439 self.target_entry_box.pack(side=tk.RIGHT)
442 new_frame=tk.Frame(self.new_file_window)
443 new_label=tk.Label(new_frame, text="file path")
444 new_label.pack(side=tk.LEFT)
445 self.new_text=tk.StringVar()
446 self.new_text.set(mount_list_text_variable.get())
447 #print "############################",mount_list_text_variable.get()
448 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
449 self.new_entry_box.pack(side=tk.RIGHT)
452 button_frame=tk.Frame(self.new_file_window)
453 create_button=tk.Button(button_frame, text="Create", command=self.create_the_hardlink)
454 create_button.pack(side=tk.LEFT)
455 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
456 cancel_button.pack(side=tk.RIGHT)
460 ##mount list entry box init
461 mount_list_frame=tk.Frame(root_window)
462 mount_list_label=tk.Label(mount_list_frame, text="mount list")
463 mount_list_label.pack(side=tk.RIGHT)
465 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
466 mount_list_entry_box.pack(side=tk.RIGHT)
467 mount_list_frame.grid(row=1, column=0, columnspan=2)
470 list_frame=tk.Frame(root_window)
471 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=80)
473 list_frame.grid(sticky=tk.W+tk.E+tk.N+tk.S)
475 name_list_box.bind("<Double-Button-1>", load_command)
477 browser_menu_bar=tk.Menu(root_window)
478 browser_file_menu=tk.Menu(browser_menu_bar)
480 browser_file_menu.add_command(label="Reload", command=load_dir)
481 #browser_file_menu.add_command(label="Open")
482 #browser_file_menu.add_command(label="Save")
483 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
484 root_window.config(menu=browser_menu_bar)
487 browser_edit_menu=tk.Menu(browser_menu_bar)
489 browser_edit_menu.add_command(label="New File", command=new_file)
490 browser_edit_menu.add_command(label="New Folder", command=new_folder)
491 browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
492 browser_edit_menu.add_command(label="New Hardlink", command=new_hardlink)
495 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
496 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
503 root_window.mainloop()
505 print"unmounting yaffs:", yaffs_unmount("yaffs2/")