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 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
101 ##this isn't working. somethihg need to be changed in the config of the simulator to release the handle of the emfile
102 print "remounting yaffs"
103 print"unmounting yaffs:", yaffs_unmount("yaffs2/")
104 print "mounting yaffs", yaffs_mount("/yaffs2/")
107 def load_file(link=0):
108 global open_windows_list
109 open_windows_list.append(editor(link))
111 def load_command(self=0):
112 global current_directory_dictls
114 print "you loaded a file/dir/link"
115 x=name_list_box.curselection()
117 print "cursor selection", x
118 print "dict", current_directory_dict
120 print "file inode is:", current_directory_dict[x]["inodes"]
123 print "file path is:", current_directory_dict[x]["path"]
124 if current_directory_dict[x]["type"]=="dir":
126 print "open directory"
127 mount_list_text_variable.set(current_directory_dict[x]["path"])
128 print mount_list_text_variable.get()
129 print "old directory dict", current_directory_dict
130 #current_directory_dict=load_dir()
133 print "new directory dict passed back"
135 elif current_directory_dict[x]["type"]=="file" :
139 elif current_directory_dict[x]["type"]=="link":
140 print "loading a symlink"
142 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
144 def back_a_directory(self=0):
145 x=len(mount_list_text_variable.get())
146 string=mount_list_text_variable.get()
148 #print "length of path", x
149 #print "string been sorted:", string
150 for i in range(0, x):
153 #print "slash found at:", i
156 ##slashes_id.sort() not needed because the list is already in acending order
157 ##print "sorted",slashes_id
159 string=string[0: slashes_id[len(slashes_id)-2]+1]
161 mount_list_text_variable.set(string)
172 if dname[-1] != "/": dname = dname + "/"
173 dc = yaffs_opendir(dname)
175 sep = yaffs_readdir(dc)
179 fullname = dname + se.d_name
180 st = yaffs_stat_struct()
181 result = yaffs_lstat(fullname,byref(st))
182 perms = st.st_mode & 0777
183 ftype = st.st_mode & yaffs_S_IFMT
184 isFile = True if ftype == yaffs_S_IFREG else False
185 isDir = True if ftype == yaffs_S_IFDIR else False
186 isSymlink= True if ftype == yaffs_S_IFLNK else False
189 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname,"extra_data":""})
190 print "file st.st_mode:", st.st_mode
193 print "dir st.st_mode:", st.st_mode
195 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/", "extra_data":""})
197 print "symlink st.st_mode:", st.st_mode
198 file_contents=ctypes.create_string_buffer(30)
199 yaffs_readlink(fullname,file_contents,30)
200 string=repr(file_contents.value)
201 print "len of str", len(string)
204 print "string", string, "###"
206 ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname, "extra_data":"> "+string})
209 print "unknown st.st_mode:", st.st_mode
210 ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname,"extra_data":""})
211 sep = yaffs_readdir(dc)
215 print "Could not open directory"
220 toolbar_frame=tk.Frame(root_window)
221 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
222 button_open.grid(column=0, row=0)
223 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
224 button_back.grid(column=1, row=0)
225 toolbar_frame.grid(row=0, column=0, columnspan=3)
227 def delete_selected(selected_dir=0):
229 print"using current_directory_dict"
230 global current_directory_dict
231 x=name_list_box.curselection()
233 print current_directory_dict[x]["type"]
234 if current_directory_dict[x]["type"]=="file":
235 path=current_directory_dict[x]["path"]
237 output=yaffs_unlink(path)
238 print "unlinking output:", output
239 elif current_directory_dict[x]["type"]=="dir":
240 path=current_directory_dict[x]["path"]
241 inside_dir=yaffs_ls(path)
242 print "files and folder inside dir", inside_dir
243 print "len of dir", len(inside_dir)
244 if inside_dir!=[]: ##if the dir is not empty
245 ## remove stuff in dir
246 for i in range(0,len(inside_dir)):
247 print "calling self*****"
248 delete_selected(inside_dir[i])
250 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
251 print "removing:", path
252 output=yaffs_rmdir(path)
253 print "rmdir output:", output
255 print "using passed dir"
256 print "dir passed", selected_dir
257 current_directory_dict =selected_dir
259 print "after copying", current_directory_dict
260 print current_directory_dict["type"]
261 if current_directory_dict["type"]=="file":
262 path=current_directory_dict["path"]
264 output=yaffs_unlink(path)
265 print "unlinking output:", output
266 elif current_directory_dict["type"]=="dir":
267 path=current_directory_dict["path"]
268 inside_dir=yaffs_ls(path)
269 print "files and folder inside dir", inside_dir
270 print "len of dir", len(inside_dir)
271 if inside_dir!=[]: ##if the dir is not empty
272 ## remove stuff in dir
273 for i in range(0,len(inside_dir)):
274 print "calling self*****"
275 delete_selected(inside_dir[i])
277 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
278 print "removing:", path
279 output=yaffs_rmdir(path)
280 print "rmdir output:", output
289 def open_the_file(self):
290 global mount_list_text_variable
291 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
292 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
293 yaffs_close(yaffs_handle)
294 self.new_file_window.destroy()
299 self.new_file_window.destroy()
301 global mount_list_text_variable
302 self.new_file_window =tk.Toplevel(takefocus=True)
303 path_frame=tk.Frame(self.new_file_window)
304 path_label=tk.Label(path_frame, text="file path")
305 path_label.pack(side=tk.LEFT)
307 text.set(mount_list_text_variable.get())
308 print "############################",mount_list_text_variable.get()
309 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
310 self.path_entry_box.pack(side=tk.RIGHT)
312 button_frame=tk.Frame(self.new_file_window)
313 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
314 create_button.pack(side=tk.LEFT)
315 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
316 cancel_button.pack(side=tk.RIGHT)
322 def create_the_folder(self):
323 global mount_list_text_variable
324 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
325 yaffs_mkdir(self.path_entry_box.get(),0666)
326 self.new_folder_window.destroy()
332 self.new_folder_window.destroy()
334 global mount_list_text_variable
335 self.new_folder_window =tk.Toplevel(takefocus=True)
336 path_frame=tk.Frame(self.new_folder_window)
337 path_label=tk.Label(path_frame, text="directory path")
338 path_label.pack(side=tk.LEFT)
340 text.set(mount_list_text_variable.get())
341 print "############################",mount_list_text_variable.get()
342 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
343 self.path_entry_box.pack(side=tk.RIGHT)
345 button_frame=tk.Frame(self.new_folder_window)
346 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
347 create_button.pack(side=tk.LEFT)
348 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
349 cancel_button.pack(side=tk.RIGHT)
358 def create_the_symlink(self):
359 global mount_list_text_variable
360 ##check the symlink's target is a file.
361 target_path=self.target_text.get()
362 new_path=self.new_text.get()
363 print "creating a symlink \n target:", target_path
364 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
365 if target_file_exists>=0:
366 ##file exists,create symlink
367 print "target file exist, creating symlink"
368 yaffs_symlink(target_path, new_path)
369 self.new_file_window.destroy()
371 ##file does not exist
372 print "target file does not exist, cannot create symlink"
377 self.new_file_window.destroy()
379 global mount_list_text_variable
380 self.new_file_window =tk.Toplevel(takefocus=True)
381 target_frame=tk.Frame(self.new_file_window)
382 target_label=tk.Label(target_frame, text="target")
383 target_label.pack(side=tk.LEFT)
384 self.target_text=tk.StringVar()
385 self.target_text.set(mount_list_text_variable.get())
386 #print "############################",mount_list_text_variable.get()
387 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
388 self.target_entry_box.pack(side=tk.RIGHT)
391 new_frame=tk.Frame(self.new_file_window)
392 new_label=tk.Label(new_frame, text="file path")
393 new_label.pack(side=tk.LEFT)
394 self.new_text=tk.StringVar()
395 self.new_text.set(mount_list_text_variable.get())
396 #print "############################",mount_list_text_variable.get()
397 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
398 self.new_entry_box.pack(side=tk.RIGHT)
401 button_frame=tk.Frame(self.new_file_window)
402 create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
403 create_button.pack(side=tk.LEFT)
404 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
405 cancel_button.pack(side=tk.RIGHT)
410 class new_hardlink():
415 def create_the_hardlink(self):
416 global mount_list_text_variable
417 ##check the symlink's target is a file.
418 target_path=self.target_text.get()
419 new_path=self.new_text.get()
420 print "creating a hardlink \n target:", target_path
421 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
422 if target_file_exists>=0:
423 ##file exists,create symlink
424 print "target file exist, creating hardlink"
425 yaffs_link(target_path, new_path)
426 self.new_file_window.destroy()
428 ##file does not exist
429 print "target file does not exist, cannot create hardlink"
434 self.new_file_window.destroy()
436 global mount_list_text_variable
437 self.new_file_window =tk.Toplevel(takefocus=True)
438 target_frame=tk.Frame(self.new_file_window)
439 target_label=tk.Label(target_frame, text="target")
440 target_label.pack(side=tk.LEFT)
441 self.target_text=tk.StringVar()
442 self.target_text.set(mount_list_text_variable.get())
443 #print "############################",mount_list_text_variable.get()
444 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
445 self.target_entry_box.pack(side=tk.RIGHT)
448 new_frame=tk.Frame(self.new_file_window)
449 new_label=tk.Label(new_frame, text="file path")
450 new_label.pack(side=tk.LEFT)
451 self.new_text=tk.StringVar()
452 self.new_text.set(mount_list_text_variable.get())
453 #print "############################",mount_list_text_variable.get()
454 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
455 self.new_entry_box.pack(side=tk.RIGHT)
458 button_frame=tk.Frame(self.new_file_window)
459 create_button=tk.Button(button_frame, text="Create", command=self.create_the_hardlink)
460 create_button.pack(side=tk.LEFT)
461 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
462 cancel_button.pack(side=tk.RIGHT)
466 ##mount list entry box init
467 mount_list_frame=tk.Frame(root_window)
468 mount_list_label=tk.Label(mount_list_frame, text="mount list")
469 mount_list_label.pack(side=tk.RIGHT)
471 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
472 mount_list_entry_box.pack(side=tk.RIGHT)
473 mount_list_frame.grid(row=1, column=0, columnspan=2)
476 list_frame=tk.Frame(root_window)
477 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=80)
479 list_frame.grid(sticky=tk.W+tk.E+tk.N+tk.S)
481 name_list_box.bind("<Double-Button-1>", load_command)
483 browser_menu_bar=tk.Menu(root_window)
484 browser_file_menu=tk.Menu(browser_menu_bar)
486 browser_file_menu.add_command(label="Reload", command=load_dir)
487 browser_file_menu.add_command(label="Remount yaffs", command=remount_yaffs)
489 #browser_file_menu.add_command(label="Open")
490 #browser_file_menu.add_command(label="Save")
491 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
492 root_window.config(menu=browser_menu_bar)
495 browser_edit_menu=tk.Menu(browser_menu_bar)
497 browser_edit_menu.add_command(label="New File", command=new_file)
498 browser_edit_menu.add_command(label="New Folder", command=new_folder)
499 browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
500 browser_edit_menu.add_command(label="New Hardlink", command=new_hardlink)
503 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
504 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
511 root_window.mainloop()
513 print"unmounting yaffs:", yaffs_unmount("yaffs2/")