10 root_window.title("YAFFS Browser")
11 mount_list_text_variable=tk.StringVar()
13 mount_list_text_variable.set("yaffs2/")
14 current_directory_dict={}
24 #global current_directory_dict
25 print "saving the file"
26 print self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
27 yaffs_lseek(self.yaffs_handle, 0, 0)
28 data_to_be_written=self.file_editor_text.get("1.0", tk.END)
29 print "data to be saved", data_to_be_written
30 length_of_file=len(data_to_be_written)
31 print "length of data to be written",length_of_file
32 output=yaffs_write(self.yaffs_handle,data_to_be_written , length_of_file)
33 print "output", output
34 yaffs_ftruncate(self.yaffs_handle, length_of_file)
35 yaffs_close(self.yaffs_handle)
37 self.yaffs_handle = yaffs_open(self.file_path,66,0666)
41 global current_directory_dict
42 x=name_list_box.curselection()
44 self.file_editor_root =tk.Toplevel()
45 self.save_button=tk.Button(self.file_editor_root, text="save", command=self.save_file)
46 self.save_button.pack()
48 self.file_path=current_directory_dict[self.id]["path"]
49 print "file path", self.file_path
50 self.file_editor_root.title(current_directory_dict[self.id]["path"])
51 self.file_editor_text=tk.Text(self.file_editor_root)
52 self.yaffs_handle = yaffs_open(current_directory_dict[self.id]["path"],66,0666)
53 length_of_file=yaffs_lseek(self.yaffs_handle, 0, 2) ##seeks to the end of the file
54 yaffs_lseek(self.yaffs_handle, 0, 0)## returns the handle to the front of th file
55 self.file_contents=ctypes.create_string_buffer(length_of_file)
56 yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
57 print "file contents", self.file_contents.raw
58 self.file_editor_text.insert(tk.END, self.file_contents.raw)
59 self.file_editor_text.pack()
60 ##self.file_editor_text.bind("<Control-s>", self.save_file)
61 ##doesn't work because it can't pass "self"
64 global current_directory_dict
65 print "loading a new directory*******************************************************************"
66 name_list_box.delete(0, tk.END)
67 current_directory_dict=yaffs_ls(mount_list_text_variable.get())
68 print "new directory", current_directory_dict
69 ##copy directory into file box
70 for x in range(0,len(current_directory_dict)):
71 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"]))
72 name_list_box.grid(column=0, row=1)
73 return current_directory_dict
76 global open_windows_list
77 open_windows_list.append(editor())
79 def load_command(self=0):
80 global current_directory_dict
81 print "you loaded a file/dir"
82 x=name_list_box.curselection()
84 print "cursor selection", x
85 print "dict", current_directory_dict
87 print "file inode is:", current_directory_dict[x]["inodes"]
90 print "file path is:", current_directory_dict[x]["path"]
91 if current_directory_dict[x]["type"]=="dir":
93 print "open directory"
94 mount_list_text_variable.set(current_directory_dict[x]["path"])
95 print mount_list_text_variable.get()
96 print "old directory dict", current_directory_dict
97 #current_directory_dict=load_dir()
100 print "new directory dict passed back"
102 elif current_directory_dict[x]["type"]=="file" :
108 ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
110 def back_a_directory(self=0):
111 x=len(mount_list_text_variable.get())
112 string=mount_list_text_variable.get()
114 #print "length of path", x
115 #print "string been sorted:", string
116 for i in range(0, x):
119 #print "slash found at:", i
122 ##slashes_id.sort() not needed because the list is already in acending order
123 ##print "sorted",slashes_id
125 string=string[0: slashes_id[len(slashes_id)-2]+1]
127 mount_list_text_variable.set(string)
138 if dname[-1] != "/": dname = dname + "/"
139 dc = yaffs_opendir(dname)
141 sep = yaffs_readdir(dc)
145 fullname = dname + se.d_name
146 st = yaffs_stat_struct()
147 result = yaffs_stat(fullname,byref(st))
148 perms = st.st_mode & 0777
149 isFile = True if st.st_mode & 0x8000 else False
150 isDir = True if st.st_mode & 0x4000 else False
153 ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname})
155 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/"})
158 # ls_dict.append( "Other ("+hex(st.st_mode)+") "+se.d_ino, hex(perms)+ fullname)
159 sep = yaffs_readdir(dc)
163 print "Could not open directory"
168 toolbar_frame=tk.Frame(root_window)
169 button_open=tk.Button(toolbar_frame, command=load_command, text="load")
170 button_open.grid(column=0, row=0)
171 button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
172 button_back.grid(column=1, row=0)
173 toolbar_frame.grid(row=0, column=0, columnspan=3)
180 def open_the_file(self):
181 global mount_list_text_variable
182 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
183 yaffs_handle=yaffs_open(self.path_entry_box.get(),66,0666)
184 yaffs_close(yaffs_handle)
185 self.new_file_window.destroy()
190 self.new_file_window.destroy()
192 global mount_list_text_variable
193 self.new_file_window =tk.Toplevel(takefocus=True)
194 path_frame=tk.Frame(self.new_file_window)
195 path_label=tk.Label(path_frame, text="file path")
196 path_label.pack(side=tk.LEFT)
198 text.set(mount_list_text_variable.get())
199 print "############################",mount_list_text_variable.get()
200 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
201 self.path_entry_box.pack(side=tk.RIGHT)
203 button_frame=tk.Frame(self.new_file_window)
204 create_button=tk.Button(button_frame, text="Create", command=self.open_the_file)
205 create_button.pack(side=tk.LEFT)
206 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
207 cancel_button.pack(side=tk.RIGHT)
213 def create_the_folder(self):
214 global mount_list_text_variable
215 print "trying to create", mount_list_text_variable.get()+self.path_entry_box.get()
216 yaffs_mkdir(self.path_entry_box.get(),0666)
217 self.new_folder_window.destroy()
223 self.new_folder_window.destroy()
225 global mount_list_text_variable
226 self.new_folder_window =tk.Toplevel(takefocus=True)
227 path_frame=tk.Frame(self.new_folder_window)
228 path_label=tk.Label(path_frame, text="directory path")
229 path_label.pack(side=tk.LEFT)
231 text.set(mount_list_text_variable.get())
232 print "############################",mount_list_text_variable.get()
233 self.path_entry_box= tk.Entry(path_frame, textvariable=text)
234 self.path_entry_box.pack(side=tk.RIGHT)
236 button_frame=tk.Frame(self.new_folder_window)
237 create_button=tk.Button(button_frame, text="Create", command=self.create_the_folder)
238 create_button.pack(side=tk.LEFT)
239 cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
240 cancel_button.pack(side=tk.RIGHT)
246 ##mount list entry box init
247 mount_list_frame=tk.Frame(root_window)
248 mount_list_label=tk.Label(mount_list_frame, text="mount list")
249 mount_list_label.pack(side=tk.RIGHT)
251 mount_list_entry_box= tk.Entry(mount_list_frame,textvariable=mount_list_text_variable)
252 mount_list_entry_box.pack(side=tk.RIGHT)
253 mount_list_frame.grid(row=1, column=0, columnspan=2)
256 list_frame=tk.Frame(root_window)
257 name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=50)
261 name_list_box.bind("<Double-Button-1>", load_command)
263 browser_menu_bar=tk.Menu(root_window)
264 browser_file_menu=tk.Menu(browser_menu_bar)
266 browser_file_menu.add_command(label="Reload", command=load_dir)
267 browser_file_menu.add_command(label="Open")
268 browser_file_menu.add_command(label="Save")
269 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
270 root_window.config(menu=browser_menu_bar)
273 browser_edit_menu=tk.Menu(browser_menu_bar)
275 browser_edit_menu.add_command(label="New File", command=new_file)
276 browser_edit_menu.add_command(label="New Folder", command=new_folder)
277 browser_edit_menu.add_command(label="Rename File")
278 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
285 root_window.mainloop()
287 print"unmounting yaffs:", yaffs_unmount("yaffs2/")