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 isFile = True if st.st_mode & 0x8000 else False
173 isDir = True if st.st_mode & 0x4000 else False
174 isSymlink=False if st.st_mode & 0x120000 else True
177 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
178 print "file st.st_mode:", st.st_mode
179 print "st.st_mode andded with st.st_mode & 0x8000", st.st_mode & 0x8000
181 print "dir st.st_mode:", st.st_mode
182 print "st.st_mode andded with st.st_mode & 0x4000", st.st_mode & 0x4000
183 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/"})
186 ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
189 print "unknown st.st_mode:", st.st_mode
190 print "st.st_mode andded with st.st_mode & 0x120000", st.st_mode & 0x120000
191 ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname})
192 sep = yaffs_readdir(dc)
196 print "Could not open directory"
201 toolbar_frame=tk.Frame(root_window)
202 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
203 button_open.grid(column=0, row=0)
204 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
205 button_back.grid(column=1, row=0)
206 toolbar_frame.grid(row=0, column=0, columnspan=3)
208 def delete_selected(selected_dir=0):
210 print"using current_directory_dict"
211 global current_directory_dict
212 x=name_list_box.curselection()
214 print current_directory_dict[x]["type"]
215 if current_directory_dict[x]["type"]=="file":
216 path=current_directory_dict[x]["path"]
218 output=yaffs_unlink(path)
219 print "unlinking output:", output
220 elif current_directory_dict[x]["type"]=="dir":
221 path=current_directory_dict[x]["path"]
222 inside_dir=yaffs_ls(path)
223 print "files and folder inside dir", inside_dir
224 print "len of dir", len(inside_dir)
225 if inside_dir!=[]: ##if the dir is not empty
226 ## remove stuff in dir
227 for i in range(0,len(inside_dir)):
228 print "calling self*****"
229 delete_selected(inside_dir[i])
231 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
232 print "removing:", path
233 output=yaffs_rmdir(path)
234 print "rmdir output:", output
236 print "using passed dir"
237 print "dir passed", selected_dir
238 current_directory_dict =selected_dir
240 print "after copying", current_directory_dict
241 print current_directory_dict["type"]
242 if current_directory_dict["type"]=="file":
243 path=current_directory_dict["path"]
245 output=yaffs_unlink(path)
246 print "unlinking output:", output
247 elif current_directory_dict["type"]=="dir":
248 path=current_directory_dict["path"]
249 inside_dir=yaffs_ls(path)
250 print "files and folder inside dir", inside_dir
251 print "len of dir", len(inside_dir)
252 if inside_dir!=[]: ##if the dir is not empty
253 ## remove stuff in dir
254 for i in range(0,len(inside_dir)):
255 print "calling self*****"
256 delete_selected(inside_dir[i])
258 path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file
259 print "removing:", path
260 output=yaffs_rmdir(path)
261 print "rmdir output:", output
272 def open_the_file(self):
273 global mount_list_text_variable
274 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
275 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
276 yaffs_close(yaffs_handle)
277 self.new_file_window.destroy()
282 self.new_file_window.destroy()
284 global mount_list_text_variable
285 self.new_file_window =tk.Toplevel(takefocus=True)
286 path_frame=tk.Frame(self.new_file_window)
287 path_label=tk.Label(path_frame, text="file path")
288 path_label.pack(side=tk.LEFT)
290 text.set(mount_list_text_variable.get())
291 print "############################",mount_list_text_variable.get()
292 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
293 self.path_entry_box.pack(side=tk.RIGHT)
295 button_frame=tk.Frame(self.new_file_window)
296 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
297 create_button.pack(side=tk.LEFT)
298 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
299 cancel_button.pack(side=tk.RIGHT)
305 def create_the_folder(self):
306 global mount_list_text_variable
307 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
308 yaffs_mkdir(self.path_entry_box.get(),0666)
309 self.new_folder_window.destroy()
315 self.new_folder_window.destroy()
317 global mount_list_text_variable
318 self.new_folder_window =tk.Toplevel(takefocus=True)
319 path_frame=tk.Frame(self.new_folder_window)
320 path_label=tk.Label(path_frame, text="directory path")
321 path_label.pack(side=tk.LEFT)
323 text.set(mount_list_text_variable.get())
324 print "############################",mount_list_text_variable.get()
325 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
326 self.path_entry_box.pack(side=tk.RIGHT)
328 button_frame=tk.Frame(self.new_folder_window)
329 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
330 create_button.pack(side=tk.LEFT)
331 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
332 cancel_button.pack(side=tk.RIGHT)
341 def create_the_symlink(self):
342 global mount_list_text_variable
343 ##check the symlink's target is a file.
344 target_path=self.target_text.get()
345 new_path=self.new_text.get()
346 print "creating a symlink \n target:", target_path
347 target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
348 if target_file_exists>=0:
349 ##file exists,create symlink
350 print "target file exist, creating symlink"
351 yaffs_symlink(target_path, new_path)
352 self.new_file_window.destroy()
354 ##file does not exist
355 print "target file does not exist, cannot create symlink"
363 self.new_file_window.destroy()
365 global mount_list_text_variable
366 self.new_file_window =tk.Toplevel(takefocus=True)
367 target_frame=tk.Frame(self.new_file_window)
368 target_label=tk.Label(target_frame, text="target")
369 target_label.pack(side=tk.LEFT)
370 self.target_text=tk.StringVar()
371 self.target_text.set(mount_list_text_variable.get())
372 #print "############################",mount_list_text_variable.get()
373 self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
374 self.target_entry_box.pack(side=tk.RIGHT)
377 new_frame=tk.Frame(self.new_file_window)
378 new_label=tk.Label(new_frame, text="file path")
379 new_label.pack(side=tk.LEFT)
380 self.new_text=tk.StringVar()
381 self.new_text.set(mount_list_text_variable.get())
382 #print "############################",mount_list_text_variable.get()
383 self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
384 self.new_entry_box.pack(side=tk.RIGHT)
387 button_frame=tk.Frame(self.new_file_window)
388 create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
389 create_button.pack(side=tk.LEFT)
390 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
391 cancel_button.pack(side=tk.RIGHT)
395 ##mount list entry box init
396 mount_list_frame=tk.Frame(root_window)
397 mount_list_label=tk.Label(mount_list_frame, text="mount list")
398 mount_list_label.pack(side=tk.RIGHT)
400 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
401 mount_list_entry_box.pack(side=tk.RIGHT)
402 mount_list_frame.grid(row=1, column=0, columnspan=2)
405 list_frame=tk.Frame(root_window)
406 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=50)
410 name_list_box.bind("<Double-Button-1>", load_command)
412 browser_menu_bar=tk.Menu(root_window)
413 browser_file_menu=tk.Menu(browser_menu_bar)
415 browser_file_menu.add_command(label="Reload", command=load_dir)
416 #browser_file_menu.add_command(label="Open")
417 #browser_file_menu.add_command(label="Save")
418 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
419 root_window.config(menu=browser_menu_bar)
422 browser_edit_menu=tk.Menu(browser_menu_bar)
424 browser_edit_menu.add_command(label="New File", command=new_file)
425 browser_edit_menu.add_command(label="New Folder", command=new_folder)
426 browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
428 browser_edit_menu.add_command(label="delete selected", command=delete_selected)
429 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
436 root_window.mainloop()
438 print"unmounting yaffs:", yaffs_unmount("yaffs2/")