def _create_connection(self, credentials=None): if credentials is None: user, password = self._parsed_url.user, self._parsed_url.password else: user, password = credentials try: connection = gio.File(self.url) mount = None try: mount = connection.find_enclosing_mount() except gio.Error, e: if (e.code == gio.ERROR_NOT_MOUNTED): self.loop = glib.MainLoop() ui.ui_factory.show_message('Mounting %s using GIO' % \ self.url) op = gio.MountOperation() if user: op.set_username(user) if password: op.set_password(password) op.connect('ask-password', self._auth_cb) m = connection.mount_enclosing_volume( op, self._mount_done_cb) self.loop.run() except gio.Error, e: raise errors.TransportError(msg="Error setting up connection:" " %s" % str(e), orig_error=e)
def consolidate(self): utils.log_line("Running boxidate.Boxidator.consolidate()", datetime.datetime.now()) #put us in the right folder to start off with, just in case... os.chdir(self.MAIN_INBOX) # Disabled for now # self.move_contents_to_main_inbox(self.FS_INBOXES, self.MAIN_INBOX) # print "Contents of external filesystem inboxes moved." notelist = self.build_note_list(self.MAIN_INBOX) agg_xml = self.build_aggregate_note(notelist) self._back_up_SH() new_sh_xml = self.build_SH_replacement_xml(agg_xml) #FIXME: still required? time.sleep(2) msg = "".join(("Boxidate is adding this to your Start Here note:\n", new_sh_xml, "\n\n\n")) utils.log_line(msg, datetime.datetime.now(), '/home/jensck/fity-data/boxidate.log') self.set_SH_xml(new_sh_xml) self.delete_notes(notelist) # handle the stuff on Sidearm main_slider_inbox = gio.File(self.FITY_SLIDER_INBOX) main_inbox = gio.File(self.MAIN_INBOX) sidearm_sftp_inbox = gio.File(uri=self.SIDEARM_SFTP_INBOX_URI) try: # sidearm_sftp_inbox.find_enclosing_mount() sidearm_sftp_inbox.mount_enclosing_volume(gio.MountOperation(), self.import_inbox_async_cb, user_data=(sidearm_sftp_inbox, main_slider_inbox, main_inbox)) except gio.Error as error: print("Error while trying to mount sftp inbox: " + str(error))
def mount_enclosing_volume(self, mount_operation=None, callback=None, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None): """Mount the enclosing volume for `self`. Stolen from the PyGObject docs: "The mount_enclosing_volume() method starts a mount_operation, mounting the volume that contains the file location. When this operation has completed, callback will be called with user_data, and the operation can be finalized with gio.File.mount_enclosing_volume_finish(). If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error gio.ERROR_CANCELLED will be returned." Args: mount_operation: a gio.MountOperation - one will be created for you if you don't pass one in. callback: a function to call when the operation is complete - if None, 'lambda *args: None' will irresponsibly be used instead. flags: optional -- gio file copy flags - defaults to gio.FILE_COPY_NONE cancellable: optional -- a gio.Cancellable. Defaults to NONE user_data: optional -- any data to pass to `callback` when the mount operation completes. Defaults to None. """ mount_operation = mount_operation if mount_operation else gio.MountOperation() callback = callback if callback else lambda *args: None self._gfile.mount_enclosing_volume(mount_operation, callback, flags, cancellable, user_data)
def launch_fb(self, widget, path=None): self.dialog.hide() if isinstance(path, gtk.Widget): path = path.get_text() self.icon_dialog.hide() if self.mode == 1: self.docklet.destroy() elif path is None: path = self.entry.get_text() #Get the file browser app config_fb = self.client.get_string(group, 'fb') #In case there is nothing but whitespace (or at all) in the entry widget if path.replace(' ', '') == '': path = os.environ['HOME'] #Check if we're supposed to open nautilus-connect-server if path.split(':')[0] == 'exec': os.system('%s &' % path.split('://')[-1]) #Or mount a specified location elif path.split(':')[0] == 'mount': mo = gio.MountOperation() num = int(path.split('://')[-1]) self.monitor.get_volumes()[num].mount(mo, self.gio_mounted) #Otherwise, open the file/directory else: os.system('%s %s &' % (config_fb, path.replace(' ', '\ ')))
def __init_values(self): hseparator_color = [(0, ("#777777", 0.0)), (0.5, ("#000000", 0.3)), (1, ("#777777", 0.0)) ] self.height = 0 self.size_check = False self.hbox = gtk.HBox() self.title_image = gtk.image_new_from_file(os.path.join(image_path, "image/usb/usb_label.png")) self.title_label = gtk.Label(_("Storage Device")) #self.title_label.connect("expose-event", self.title_label_expose_event) self.title_label_ali = gtk.Alignment(0, 0, 0, 0) self.title_label_ali.set_padding(0, 0, 0, 0) self.title_label_ali.add(self.title_label) self.hbox.pack_start(self.title_image, False, False) self.hbox.pack_start(self.title_label_ali, True, True) self.h_separator_top = HSeparator(hseparator_color, 0, 0) self.h_separator_ali = gtk.Alignment(1, 1, 1, 1) self.h_separator_ali.set_padding(5, 10, 0, 0) self.h_separator_ali.add(self.h_separator_top) self.monitor_vbox = gtk.VBox() self.vbox = gtk.VBox() self.vbox.pack_start(self.hbox, False, False) self.vbox.pack_start(self.h_separator_ali, True, True) self.vbox.pack_start(self.monitor_vbox, True, True) self._ask_confirmed = False self.monitor = gio.VolumeMonitor() self.op = gio.MountOperation()
def device_btn_close_btn_clicked(self, widget, drive, volume, mount): # 挂载的开关. print "device_btn_close_btn_clicked..." op = gio.MountOperation() if mount: mount.unmount(self.cancall_opeartion, flags=gio.MOUNT_UNMOUNT_NONE) else: if volume: volume.mount(op, self.cancall_opeartion, flags=gio.MOUNT_MOUNT_NONE)
def clicked(self, sender, item): ''' Клик по кнопке ''' m = None path = None if isinstance(item, gio.Volume): m = item.get_mount() if not m and item.can_mount(): item.mount(gio.MountOperation(), self.async_result_callback) elif isinstance(item, gio.Mount): m = item else: path = item.path if m: path = m.get_root().get_path() if path: self.callback(DriveEvent(DriveEvent.TYPE_CD, path))
def append_volumes(self): # Delete old items for item in self.volume_items: item.destroy() self.volume_items = [] index = self.__volumes_index + len(self.bookmarks_items) for volume in self.__volumes_mounts_monitor.get_volumes(): name = volume.get_name() mount = volume.get_mount() if mount is not None: icon_name = self.get_icon_name(mount.get_icon()) tooltip = name else: icon_name = self.get_icon_name(volume.get_icon()) tooltip = _("Mount %s") % name item = self.create_menu_item(name, icon_name, tooltip) self.places_menu.insert(item, index) index += 1 self.volume_items.append(item) if mount is not None: uri = mount.get_root().get_uri() item.connect("activate", self.open_folder_cb, uri) else: def mount_volume(widget, vol): def mount_result(vol2, result): try: if vol2.mount_finish(result): uri = vol2.get_mount().get_root().get_uri() self.open_uri(uri) except glib.GError, e: error_dialog = self.UnableToMountErrorDialog( self.applet, vol2.get_name(), e) error_dialog.show_all() vol.mount(gio.MountOperation(), mount_result) item.connect("activate", mount_volume, volume)
def _mount(self, uri, domain, username, password=None): """Perform actual mounting operation with specified data""" self._show_spinner() def ask_password(operation, message, default_user, default_domain, flags): # configure mount operation operation.set_domain(domain if domain is not None and domain != '' else default_domain) operation.set_username(username if username is not None and username != '' else default_user) if password is not None: # set password to stored one operation.set_password(password) operation.reply(gio.MOUNT_OPERATION_HANDLED) else: # we don't have stored password, ask user to provide one with gtk.gdk.lock: dialog = InputDialog(self._application) dialog.set_title(_('Mount operation')) dialog.set_label(message) dialog.set_password() response = dialog.get_response() if response[0] == gtk.RESPONSE_OK: operation.set_password(response[1]) operation.reply(gio.MOUNT_OPERATION_HANDLED) # create new mount operation object operation = gio.MountOperation() operation.connect('ask-password', ask_password) # perform mount path = gio.File(uri) path.mount_enclosing_volume(operation, self.__mount_callback)
def mount_mountable(f): op = gio.MountOperation() op.connect('ask-password', ask_password_cb) f.mount_mountable(op, mount_mountable_done_cb)
def mount(f): op = gio.MountOperation() op.connect('ask-password', ask_password_cb) f.mount_enclosing_volume(op, mount_done_cb)
if e.code == gio.ERROR_ALREADY_MOUNTED: print('WARNING: testfile is already mounted, ' 'skipping test') loop.quit() return raise self.failUnless(retval) finally: try: mount = gfile.find_enclosing_mount() except gio.Error: loop.quit() return mount.unmount(unmount_done) mount_operation = gio.MountOperation() gfile.mount_enclosing_volume(mount_operation, mount_enclosing_volume_done) loop = glib.MainLoop() loop.run() def testCopy(self): if os.path.exists('copy.txt'): os.unlink("copy.txt") source = gio.File('file.txt') destination = gio.File('copy.txt') try: retval = source.copy(destination) self.failUnless(retval)
def Mount(self, f): if (SambaProvider.DEBUG): logger.debug('will try to mount {}'.format(f.get_uri())) op = gio.MountOperation() op.connect('ask-password', self.AskPasswordCb) f.mount_enclosing_volume(op, self.MountDoneCb)