def checkifmounted(self, source, mountbase): """ @return: True if mounted, False if not """ mountpoint = local_file_utils.joinpath( mountbase, self._defineMountDirName(source)) return local_file_utils.is_mount(mountpoint)
def _check_for_excludes(self, path): #, force_exclusion=False): """Checks given `path` for exclusion and adds it to the `ExcludeFlist` if required. Sub-directories are only entered in the case the `path` is not excluded. @param path: The path being checked for exclusion @note: Links are always backuped; TAR follows links (i.e. dereferences them = stores the actual content) only if option `followlinks` is set. A link targeting a directory yields 'islink=True' and 'isdir=True'. """ _excluded = False _stop_checking = False if self._is_excluded_by_name(path): if not self.__snapshot.is_subpath_in_incl_filelist(path): # add to exclude list, if not explicitly included; since paths can be nested, # it is checked for sub-paths instead of full paths self.__snapshot.addToExcludeFlist(path) self.__collect_stats.count_excl_config() _excluded = True elif self._is_excluded_by_force(path): # force exclusion e.g. path is defined in includes list but does not exist/is not accessable self.__snapshot.addToExcludeFlist(path) self.__collect_stats.count_excl_forced() _excluded = True elif self._is_excluded_by_size(path): if not self.__snapshot.is_subpath_in_incl_filelist(path): # add to exclude list, if not explicitly included; since paths can be nested, # it is checked for sub-paths instead of full paths self.__snapshot.addToExcludeFlist(path) self.__collect_stats.count_excl_config() _excluded = True if not _excluded: # path was not excluded, so do further tests (stats, enter dir...) if self.__fislink: self.__logger.debug("Symbolic link found: '%(path)s' -> '%(ln_target)s'."\ % {'path' : path, 'ln_target' : local_file_utils.get_link(path)}) self.__collect_stats.count_symlink() if not self.__snapshot.isFollowLinks(): # if `followlinks` is *disabled*, just count the link and finish _stop_checking = True if self.__fisdir: if _stop_checking: # i.e. `followlinks` is not enabled self.__collect_stats.count_file() self.__cumulate_size(path) else: # if it's a directory, enter inside try: for _dir_item in local_file_utils.listdir(path): _dir_item = local_file_utils.joinpath( path, _dir_item) self._check_for_excludes(path=_dir_item) self.__collect_stats.count_dir( ) # the directory `path` except OSError, _exc: self.__logger.warning(_("Error while checking directory '%(dir)s': %(error)s.")\ % {'dir' : path, 'error' : str(_exc)}) self.__snapshot.addToExcludeFlist( path) # problems with `path` -> exclude it self.__collect_stats.count_excl_forced() else: # it's a file (may also a link target in case of enabled `followlinks` option) self.__collect_stats.count_file() self.__cumulate_size(path)
def mount(self, source, mountbase): """ Mount the source intor the mountbase dir . This method should create a mount point to mount the source. The name of the mount point should be very expressive so that we avoid collision with other mount points @param source: The remote path @param mountbase: The mount points base dir @return: The mount point complete path """ exp = re.compile(ssh_url_re) match = exp.search(source) if not match: raise FuseFAMException( _("Error matching the schema 'ssh://*****:*****@example.com/home/' with '%s' (The '/' after server is mandatory)" ) % source) else: remoteSource = "ssh://" + match.group(1) if match.group(3): remoteSource += ":" + match.group(3) remoteSource += "@" + match.group(4) if match.group(6): remoteSource += ":" + match.group(6) remoteSource += "/" user = match.group(1) mountpoint = local_file_utils.joinpath( mountbase, self._defineMountDirName(source)) if match.group(7): pathinside = match.group(7) else: pathinside = "" #If the path is already mounted No need to retry if self.checkifmounted(source, mountbase): return (remoteSource, mountpoint, pathinside) cmd = "sshfs " + user + "@" + match.group(4) + ":/" cmd = cmd + " " + mountpoint port = match.group(6) if port: cmd += " -p " + port if not local_file_utils.path_exists(mountpoint): local_file_utils.makedir(mountpoint) if system.is_superuser(): cmd += " -o allow_root" self.logger.debug("Spawning: " + cmd) password = match.group(3) sshfsp = pexpect.spawn(cmd) i = sshfsp.expect(['(yes/no)', 'password:'******'Password:'******'yes') i = sshfsp.expect( ['(yes/no)', 'password:'******'Password:'******'(yes/no)', 'password:'******'Password:'******'%(command)s' didn't perform normally. Output => %(erroroutput)s " ) % { "command": cmd, "erroroutput": result }) return (remoteSource, mountpoint, pathinside)