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()
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()
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"]))
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})
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+"/"})
189 print "symlink st.st_mode:", st.st_mode
191 ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
194 print "unknown st.st_mode:", st.st_mode
195 ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname})
196 sep = yaffs_readdir(dc)
200 print "Could not open directory"
205 toolbar_frame=tk.Frame(root_window)
206 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
207 button_open.grid(column=0, row=0)
208 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
209 button_back.grid(column=1, row=0)
210 toolbar_frame.grid(row=0, column=0, columnspan=3)
212 def delete_selected(selected_dir=0):
214 print"using current_directory_dict"
215 global current_directory_dict
216 x=name_list_box.curselection()
218 print current_directory_dict[x]["type"]
219 if current_directory_dict[x]["type"]=="file":
220 path=current_directory_dict[x]["path"]
222 output=yaffs_unlink(path)
223 print "unlinking output:", output
224 elif current_directory_dict[x]["type"]=="dir":
225 path=current_directory_dict[x]["path"]
226 inside_dir=yaffs_ls(path)
227 print "files and folder inside dir", inside_dir
228 print "len of dir", len(inside_dir)
229 if inside_dir!=[]: ##if the dir is not empty
230 ## remove stuff in dir
231 for i in range(0,len(inside_dir)):
232 print "calling self*****"
233 delete_selected(inside_dir[i])
235 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
236 print "removing:", path
237 output=yaffs_rmdir(path)
238 print "rmdir output:", output
240 print "using passed dir"
241 print "dir passed", selected_dir
242 current_directory_dict =selected_dir
244 print "after copying", current_directory_dict
245 print current_directory_dict["type"]
246 if current_directory_dict["type"]=="file":
247 path=current_directory_dict["path"]
249 output=yaffs_unlink(path)
250 print "unlinking output:", output
251 elif current_directory_dict["type"]=="dir":
252 path=current_directory_dict["path"]
253 inside_dir=yaffs_ls(path)
254 print "files and folder inside dir", inside_dir
255 print "len of dir", len(inside_dir)
256 if inside_dir!=[]: ##if the dir is not empty
257 ## remove stuff in dir
258 for i in range(0,len(inside_dir)):
259 print "calling self*****"
260 delete_selected(inside_dir[i])
262 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
263 print "removing:", path
264 output=yaffs_rmdir(path)
265 print "rmdir output:", output
276 def open_the_file(self):
277 global mount_list_text_variable
278 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
279 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
280 yaffs_close(yaffs_handle)
281 self.new_file_window.destroy()
286 self.new_file_window.destroy()
288 global mount_list_text_variable
289 self.new_file_window =tk.Toplevel(takefocus=True)
290 path_frame=tk.Frame(self.new_file_window)
291 path_label=tk.Label(path_frame, text="file path")
292 path_label.pack(side=tk.LEFT)
294 text.set(mount_list_text_variable.get())
295 print "############################",mount_list_text_variable.get()
296 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
297 self.path_entry_box.pack(side=tk.RIGHT)
299 button_frame=tk.Frame(self.new_file_window)
300 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
301 create_button.pack(side=tk.LEFT)
302 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
303 cancel_button.pack(side=tk.RIGHT)
309 def create_the_folder(self):
310 global mount_list_text_variable
311 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
312 yaffs_mkdir(self.path_entry_box.get(),0666)
313 self.new_folder_window.destroy()
319 self.new_folder_window.destroy()
321 global mount_list_text_variable
322 self.new_folder_window =tk.Toplevel(takefocus=True)
323 path_frame=tk.Frame(self.new_folder_window)
324 path_label=tk.Label(path_frame, text="directory path")
325 path_label.pack(side=tk.LEFT)
327 text.set(mount_list_text_variable.get())
328 print "############################",mount_list_text_variable.get()
329 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
330 self.path_entry_box.pack(side=tk.RIGHT)
332 button_frame=tk.Frame(self.new_folder_window)
333 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
334 create_button.pack(side=tk.LEFT)
335 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
336 cancel_button.pack(side=tk.RIGHT)
345 def create_the_symlink(self):
346 global mount_list_text_variable
347 ##check the symlink's target is a file.
348 target_path=self.target_text.get()
349 new_path=self.new_text.get()
350 print "creating a symlink \n target:", target_path
351 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
352 if target_file_exists>=0:
353 ##file exists,create symlink
354 print "target file exist, creating symlink"
355 yaffs_symlink(target_path, new_path)
356 self.new_file_window.destroy()
358 ##file does not exist
359 print "target file does not exist, cannot create symlink"
364 self.new_file_window.destroy()
366 global mount_list_text_variable
367 self.new_file_window =tk.Toplevel(takefocus=True)
368 target_frame=tk.Frame(self.new_file_window)
369 target_label=tk.Label(target_frame, text="target")
370 target_label.pack(side=tk.LEFT)
371 self.target_text=tk.StringVar()
372 self.target_text.set(mount_list_text_variable.get())
373 #print "############################",mount_list_text_variable.get()
374 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
375 self.target_entry_box.pack(side=tk.RIGHT)
378 new_frame=tk.Frame(self.new_file_window)
379 new_label=tk.Label(new_frame, text="file path")
380 new_label.pack(side=tk.LEFT)
381 self.new_text=tk.StringVar()
382 self.new_text.set(mount_list_text_variable.get())
383 #print "############################",mount_list_text_variable.get()
384 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
385 self.new_entry_box.pack(side=tk.RIGHT)
388 button_frame=tk.Frame(self.new_file_window)
389 create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
390 create_button.pack(side=tk.LEFT)
391 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
392 cancel_button.pack(side=tk.RIGHT)
397 class new_hardlink():
402 def create_the_hardlink(self):
403 global mount_list_text_variable
404 ##check the symlink's target is a file.
405 target_path=self.target_text.get()
406 new_path=self.new_text.get()
407 print "creating a hardlink \n target:", target_path
408 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
409 if target_file_exists>=0:
410 ##file exists,create symlink
411 print "target file exist, creating hardlink"
412 yaffs_link(target_path, new_path)
413 self.new_file_window.destroy()
415 ##file does not exist
416 print "target file does not exist, cannot create hardlink"
421 self.new_file_window.destroy()
423 global mount_list_text_variable
424 self.new_file_window =tk.Toplevel(takefocus=True)
425 target_frame=tk.Frame(self.new_file_window)
426 target_label=tk.Label(target_frame, text="target")
427 target_label.pack(side=tk.LEFT)
428 self.target_text=tk.StringVar()
429 self.target_text.set(mount_list_text_variable.get())
430 #print "############################",mount_list_text_variable.get()
431 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
432 self.target_entry_box.pack(side=tk.RIGHT)
435 new_frame=tk.Frame(self.new_file_window)
436 new_label=tk.Label(new_frame, text="file path")
437 new_label.pack(side=tk.LEFT)
438 self.new_text=tk.StringVar()
439 self.new_text.set(mount_list_text_variable.get())
440 #print "############################",mount_list_text_variable.get()
441 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
442 self.new_entry_box.pack(side=tk.RIGHT)
445 button_frame=tk.Frame(self.new_file_window)
446 create_button=tk.Button(button_frame, text="Create", command=self.create_the_hardlink)
447 create_button.pack(side=tk.LEFT)
448 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
449 cancel_button.pack(side=tk.RIGHT)
453 ##mount list entry box init
454 mount_list_frame=tk.Frame(root_window)
455 mount_list_label=tk.Label(mount_list_frame, text="mount list")
456 mount_list_label.pack(side=tk.RIGHT)
458 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
459 mount_list_entry_box.pack(side=tk.RIGHT)
460 mount_list_frame.grid(row=1, column=0, columnspan=2)
463 list_frame=tk.Frame(root_window)
464 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=50)
468 name_list_box.bind("<Double-Button-1>", load_command)
470 browser_menu_bar=tk.Menu(root_window)
471 browser_file_menu=tk.Menu(browser_menu_bar)
473 browser_file_menu.add_command(label="Reload", command=load_dir)
474 #browser_file_menu.add_command(label="Open")
475 #browser_file_menu.add_command(label="Save")
476 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
477 root_window.config(menu=browser_menu_bar)
480 browser_edit_menu=tk.Menu(browser_menu_bar)
482 browser_edit_menu.add_command(label="New File", command=new_file)
483 browser_edit_menu.add_command(label="New Folder", command=new_folder)
484 browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
485 browser_edit_menu.add_command(label="New Hardlink", command=new_hardlink)
488 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
489 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
496 root_window.mainloop()
498 print"unmounting yaffs:", yaffs_unmount("yaffs2/")