Changeset 3812 for lliurex-gdrive/trunk/fuentes/lliurex-gdrive-gui.install
- Timestamp:
- Mar 3, 2017, 2:09:19 PM (4 years ago)
- Location:
- lliurex-gdrive/trunk/fuentes/lliurex-gdrive-gui.install/usr/share/lliurex-gdrive
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lliurex-gdrive/trunk/fuentes/lliurex-gdrive-gui.install/usr/share/lliurex-gdrive/LliurexGdrive.py
r3806 r3812 16 16 17 17 RSRC="./" 18 CONFIG_DIR=os.path.expanduser("~/.config/lliurex-google-drive-profiles/config")18 #CONFIG_DIR=os.path.expanduser("~/.config/lliurex-google-drive-profiles/config") 19 19 20 20 class LliurexGdrive: … … 54 54 55 55 56 profiles_info={} 56 profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() 57 # if os.path.exists(CONFIG_DIR): 57 58 58 if os.path.exists(CONFIG_DIR): 59 60 f=open(CONFIG_DIR) 61 profiles_info=json.load(f) 62 f.close() 59 # f=open(CONFIG_DIR) 60 # profiles_info=json.load(f) 61 # f.close() 63 62 64 63 -
lliurex-gdrive/trunk/fuentes/lliurex-gdrive-gui.install/usr/share/lliurex-gdrive/LliurexGoogleDriveManager.py
r3808 r3812 33 33 34 34 var={} 35 var["default"]={}36 var["default"]["email"]=""37 var["default"]["mountpoint"]=""38 var["default"]["automount"]=""35 # var["default"]={} 36 # var["default"]["email"]="" 37 # var["default"]["mountpoint"]="" 38 # var["default"]["automount"]="" 39 39 40 40 f=open(self.config_file,"w") … … 53 53 54 54 f=open(self.config_file) 55 self. var=json.load(f)55 self.profiles_config=json.load(f) 56 56 f.close() 57 57 … … 79 79 #def check_configuration 80 80 81 def mount_drive(self,profile ):81 def mount_drive(self,profile,mountpoint): 82 82 83 83 if os.path.exists(GDRIVE_CONFIG_DIR+profile): 84 84 if self.check_config(profile): 85 if profile in self.var:86 mount_point=os.path.expanduser(self.var[profile]["mountpoint"])87 print mount _point,type(mount_point)85 #if profile in self.profiles_config: 86 #mount_point=os.path.expanduser(self.profiles_config[profile]["mountpoint"]) 87 print mountpoint,type(mountpoint) 88 88 #if type(mount_point)==type(u""): 89 if str(mount _point)!="":89 if str(mountpoint)!="": 90 90 self.dprint("Mounting '%s'..."%profile) 91 if not os.path.exists(mount _point):91 if not os.path.exists(mountpoint): 92 92 try: 93 os.makedirs(mount _point)93 os.makedirs(mountpoint) 94 94 except: 95 self.dprint("Unable to create '%s' mount destination"%mount _point)95 self.dprint("Unable to create '%s' mount destination"%mountpoint) 96 96 return False 97 97 98 98 99 if os.access(mount _point,os.W_OK):100 os.system(self.mount_cmd%(profile,mount _point))99 if os.access(mountpoint,os.W_OK): 100 os.system(self.mount_cmd%(profile,mountpoint)) 101 101 return True 102 102 else: 103 103 104 self.dprint("'%s' mount destination is not owned by user"%mount _point)104 self.dprint("'%s' mount destination is not owned by user"%mountpoint) 105 105 106 106 else: 107 107 self.dprint("'%s' mountpoint not configured"%profile) 108 else:109 self.dprint("'%s' profile unknown"%profile)108 #else: 109 #self.dprint("'%s' profile unknown"%profile) 110 110 else: 111 111 self.dprint("'%s' GDrive profile path does not exist"%profile) … … 118 118 def mount_drives(self): 119 119 120 for profile in self. var:120 for profile in self.profiles_config: 121 121 self.dprint(profile) 122 self.mount_drive(profile) 122 automount=self.profiles_config[profile]["automount"] 123 124 if automount: 125 mountpoint=self.profiles_config[profile]["mountpoint"] 126 self.mount_drive(profile,mountpoint) 123 127 124 128 … … 135 139 def save_profiles(self,info): 136 140 137 self. var=info141 self.profiles_config=info 138 142 139 143 f=open(self.config_file,"w") … … 141 145 f.write(data) 142 146 f.close() 143 144 def create_profile(self,info,profile):145 146 self.save_profiles(info)147 profile=str(profile)148 149 if not self.check_config(profile):150 os.system("google-drive-ocamlfuse -label %s"%profile)151 self.dprint("'%s' profile has been create"%profile)152 self.mount_drive(profile)153 154 # llx config file155 # clean cache google-drive-ocamlfuse -cc156 157 158 #def save_profiles159 147 160 148 … … 166 154 mountpoint_per="" 167 155 168 command='df -h | grep "google-ocamlfuse" | grep ' +str(mountpoint) 156 command='df -h | grep "google-drive-ocamlfuse" | grep ' +str(mountpoint) 157 169 158 p=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE) 170 159 poutput,perror=p.communicate() … … 180 169 status=False 181 170 182 return {"status":status,"size":mountpoint_size,"used":mountpoint_used,"available":mountpoint_available,"Used%":mountpoint_per} 183 184 185 186 def delete_profile(self,info,profile): 171 return {"status":status,"size":mountpoint_size,"used":mountpoint_used,"available":mountpoint_available,"Used%":mountpoint_per} 172 173 174 def create_profile(self,info,profile): 175 176 result=False 187 177 188 178 profile=str(profile) 189 mountpoint=self.var[profile]["mountpoint"] 190 191 192 if os.path.exists(GDRIVE_CONFIG_DIR+profile): 193 194 is_mountpoint_mounted=self.check_mountpoint_status(mountpoint) 195 196 if is_mountpoint_mounted["status"]: 197 cmd='fusermount -u '+str(mountpoint) 198 os.command(cmd) 199 self.dprint("'%s' mountpoint has been unmonted"%mounpoint) 200 179 mountpoint=info[profile]["mountpoint"] 180 181 182 if not self.check_config(profile): 183 os.system("google-drive-ocamlfuse -label %s"%profile) 184 self.dprint("'%s' profile has been create"%profile) 185 result=self.mount_drive(profile,mountpoint) 186 187 if result: 188 self.save_profiles(info) 189 else: 201 190 shutil.rmtree(os.path.join(GDRIVE_CONFIG_DIR+profile)) 202 191 self.dprint("'%s' profile has been delete"%profile) 192 193 return result 194 195 # llx config file 196 # clean cache google-drive-ocamlfuse -cc 197 198 199 #def save_profiles 200 201 202 def delete_profile(self,info,profile): 203 204 result=True 205 206 profile=str(profile) 207 mountpoint=info[profile]["mountpoint"] 208 209 210 if os.path.exists(GDRIVE_CONFIG_DIR+profile): 211 212 is_mountpoint_mounted=self.check_mountpoint_status(mountpoint) 213 214 if is_mountpoint_mounted["status"]: 215 cmd='fusermount -u ' + mountpoint 216 os.system(cmd) 217 self.dprint("'%s' mountpoint has been unmonted"%mountpoint) 218 219 shutil.rmtree(os.path.join(GDRIVE_CONFIG_DIR+profile)) 220 self.dprint("'%s' profile has been delete"%profile) 221 222 223 else: 203 224 self.save_profiles(info) 204 return True205 206 else:207 self.save_profiles(var)208 225 self.dprint("'%s' GDrive profile path does not exist"%profile) 226 227 self.save_profiles(info) 228 229 # delete_profile 230 231 232 def edit_profile(self,info,profile): 233 234 result=True 235 old_mountpoint=self.profiles_config[profile]["mountpoint"] 236 old_automount=self.profiles_config[profile]["automount"] 237 new_mountpoint=info[profile]["mountpoint"] 238 new_automount=info[profile]["automount"] 239 240 241 if old_mountpoint!=new_mountpoint: 242 status=self.check_mountpoint_status(old_mountpoint) 243 244 if status["status"]: 245 cmd='fusermount -u ' + old_mountpoint 246 os.system(cmd) 247 self.dprint("'%s' mountpoint has been unmonted"%old_mountpoint) 248 249 result=self.mount_drive(profile,new_mountpoint) 250 251 if result: 252 self.save_profiles(info) 253 254 return result 255 256 def sync_profile(self,profile,mountpoint): 257 258 status=self.check_mountpoint_status(mountpoint) 259 260 if status["status"]: 261 cmd='fusermount -u ' + mountpoint 262 263 os.system(cmd) 264 265 self.dprint("'%s' mountpoint has been unmonted"%mountpoint) 209 266 return False 210 267 211 # delete_profile 268 else: 269 return self.mount_drive(profile,mountpoint) 212 270 213 271 if __name__=="__main__": -
lliurex-gdrive/trunk/fuentes/lliurex-gdrive-gui.install/usr/share/lliurex-gdrive/ProfileBox.py
r3808 r3812 35 35 ui_path=RSRC + "/rsrc/lliurex-gdrive.ui" 36 36 builder.add_from_file(ui_path) 37 37 38 self.main_box=builder.get_object("profile_data_box") 38 39 self.profiles_list_label=builder.get_object("profiles_list_label") … … 55 56 56 57 self.pack_start(self.main_box,True,True,0) 57 58 58 self.connect_signals() 59 59 self.set_css_info() 60 60 61 61 self.edition=False 62 62 #self.current_var=None … … 72 72 73 73 self.style_provider=Gtk.CssProvider() 74 74 75 f=Gio.File.new_for_path("lliurex-gdrive.css") 75 76 self.style_provider.load_from_file(f) 77 76 78 Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) 77 79 self.profiles_list_label.set_name("OPTION_LABEL") … … 100 102 101 103 self.profiles_info=info 102 print self.profiles_info 104 103 105 for item in self.profiles_info: 104 106 profile=item … … 106 108 mountpoint=self.profiles_info[item]["mountpoint"] 107 109 self.new_profile_button(profile,email,mountpoint) 110 print self.profiles_info[item]["automount"] 111 112 #def load_info() 108 113 109 114 def hide_window(self,widget,event): … … 111 116 widget.hide() 112 117 return True 118 119 #def hide_window 113 120 114 121 def add_new_profile_button_clicked(self,widget): … … 121 128 self.automount_entry.set_state(False) 122 129 self.edition=False 130 123 131 self.new_profile_window.show() 132 133 #def add_new_profile_button_clicked 124 134 125 135 def delete_profile_clicked(self,button,hbox): … … 127 137 profile=hbox.get_children()[1].get_text().split("\n")[0] 128 138 self.profiles_info.pop(profile) 139 129 140 self.core.LliurexGoogleDriveManager.delete_profile(self.profiles_info,profile) 130 131 141 self.profile_list_box.remove(hbox) 132 133 def mount_profile_clicked(self,button,hbox): 134 135 print "SINCRONIZANDO" 136 mount_image=Gtk.Image.new_from_file(MOUNT_OFF_IMAGE) 142 self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() 143 144 145 # def delete_profile_clicked 146 147 148 def sync_profile_clicked(self,button,hbox): 149 150 profile=hbox.get_children()[1].get_text().split("\n")[0] 151 mountpoint=hbox.get_children()[3].get_text() 152 153 status=self.core.LliurexGoogleDriveManager.sync_profile(profile,mountpoint) 154 155 if status: 156 mount_image=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) 157 else: 158 mount_image=Gtk.Image.new_from_file(MOUNT_OFF_IMAGE) 159 137 160 hbox.get_children()[4].set_image(mount_image) 161 162 #def mount_profile_clicked 138 163 139 164 def edit_profile_clicked(self,button,hbox): … … 148 173 mountpoint=self.profile_to_edit.get_children()[3].get_text() 149 174 self.mountpoint_entry.set_filename(mountpoint) 175 automount=self.profiles_info[profile]["automount"] 176 self.automount_entry.set_state(automount) 150 177 self.edition=True 178 151 179 self.new_profile_window.show() 180 181 #def edit_profile_clicked 152 182 153 183 … … 190 220 edit.set_tooltip_text(_("Edit profile")) 191 221 mount=Gtk.Button() 192 mount_image=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) 222 223 status=self.core.LliurexGoogleDriveManager.check_mountpoint_status(mountpoint) 224 if status["status"]: 225 mount_image=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) 226 else: 227 mount_image=Gtk.Image.new_from_file(MOUNT_OFF_IMAGE) 228 193 229 mount.add(mount_image) 194 230 mount.set_halign(Gtk.Align.CENTER) 195 231 mount.set_valign(Gtk.Align.CENTER) 196 232 mount.set_name("MOUNT_ITEM_BUTTON") 197 mount.connect("clicked",self. mount_profile_clicked,hbox)233 mount.connect("clicked",self.sync_profile_clicked,hbox) 198 234 mount.set_tooltip_text(_("Mount profile")) 199 235 hbox.pack_start(profile_image,False,False,0) … … 210 246 hbox.queue_draw() 211 247 212 #def new_p ackage_button248 #def new_profile_button 213 249 214 250 def accept_add_profile_clicked(self,widget): 215 251 216 if not self.edition: 217 profile=self.profile_entry.get_text() 218 profile=profile.strip(" ") 219 email=self.email_entry.get_text() 220 email=email.strip(" ") 221 mountpoint=self.mountpoint_entry.get_filename() 222 self.new_profile_button(profile,email,mountpoint) 223 224 else: 225 mountpoint=self.mountpoint_entry.get_filename() 226 self.profile_to_edit.get_children()[3].set_text(mountpoint) 227 252 profile=self.profile_entry.get_text() 253 profile=profile.strip(" ") 254 email=self.email_entry.get_text() 255 email=email.strip(" ") 256 mountpoint=self.mountpoint_entry.get_filename() 257 automount=self.automount_entry.get_state() 258 228 259 self.profiles_info[profile]={} 229 260 self.profiles_info[profile]["email"]=email 230 261 self.profiles_info[profile]["mountpoint"]=mountpoint 231 self.core.LliurexGoogleDriveManager.create_profile(self.profiles_info,profile) 262 self.profiles_info[profile]["automount"]=automount 263 264 265 if not self.edition: 266 result=self.core.LliurexGoogleDriveManager.create_profile(self.profiles_info,profile) 267 268 if result: 269 self.new_profile_button(profile,email,mountpoint) 270 self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() 271 272 else: 273 result=self.core.LliurexGoogleDriveManager.edit_profile(self.profiles_info,profile) 274 275 if result: 276 self.profile_to_edit.get_children()[3].set_text(mountpoint) 277 self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() 278 279 280 232 281 self.new_profile_window.hide() 233 282 283 #def accept_add_profile_clickedef 234 284 235 285 def cancel_add_profile_clicked(self,widget): … … 238 288 239 289 240 290 #def cancel_add_profile_clicked 241 291 242 292 #class profilebox
Note: See TracChangeset
for help on using the changeset viewer.