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
73 self.file_contents=ctypes.create_string_buffer(100)
74 yaffs_readlink(self.file_path,self.file_contents,100)
77 self.file_contents=ctypes.create_string_buffer(length_of_file)
78 yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
79 print "file contents", self.file_contents.raw
80 self.file_editor_text.insert(tk.END, self.file_contents.raw)
81 self.file_editor_text.pack()
82 ##self.file_editor_text.bind("<Control-s>", self.save_file)
83 ##doesn't work because it can't pass "self"
86 global current_directory_dict
87 print "loading a new directory*******************************************************************"
88 name_list_box.delete(0, tk.END)
89 current_directory_dict=yaffs_ls(mount_list_text_variable.get())
90 print "new directory", current_directory_dict
91 ##copy directory into file box
92 for x in range(0,len(current_directory_dict)):
93 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"]))
94 name_list_box.grid(column=0, row=1)
95 return current_directory_dict
97 def load_file(link=0):
98 global open_windows_list
99 open_windows_list.append(editor(link))
101 def load_command(self=0):
102 global current_directory_dict
103 print "you loaded a file/dir/link"
104 x=name_list_box.curselection()
106 print "cursor selection", x
107 print "dict", current_directory_dict
109 print "file inode is:", current_directory_dict[x]["inodes"]
112 print "file path is:", current_directory_dict[x]["path"]
113 if current_directory_dict[x]["type"]=="dir":
115 print "open directory"
116 mount_list_text_variable.set(current_directory_dict[x]["path"])
117 print mount_list_text_variable.get()
118 print "old directory dict", current_directory_dict
119 #current_directory_dict=load_dir()
122 print "new directory dict passed back"
124 elif current_directory_dict[x]["type"]=="file" :
128 elif current_directory_dict[x]["type"]=="link":
129 print "loading a symlink"
131 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
133 def back_a_directory(self=0):
134 x=len(mount_list_text_variable.get())
135 string=mount_list_text_variable.get()
137 #print "length of path", x
138 #print "string been sorted:", string
139 for i in range(0, x):
142 #print "slash found at:", i
145 ##slashes_id.sort() not needed because the list is already in acending order
146 ##print "sorted",slashes_id
148 string=string[0: slashes_id[len(slashes_id)-2]+1]
150 mount_list_text_variable.set(string)
161 if dname[-1] != "/": dname = dname + "/"
162 dc = yaffs_opendir(dname)
164 sep = yaffs_readdir(dc)
168 fullname = dname + se.d_name
169 st = yaffs_stat_struct()
170 result = yaffs_stat(fullname,byref(st))
171 perms = st.st_mode & 0777
172 ftype = st.st_mode & yaffs_S_IFMT
173 isFile = True if ftype == yaffs_S_IFREG else False
174 isDir = True if ftype == yaffs_S_IFDIR else False
175 isSymlink= True if ftype == yaffs_S_IFLNK else False
178 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
179 print "file st.st_mode:", st.st_mode
182 print "dir st.st_mode:", st.st_mode
184 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/"})
186 print "symlink st.st_mode:", st.st_mode
188 ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
191 print "unknown st.st_mode:", st.st_mode
192 ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname})
193 sep = yaffs_readdir(dc)
197 print "Could not open directory"
202 toolbar_frame=tk.Frame(root_window)
203 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
204 button_open.grid(column=0, row=0)
205 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
206 button_back.grid(column=1, row=0)
207 toolbar_frame.grid(row=0, column=0, columnspan=3)
209 def delete_selected(selected_dir=0):
211 print"using current_directory_dict"
212 global current_directory_dict
213 x=name_list_box.curselection()
215 print current_directory_dict[x]["type"]
216 if current_directory_dict[x]["type"]=="file":
217 path=current_directory_dict[x]["path"]
219 output=yaffs_unlink(path)
220 print "unlinking output:", output
221 elif current_directory_dict[x]["type"]=="dir":
222 path=current_directory_dict[x]["path"]
223 inside_dir=yaffs_ls(path)
224 print "files and folder inside dir", inside_dir
225 print "len of dir", len(inside_dir)
226 if inside_dir!=[]: ##if the dir is not empty
227 ## remove stuff in dir
228 for i in range(0,len(inside_dir)):
229 print "calling self*****"
230 delete_selected(inside_dir[i])
232 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
233 print "removing:", path
234 output=yaffs_rmdir(path)
235 print "rmdir output:", output
237 print "using passed dir"
238 print "dir passed", selected_dir
239 current_directory_dict =selected_dir
241 print "after copying", current_directory_dict
242 print current_directory_dict["type"]
243 if current_directory_dict["type"]=="file":
244 path=current_directory_dict["path"]
246 output=yaffs_unlink(path)
247 print "unlinking output:", output
248 elif current_directory_dict["type"]=="dir":
249 path=current_directory_dict["path"]
250 inside_dir=yaffs_ls(path)
251 print "files and folder inside dir", inside_dir
252 print "len of dir", len(inside_dir)
253 if inside_dir!=[]: ##if the dir is not empty
254 ## remove stuff in dir
255 for i in range(0,len(inside_dir)):
256 print "calling self*****"
257 delete_selected(inside_dir[i])
259 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
260 print "removing:", path
261 output=yaffs_rmdir(path)
262 print "rmdir output:", output
273 def open_the_file(self):
274 global mount_list_text_variable
275 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
276 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
277 yaffs_close(yaffs_handle)
278 self.new_file_window.destroy()
283 self.new_file_window.destroy()
285 global mount_list_text_variable
286 self.new_file_window =tk.Toplevel(takefocus=True)
287 path_frame=tk.Frame(self.new_file_window)
288 path_label=tk.Label(path_frame, text="file path")
289 path_label.pack(side=tk.LEFT)
291 text.set(mount_list_text_variable.get())
292 print "############################",mount_list_text_variable.get()
293 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
294 self.path_entry_box.pack(side=tk.RIGHT)
296 button_frame=tk.Frame(self.new_file_window)
297 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
298 create_button.pack(side=tk.LEFT)
299 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
300 cancel_button.pack(side=tk.RIGHT)
306 def create_the_folder(self):
307 global mount_list_text_variable
308 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
309 yaffs_mkdir(self.path_entry_box.get(),0666)
310 self.new_folder_window.destroy()
316 self.new_folder_window.destroy()
318 global mount_list_text_variable
319 self.new_folder_window =tk.Toplevel(takefocus=True)
320 path_frame=tk.Frame(self.new_folder_window)
321 path_label=tk.Label(path_frame, text="directory path")
322 path_label.pack(side=tk.LEFT)
324 text.set(mount_list_text_variable.get())
325 print "############################",mount_list_text_variable.get()
326 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
327 self.path_entry_box.pack(side=tk.RIGHT)
329 button_frame=tk.Frame(self.new_folder_window)
330 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
331 create_button.pack(side=tk.LEFT)
332 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
333 cancel_button.pack(side=tk.RIGHT)
342 def create_the_symlink(self):
343 global mount_list_text_variable
344 ##check the symlink's target is a file.
345 target_path=self.target_text.get()
346 new_path=self.new_text.get()
347 print "creating a symlink \n target:", target_path
348 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
349 if target_file_exists>=0:
350 ##file exists,create symlink
351 print "target file exist, creating symlink"
352 yaffs_symlink(target_path, new_path)
353 self.new_file_window.destroy()
355 ##file does not exist
356 print "target file does not exist, cannot create symlink"
361 self.new_file_window.destroy()
363 global mount_list_text_variable
364 self.new_file_window =tk.Toplevel(takefocus=True)
365 target_frame=tk.Frame(self.new_file_window)
366 target_label=tk.Label(target_frame, text="target")
367 target_label.pack(side=tk.LEFT)
368 self.target_text=tk.StringVar()
369 self.target_text.set(mount_list_text_variable.get())
370 #print "############################",mount_list_text_variable.get()
371 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
372 self.target_entry_box.pack(side=tk.RIGHT)
375 new_frame=tk.Frame(self.new_file_window)
376 new_label=tk.Label(new_frame, text="file path")
377 new_label.pack(side=tk.LEFT)
378 self.new_text=tk.StringVar()
379 self.new_text.set(mount_list_text_variable.get())
380 #print "############################",mount_list_text_variable.get()
381 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
382 self.new_entry_box.pack(side=tk.RIGHT)
385 button_frame=tk.Frame(self.new_file_window)
386 create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
387 create_button.pack(side=tk.LEFT)
388 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
389 cancel_button.pack(side=tk.RIGHT)
394 class new_hardlink():
399 def create_the_hardlink(self):
400 global mount_list_text_variable
401 ##check the symlink's target is a file.
402 target_path=self.target_text.get()
403 new_path=self.new_text.get()
404 print "creating a hardlink \n target:", target_path
405 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
406 if target_file_exists>=0:
407 ##file exists,create symlink
408 print "target file exist, creating hardlink"
409 yaffs_link(target_path, new_path)
410 self.new_file_window.destroy()
412 ##file does not exist
413 print "target file does not exist, cannot create hardlink"
418 self.new_file_window.destroy()
420 global mount_list_text_variable
421 self.new_file_window =tk.Toplevel(takefocus=True)
422 target_frame=tk.Frame(self.new_file_window)
423 target_label=tk.Label(target_frame, text="target")
424 target_label.pack(side=tk.LEFT)
425 self.target_text=tk.StringVar()
426 self.target_text.set(mount_list_text_variable.get())
427 #print "############################",mount_list_text_variable.get()
428 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
429 self.target_entry_box.pack(side=tk.RIGHT)
432 new_frame=tk.Frame(self.new_file_window)
433 new_label=tk.Label(new_frame, text="file path")
434 new_label.pack(side=tk.LEFT)
435 self.new_text=tk.StringVar()
436 self.new_text.set(mount_list_text_variable.get())
437 #print "############################",mount_list_text_variable.get()
438 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
439 self.new_entry_box.pack(side=tk.RIGHT)
442 button_frame=tk.Frame(self.new_file_window)
443 create_button=tk.Button(button_frame, text="Create", command=self.create_the_hardlink)
444 create_button.pack(side=tk.LEFT)
445 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
446 cancel_button.pack(side=tk.RIGHT)
450 ##mount list entry box init
451 mount_list_frame=tk.Frame(root_window)
452 mount_list_label=tk.Label(mount_list_frame, text="mount list")
453 mount_list_label.pack(side=tk.RIGHT)
455 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
456 mount_list_entry_box.pack(side=tk.RIGHT)
457 mount_list_frame.grid(row=1, column=0, columnspan=2)
460 list_frame=tk.Frame(root_window)
461 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=50)
465 name_list_box.bind("<Double-Button-1>", load_command)
467 browser_menu_bar=tk.Menu(root_window)
468 browser_file_menu=tk.Menu(browser_menu_bar)
470 browser_file_menu.add_command(label="Reload", command=load_dir)
471 #browser_file_menu.add_command(label="Open")
472 #browser_file_menu.add_command(label="Save")
473 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
474 root_window.config(menu=browser_menu_bar)
477 browser_edit_menu=tk.Menu(browser_menu_bar)
479 browser_edit_menu.add_command(label="New File", command=new_file)
480 browser_edit_menu.add_command(label="New Folder", command=new_folder)
481 browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
482 browser_edit_menu.add_command(label="New Hardlink", command=new_hardlink)
485 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
486 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
493 root_window.mainloop()
495 print"unmounting yaffs:", yaffs_unmount("yaffs2/")