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
73 if isLink==True and False ==True : ##this alows the symlink to be edited and is no longer used. to renable it delete "and False ==True"
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 ##deleate current items in text box
92 name_list_box.delete(0, tk.END)
93 current_directory_dict=yaffs_ls(mount_list_text_variable.get())
94 print "new directory", current_directory_dict
95 ##copy directory into file box
96 for x in range(0,len(current_directory_dict)):
97 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"]))
98 name_list_box.grid(column=0, row=1)
99 return current_directory_dict
102 ##this isn't working. somethihg need to be changed in the config of the simulator to release the handle of the emfile
103 print "remounting yaffs"
104 print"unmounting yaffs:", yaffs_unmount("yaffs2/")
105 print "mounting yaffs", yaffs_mount("/yaffs2/")
108 def load_file(link=0):
109 global open_windows_list
110 open_windows_list.append(editor(link))
112 def load_command(self=0):
113 global current_directory_dictls
115 print "you loaded a file/dir/link"
116 x=name_list_box.curselection()
118 print "cursor selection", x
119 print "dict", current_directory_dict
121 print "file inode is:", current_directory_dict[x]["inodes"]
124 print "file path is:", current_directory_dict[x]["path"]
125 if current_directory_dict[x]["type"]=="dir":
127 print "open directory"
128 mount_list_text_variable.set(current_directory_dict[x]["path"])
129 print mount_list_text_variable.get()
130 print "old directory dict", current_directory_dict
131 #current_directory_dict=load_dir()
134 print "new directory dict passed back"
136 elif current_directory_dict[x]["type"]=="file" :
140 elif current_directory_dict[x]["type"]=="link":
141 print "loading a symlink"
143 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
145 def back_a_directory(self=0):
146 x=len(mount_list_text_variable.get())
147 string=mount_list_text_variable.get()
149 #print "length of path", x
150 #print "string been sorted:", string
151 for i in range(0, x):
154 #print "slash found at:", i
157 ##slashes_id.sort() not needed because the list is already in acending order
158 ##print "sorted",slashes_id
160 string=string[0: slashes_id[len(slashes_id)-2]+1]
162 mount_list_text_variable.set(string)
173 if dname[-1] != "/": dname = dname + "/"
174 dc = yaffs_opendir(dname)
176 sep = yaffs_readdir(dc)
180 fullname = dname + se.d_name
181 st = yaffs_stat_struct()
182 result = yaffs_lstat(fullname,byref(st))
183 perms = st.st_mode & 0777
184 ftype = st.st_mode & yaffs_S_IFMT
185 isFile = True if ftype == yaffs_S_IFREG else False
186 isDir = True if ftype == yaffs_S_IFDIR else False
187 isSymlink= True if ftype == yaffs_S_IFLNK else False
190 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname,"extra_data":""})
191 print "file st.st_mode:", st.st_mode
194 print "dir st.st_mode:", st.st_mode
196 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/", "extra_data":""})
198 print "symlink st.st_mode:", st.st_mode
199 file_contents=ctypes.create_string_buffer(30)
200 yaffs_readlink(fullname,file_contents,30)
201 string=repr(file_contents.value)
202 print "len of str", len(string)
205 print "string", string, "###"
207 ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname, "extra_data":"> "+string})
210 print "unknown st.st_mode:", st.st_mode
211 ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname,"extra_data":""})
212 sep = yaffs_readdir(dc)
216 print "Could not open directory"
221 toolbar_frame=tk.Frame(root_window)
222 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
223 button_open.grid(column=0, row=0)
224 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
225 button_back.grid(column=1, row=0)
226 toolbar_frame.grid(row=0, column=0, columnspan=3)
228 def delete_selected(selected_dir=0):
230 print"using current_directory_dict"
231 global current_directory_dict
232 x=name_list_box.curselection()
234 print current_directory_dict[x]["type"]
235 if current_directory_dict[x]["type"]=="file":
236 path=current_directory_dict[x]["path"]
238 output=yaffs_unlink(path)
239 print "unlinking output:", output
240 elif current_directory_dict[x]["type"]=="dir":
241 path=current_directory_dict[x]["path"]
242 inside_dir=yaffs_ls(path)
243 print "files and folder inside dir", inside_dir
244 print "len of dir", len(inside_dir)
245 if inside_dir!=[]: ##if the dir is not empty
246 ## remove stuff in dir
247 for i in range(0,len(inside_dir)):
248 print "calling self*****"
249 delete_selected(inside_dir[i])
251 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
252 print "removing:", path
253 output=yaffs_rmdir(path)
254 print "rmdir output:", output
256 print "using passed dir"
257 print "dir passed", selected_dir
258 current_directory_dict =selected_dir
260 print "after copying", current_directory_dict
261 print current_directory_dict["type"]
262 if current_directory_dict["type"]=="file":
263 path=current_directory_dict["path"]
265 output=yaffs_unlink(path)
266 print "unlinking output:", output
267 elif current_directory_dict["type"]=="dir":
268 path=current_directory_dict["path"]
269 inside_dir=yaffs_ls(path)
270 print "files and folder inside dir", inside_dir
271 print "len of dir", len(inside_dir)
272 if inside_dir!=[]: ##if the dir is not empty
273 ## remove stuff in dir
274 for i in range(0,len(inside_dir)):
275 print "calling self*****"
276 delete_selected(inside_dir[i])
278 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
279 print "removing:", path
280 output=yaffs_rmdir(path)
281 print "rmdir output:", output
290 def open_the_file(self):
291 global mount_list_text_variable
292 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
293 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
294 yaffs_close(yaffs_handle)
295 self.new_file_window.destroy()
300 self.new_file_window.destroy()
302 global mount_list_text_variable
303 self.new_file_window =tk.Toplevel(takefocus=True)
304 path_frame=tk.Frame(self.new_file_window)
305 path_label=tk.Label(path_frame, text="file path")
306 path_label.pack(side=tk.LEFT)
308 text.set(mount_list_text_variable.get())
309 print "############################",mount_list_text_variable.get()
310 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
311 self.path_entry_box.pack(side=tk.RIGHT)
313 button_frame=tk.Frame(self.new_file_window)
314 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
315 create_button.pack(side=tk.LEFT)
316 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
317 cancel_button.pack(side=tk.RIGHT)
323 def create_the_folder(self):
324 global mount_list_text_variable
325 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
326 yaffs_mkdir(self.path_entry_box.get(),0666)
327 self.new_folder_window.destroy()
333 self.new_folder_window.destroy()
335 global mount_list_text_variable
336 self.new_folder_window =tk.Toplevel(takefocus=True)
337 path_frame=tk.Frame(self.new_folder_window)
338 path_label=tk.Label(path_frame, text="directory path")
339 path_label.pack(side=tk.LEFT)
341 text.set(mount_list_text_variable.get())
342 print "############################",mount_list_text_variable.get()
343 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
344 self.path_entry_box.pack(side=tk.RIGHT)
346 button_frame=tk.Frame(self.new_folder_window)
347 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
348 create_button.pack(side=tk.LEFT)
349 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
350 cancel_button.pack(side=tk.RIGHT)
359 def create_the_symlink(self):
360 global mount_list_text_variable
361 ##check the symlink's target is a file.
362 target_path=self.target_text.get()
363 new_path=self.new_text.get()
364 print "creating a symlink \n target:", target_path
365 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
366 if target_file_exists>=0:
367 ##file exists,create symlink
368 print "target file exist, creating symlink"
369 yaffs_symlink(target_path, new_path)
370 self.new_file_window.destroy()
372 ##file does not exist
373 print "target file does not exist, cannot create symlink"
378 self.new_file_window.destroy()
380 global mount_list_text_variable
381 self.new_file_window =tk.Toplevel(takefocus=True)
382 target_frame=tk.Frame(self.new_file_window)
383 target_label=tk.Label(target_frame, text="target")
384 target_label.pack(side=tk.LEFT)
385 self.target_text=tk.StringVar()
386 self.target_text.set(mount_list_text_variable.get())
387 #print "############################",mount_list_text_variable.get()
388 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
389 self.target_entry_box.pack(side=tk.RIGHT)
392 new_frame=tk.Frame(self.new_file_window)
393 new_label=tk.Label(new_frame, text="file path")
394 new_label.pack(side=tk.LEFT)
395 self.new_text=tk.StringVar()
396 self.new_text.set(mount_list_text_variable.get())
397 #print "############################",mount_list_text_variable.get()
398 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
399 self.new_entry_box.pack(side=tk.RIGHT)
402 button_frame=tk.Frame(self.new_file_window)
403 create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
404 create_button.pack(side=tk.LEFT)
405 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
406 cancel_button.pack(side=tk.RIGHT)
411 class new_hardlink():
416 def create_the_hardlink(self):
417 global mount_list_text_variable
418 ##check the symlink's target is a file.
419 target_path=self.target_text.get()
420 new_path=self.new_text.get()
421 print "creating a hardlink \n target:", target_path
422 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
423 if target_file_exists>=0:
424 ##file exists,create symlink
425 print "target file exist, creating hardlink"
426 yaffs_link(target_path, new_path)
427 self.new_file_window.destroy()
429 ##file does not exist
430 print "target file does not exist, cannot create hardlink"
435 self.new_file_window.destroy()
437 global mount_list_text_variable
438 self.new_file_window =tk.Toplevel(takefocus=True)
439 target_frame=tk.Frame(self.new_file_window)
440 target_label=tk.Label(target_frame, text="target")
441 target_label.pack(side=tk.LEFT)
442 self.target_text=tk.StringVar()
443 self.target_text.set(mount_list_text_variable.get())
444 #print "############################",mount_list_text_variable.get()
445 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
446 self.target_entry_box.pack(side=tk.RIGHT)
449 new_frame=tk.Frame(self.new_file_window)
450 new_label=tk.Label(new_frame, text="file path")
451 new_label.pack(side=tk.LEFT)
452 self.new_text=tk.StringVar()
453 self.new_text.set(mount_list_text_variable.get())
454 #print "############################",mount_list_text_variable.get()
455 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
456 self.new_entry_box.pack(side=tk.RIGHT)
459 button_frame=tk.Frame(self.new_file_window)
460 create_button=tk.Button(button_frame, text="Create", command=self.create_the_hardlink)
461 create_button.pack(side=tk.LEFT)
462 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
463 cancel_button.pack(side=tk.RIGHT)
467 ##mount list entry box init
468 mount_list_frame=tk.Frame(root_window)
469 mount_list_label=tk.Label(mount_list_frame, text="mount list")
470 mount_list_label.pack(side=tk.RIGHT)
472 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
473 mount_list_entry_box.pack(side=tk.RIGHT)
474 mount_list_frame.grid(row=1, column=0, columnspan=2)
477 list_frame=tk.Frame(root_window)
478 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=80)
480 list_frame.grid(sticky=tk.W+tk.E+tk.N+tk.S)
482 name_list_box.bind("<Double-Button-1>", load_command)
484 browser_menu_bar=tk.Menu(root_window)
485 browser_file_menu=tk.Menu(browser_menu_bar)
487 browser_file_menu.add_command(label="Reload", command=load_dir)
488 browser_file_menu.add_command(label="Remount yaffs", command=remount_yaffs)
490 #browser_file_menu.add_command(label="Open")
491 #browser_file_menu.add_command(label="Save")
492 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
493 root_window.config(menu=browser_menu_bar)
496 browser_edit_menu=tk.Menu(browser_menu_bar)
498 browser_edit_menu.add_command(label="New File", command=new_file)
499 browser_edit_menu.add_command(label="New Folder", command=new_folder)
500 browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
501 browser_edit_menu.add_command(label="New Hardlink", command=new_hardlink)
504 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
505 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
512 root_window.mainloop()
514 print"unmounting yaffs:", yaffs_unmount("yaffs2/")