コード例 #1
0
    def rename(self, src, dst):
        src = normpath(src)
        dst = normpath(dst)
        src_dir, src_name = pathsplit(src)
        src_entry = self._get_dir_entry(src)
        if src_entry is None:
            raise ResourceNotFoundError(src)
        open_files = src_entry.open_files[:]
        for f in open_files:
            f.flush()
            f.path = dst

        dst_dir,dst_name = pathsplit(dst)
        dst_entry = self._get_dir_entry(dst)
        if dst_entry is not None:
            raise DestinationExistsError(dst)

        src_dir_entry = self._get_dir_entry(src_dir)
        src_xattrs = src_dir_entry.xattrs.copy()
        dst_dir_entry = self._get_dir_entry(dst_dir)
        if dst_dir_entry is None:
            raise ParentDirectoryMissingError(dst)
        dst_dir_entry.contents[dst_name] = src_dir_entry.contents[src_name]
        dst_dir_entry.contents[dst_name].name = dst_name
        dst_dir_entry.xattrs.update(src_xattrs)
        del src_dir_entry.contents[src_name]
コード例 #2
0
ファイル: riakfs.py プロジェクト: jaydoane/python-riakfs
    def rename(self, src, dst):
        src = normpath(src)
        dst = normpath(dst)
        src_dir, src_name = pathsplit(src)
        src_entry = self._get_dir_entry(src)
        if src_entry is None:
            raise ResourceNotFoundError(src)
        open_files = src_entry.open_files[:]
        for f in open_files:
            f.flush()
            f.path = dst
        if src_entry.isdir():
            self.movedir(src, dst)
            return

        dst_dir, dst_name = pathsplit(dst)
        dst_entry = self._get_dir_entry(dst)
        if dst_entry is not None:
            raise DestinationExistsError(dst)

        src_dir_entry = self._get_dir_entry(src_dir)
        src_xattrs = src_dir_entry.xattrs.copy()
        dst_dir_entry = self._get_dir_entry(dst_dir)
        if dst_dir_entry is None:
            raise ParentDirectoryMissingError(dst)
        dst_dir_entry._make_dir_entry(src_entry.type, dst_name, src_entry.contents)
        # dst_dir_entry.contents[dst_name] = src_dir_entry.contents[src_name]
        # dst_dir_entry.contents[dst_name].name = dst_name
        # dst_dir_entry.xattrs.update(src_xattrs)
        # del src_dir_entry.contents[src_name]
        src_dir_entry.remove(src_name)
        self.dirty = True
コード例 #3
0
ファイル: ftpfs.py プロジェクト: smartfile/pyfilesystem
    def removedir(self, path, recursive=False, force=False, **kwargs):
        path = abspath(normpath(path))
        if not self.exists(path):
            raise ResourceNotFoundError(path)
        if self.isfile(path):
            raise ResourceInvalidError(path)
        if normpath(path) in ('', '/'):
            raise RemoveRootError(path)

        if not force:
            for _checkpath in self.listdir(path):
                raise DirectoryNotEmptyError(path)
        try:
            if force:
                for rpath in self.listdir(path, full=True):
                    try:
                        if self.isfile(rpath):
                            self.remove(rpath)
                        elif self.isdir(rpath):
                            self.removedir(rpath, force=force)
                    except FSError:
                        pass
            self.clear_dircache(dirname(path))
            self.ftp.rmd(_encode(path))
        except error_reply:
            pass
        if recursive:
            try:
                if dirname(path) not in ('', '/'):
                    self.removedir(dirname(path), recursive=True)
            except DirectoryNotEmptyError:
                pass
        self.clear_dircache(dirname(path), path)
コード例 #4
0
ファイル: __init__.py プロジェクト: dmitry-viskov/smbfs
    def copy(self, src, dst, overwrite=False, chunk_size=1024 * 1024):
        src = normpath(src)

        if not self.isfile(src):
            if self.isdir(src):
                raise ResourceInvalidError(src, msg="Source is not a file: %(path)s")
            raise ResourceNotFoundError(src)

        dst = normpath(dst)

        if not overwrite and self.exists(dst):
            raise DestinationExistsError(dst)

        src_file = None
        dst_file = None

        try:
            src_file = self.open(src, 'r')
            dst_file = self.open(dst, 'w')

            while 1:
                copy_buffer = src_file.read(chunk_size)
                if copy_buffer:
                    dst_file.write(copy_buffer)
                else:
                    break
        finally:
            if src_file is not None:
                src_file.close()
            if dst_file is not None:
                dst_file.close()
コード例 #5
0
ファイル: __init__.py プロジェクト: pombreda/smbfs
    def copy(self, src, dst, overwrite=False, chunk_size=1024 * 1024):
        src = normpath(src)

        if not self.isfile(src):
            if self.isdir(src):
                raise ResourceInvalidError(
                    src, msg="Source is not a file: %(path)s")
            raise ResourceNotFoundError(src)

        dst = normpath(dst)

        if not overwrite and self.exists(dst):
            raise DestinationExistsError(dst)

        src_file = None
        dst_file = None

        try:
            src_file = self.open(src, 'r')
            dst_file = self.open(dst, 'w')

            while 1:
                copy_buffer = src_file.read(chunk_size)
                if copy_buffer:
                    dst_file.write(copy_buffer)
                else:
                    break
        finally:
            if src_file is not None:
                src_file.close()
            if dst_file is not None:
                dst_file.close()
コード例 #6
0
ファイル: ftpfs.py プロジェクト: svn2github/pyfilesystem
    def removedir(self, path, recursive=False, force=False):
        path = abspath(normpath(path))
        if not self.exists(path):
            raise ResourceNotFoundError(path)
        if self.isfile(path):
            raise ResourceInvalidError(path)
        if normpath(path) in ('', '/'):
            raise RemoveRootError(path)

        if not force:
            for _checkpath in self.listdir(path):
                raise DirectoryNotEmptyError(path)
        try:
            if force:
                for rpath in self.listdir(path, full=True):
                    try:
                        if self.isfile(rpath):
                            self.remove(rpath)
                        elif self.isdir(rpath):
                            self.removedir(rpath, force=force)
                    except FSError:
                        pass
            self.clear_dircache(dirname(path))
            self.ftp.rmd(_encode(path))
        except error_reply:
            pass
        if recursive:
            try:
                if dirname(path) not in ('', '/'):
                    self.removedir(dirname(path), recursive=True)
            except DirectoryNotEmptyError:
                pass
        self.clear_dircache(dirname(path), path)
コード例 #7
0
ファイル: memoryfs.py プロジェクト: Liryna/pyfilesystem
    def rename(self, src, dst):
        src = normpath(src)
        dst = normpath(dst)
        src_dir, src_name = pathsplit(src)
        src_entry = self._get_dir_entry(src)
        if src_entry is None:
            raise ResourceNotFoundError(src)
        open_files = src_entry.open_files[:]
        for f in open_files:
            f.flush()
            f.path = dst

        dst_dir,dst_name = pathsplit(dst)
        dst_entry = self._get_dir_entry(dst)
        if dst_entry is not None:
            raise DestinationExistsError(dst)

        src_dir_entry = self._get_dir_entry(src_dir)
        src_xattrs = src_dir_entry.xattrs.copy()
        dst_dir_entry = self._get_dir_entry(dst_dir)
        if dst_dir_entry is None:
            raise ParentDirectoryMissingError(dst)
        dst_dir_entry.contents[dst_name] = src_dir_entry.contents[src_name]
        dst_dir_entry.contents[dst_name].name = dst_name
        dst_dir_entry.xattrs.update(src_xattrs)
        del src_dir_entry.contents[src_name]
コード例 #8
0
ファイル: gedaproject.py プロジェクト: chintal/tendril
def gen_pcb_dxf(projfolder, force=False):
    """
    Generates a DXF file of the PCB provided by the gEDA project.

    The pcb file is the one listed in the gEDA project file, and the
    pcbname is the one specified in the
    :mod:`tendril.gedaif.conffile.ConfigsFile`.

    This function does not use jinja2 and latex. It relies on
    :func:`tendril.gedaif.pcb.conv_pcb2dxf` instead.

    :param projfolder: The gEDA project folder.
    :type projfolder: str
    :param force: Regenerate even if up-to-date.
    :type force: bool
    :return: The output file path.

    .. rubric:: Paths

    * Output File :  ``<projectfolder>/pcb/<pcbfile>.dxf``
    * Source Files : The project's `.pcb` file.

    """
    configfile = conffile.ConfigsFile(projfolder)
    gpf = projfile.GedaProjectFile(configfile.projectfolder)
    pcb_mtime = fsutils.get_file_mtime(
        os.path.join(configfile.projectfolder, 'pcb', gpf.pcbfile + '.pcb'),
    )
    if pcb_mtime is None:
        logger.warning("PCB does not seem to exist for : " + projfolder)
        return
    docfolder = get_project_doc_folder(projfolder)
    dxffile = path.normpath(os.path.join(docfolder, os.pardir,
                            configfile.pcbname + '.dxf'))
    bottom_dxffile = path.normpath(os.path.join(docfolder, os.pardir,
                                   configfile.pcbname + 'bottom.dxf'))

    outf_mtime = fsutils.get_file_mtime(dxffile, fs=refdoc_fs)

    if not force and outf_mtime is not None and outf_mtime > pcb_mtime:
        logger.debug('Skipping up-to-date ' + dxffile)
        return dxffile

    logger.info('Regenerating ' + dxffile + os.linesep +
                'Last modified : ' + str(pcb_mtime) +
                '; Last Created : ' + str(outf_mtime))

    workspace_folder = workspace_fs.getsyspath(path.dirname(dxffile))
    workspace_fs.makedir(path.dirname(dxffile),
                         recursive=True, allow_recreate=True)

    pcb.conv_pcb2dxf(
        os.path.join(configfile.projectfolder, 'pcb', gpf.pcbfile + '.pcb'),
        workspace_folder, configfile.pcbname
    )

    copyfile(workspace_fs, dxffile, refdoc_fs, dxffile, overwrite=True)
    copyfile(workspace_fs, bottom_dxffile, refdoc_fs, bottom_dxffile, overwrite=True)
    return dxffile
コード例 #9
0
ファイル: gedaproject.py プロジェクト: chintal/tendril
def gen_pcb_dxf(projfolder, force=False):
    """
    Generates a DXF file of the PCB provided by the gEDA project.

    The pcb file is the one listed in the gEDA project file, and the
    pcbname is the one specified in the
    :mod:`tendril.gedaif.conffile.ConfigsFile`.

    This function does not use jinja2 and latex. It relies on
    :func:`tendril.connectors.geda.pcb.conv_pcb2dxf` instead.

    :param projfolder: The gEDA project folder.
    :type projfolder: str
    :param force: Regenerate even if up-to-date.
    :type force: bool
    :return: The output file path.

    .. rubric:: Paths

    * Output File :  ``<projectfolder>/pcb/<pcbfile>.dxf``
    * Source Files : The project's `.pcb` file.

    """
    configfile = conffile.ConfigsFile(projfolder)
    gpf = projfile.GedaProjectFile(configfile.projectfolder)
    pcb_mtime = fsutils.get_file_mtime(
        os.path.join(configfile.projectfolder, 'pcb', gpf.pcbfile + '.pcb'),
    )
    if pcb_mtime is None:
        logger.warning("PCB does not seem to exist for : " + projfolder)
        return
    docfolder = get_project_doc_folder(projfolder)
    dxffile = path.normpath(os.path.join(docfolder, os.pardir,
                            configfile.pcbname + '.dxf'))
    bottom_dxffile = path.normpath(os.path.join(docfolder, os.pardir,
                                   configfile.pcbname + 'bottom.dxf'))

    outf_mtime = fsutils.get_file_mtime(dxffile, fs=refdoc_fs)

    if not force and outf_mtime is not None and outf_mtime > pcb_mtime:
        logger.debug('Skipping up-to-date ' + dxffile)
        return dxffile

    logger.info('Regenerating ' + dxffile + os.linesep +
                'Last modified : ' + str(pcb_mtime) +
                '; Last Created : ' + str(outf_mtime))

    workspace_folder = workspace_fs.getsyspath(path.dirname(dxffile))
    workspace_fs.makedir(path.dirname(dxffile),
                         recursive=True, allow_recreate=True)

    pcb.conv_pcb2dxf(
        os.path.join(configfile.projectfolder, 'pcb', gpf.pcbfile + '.pcb'),
        workspace_folder, configfile.pcbname
    )

    copyfile(workspace_fs, dxffile, refdoc_fs, dxffile, overwrite=True)
    copyfile(workspace_fs, bottom_dxffile, refdoc_fs, bottom_dxffile, overwrite=True)
    return dxffile
コード例 #10
0
ファイル: dropboxfs.py プロジェクト: mhellmic/b2share
 def copydir(self, src, dst, *args, **kwargs):
     """
     @param src: Path to the folder to be copied
     @param dst: Path to the folder in which to copy the folder
     @return: Path to the copied folder
     """
     src = abspath(normpath(src))
     dst = abspath(normpath(dst))
     return self.client.file_copy(src, dst)
コード例 #11
0
    def copydir(self, src, dst, *args, **kwargs):
        """Copy a directory to another location.

        :param src: Path to the folder to be copied
        :param dst: Path to the folder in which to copy the folder
        :return: Path to the copied folder
        """
        src = abspath(normpath(src))
        dst = abspath(normpath(dst))
        return self.client.file_copy(src, dst)
コード例 #12
0
ファイル: dropboxfs.py プロジェクト: mhellmic/b2share
 def rename(self, src, dst, *args, **kwargs):
     """
     @param src: Path to the file to be renamed
     @param dst: Full path with the new name
     @raise UnsupportedError: If trying to remove the root directory
     @return: Path to the renamed file
     """
     src = abspath(normpath(src))
     dst = abspath(normpath(dst))
     return self.client.file_move(src, dst)
コード例 #13
0
ファイル: dropboxfs.py プロジェクト: mhellmic/b2share
 def movedir(self, src, dst, *args, **kwargs):
     """
     @param src: Path to the folder to be moved
     @param dst: Path to the folder in which the folder will be moved
     @param chunk_size: if using chunk upload
     @return: Path to the moved folder
     """
     src = abspath(normpath(src))
     dst = abspath(normpath(dst))
     return self.client.file_move(src, dst)
コード例 #14
0
ファイル: dropboxfs.py プロジェクト: SCOAP3/invenio
    def copydir(self, src, dst, *args, **kwargs):
        """Copy a directory to another location.

        :param src: Path to the folder to be copied
        :param dst: Path to the folder in which to copy the folder
        :return: Path to the copied folder
        """
        src = abspath(normpath(src))
        dst = abspath(normpath(dst))
        return self.client.file_copy(src, dst)
コード例 #15
0
    def movedir(self, src, dst, *args, **kwargs):
        """Move a directory to another location.

        :param src: Path to the folder to be moved
        :param dst: Path to the folder in which the folder will be moved
        :param chunk_size: if using chunk upload
        :return: Path to the moved folder
        """
        src = abspath(normpath(src))
        dst = abspath(normpath(dst))
        return self.client.file_move(src, dst)
コード例 #16
0
    def rename(self, src, dst, *args, **kwargs):
        """Rename a file of a given path.

        :param src: Path to the file to be renamed
        :param dst: Full path with the new name
        :raise UnsupportedError: If trying to remove the root directory
        :return: Path to the renamed file
        """
        src = abspath(normpath(src))
        dst = abspath(normpath(dst))
        return self.client.file_move(src, dst)
コード例 #17
0
ファイル: dropboxfs.py プロジェクト: SCOAP3/invenio
    def movedir(self, src, dst, *args, **kwargs):
        """Move a directory to another location.

        :param src: Path to the folder to be moved
        :param dst: Path to the folder in which the folder will be moved
        :param chunk_size: if using chunk upload
        :return: Path to the moved folder
        """
        src = abspath(normpath(src))
        dst = abspath(normpath(dst))
        return self.client.file_move(src, dst)
コード例 #18
0
ファイル: ftpfs.py プロジェクト: smartfile/pyfilesystem
 def open(self, path, mode, buffering=-1, encoding=None, errors=None, newline=None, line_buffering=False, **kwargs):
     path = normpath(path)
     mode = mode.lower()
     if self.isdir(path):
         raise ResourceInvalidError(path)
     if 'r' in mode or 'a' in mode:
         if not self.isfile(path):
             raise ResourceNotFoundError(path)
     if 'w' in mode or 'a' in mode or '+' in mode:
         self.refresh_dircache(dirname(path))
     ftp = self._open_ftp()
     f = _FTPFile(self, ftp, normpath(path), mode)
     return f
コード例 #19
0
 def open(self, path, mode, buffering=-1, encoding=None, errors=None, newline=None, line_buffering=False, **kwargs):
     path = normpath(path)
     mode = mode.lower()
     if self.isdir(path):
         raise ResourceInvalidError(path)
     if 'r' in mode or 'a' in mode:
         if not self.isfile(path):
             raise ResourceNotFoundError(path)
     if 'w' in mode or 'a' in mode or '+' in mode:
         self.refresh_dircache(dirname(path))
     ftp = self._open_ftp()
     f = _FTPFile(self, ftp, normpath(path), mode)
     return f
コード例 #20
0
ファイル: ftpfs.py プロジェクト: offlinehacker/pyfilesystem
 def open(self, path, mode="r"):
     path = normpath(path)
     mode = mode.lower()
     if self.isdir(path):
         raise ResourceInvalidError(path)
     if "r" in mode or "a" in mode:
         if not self.isfile(path):
             raise ResourceNotFoundError(path)
     if "w" in mode or "a" in mode or "+" in mode:
         self.refresh_dircache(dirname(path))
     ftp = self._open_ftp()
     f = _FTPFile(self, ftp, normpath(path), mode)
     return f
コード例 #21
0
ファイル: ftpfs.py プロジェクト: devs1991/test_edx_docmode
 def open(self, path, mode='r'):
     path = normpath(path)
     mode = mode.lower()
     if self.isdir(path):
         raise ResourceInvalidError(path)
     if 'r' in mode or 'a' in mode:
         if not self.isfile(path):
             raise ResourceNotFoundError(path)
     if 'w' in mode or 'a' in mode or '+' in mode:
         self.refresh_dircache(dirname(path))
     ftp = self._open_ftp()
     f = _FTPFile(self, ftp, normpath(path), mode)
     return f
コード例 #22
0
 def ftp_move_to(self, item):
     txt = item.text()
     txt2 = normpath(join(self.pathbarftp.text(), txt))
     self.li.clear()
     if txt2 != '/':
         normpath(join(txt2, '..'))
         item = QListWidgetItem(
             qta.icon('fa5s.folder-open', color='orange'), '..', self.li)
         self.li.addItem(item)
     for i in self.ftpm.list_dir(txt2):
         item = QListWidgetItem(
             qta.icon('fa5s.folder-open', color='orange'), i, self.li)
         self.li.addItem(item)
     self.pathbarftp.setText(txt2)
コード例 #23
0
ファイル: sqlitefs.py プロジェクト: Liryna/pyfilesystem
 def rename(self,src, dst):
     self._initdb()
     src = normpath(src)
     dst = normpath(dst)
     if self._isexist(dst)== False:
         #first check if this is a directory rename or a file rename
         if( self.isfile(src)):
             self._rename_file(src, dst)
         elif self.isdir(src):
             self._rename_dir(src, dst)
         else:
             raise ResourceNotFoundError(path)
     else:
         raise DestinationExistsError(dst)
コード例 #24
0
 def rename(self,src, dst):
     self._initdb()
     src = normpath(src)
     dst = normpath(dst)
     if self._isexist(dst)== False:
         #first check if this is a directory rename or a file rename
         if( self.isfile(src)):
             self._rename_file(src, dst)
         elif self.isdir(src):
             self._rename_dir(src, dst)
         else:
             raise ResourceNotFoundError(path)
     else:
         raise DestinationExistsError(dst)
コード例 #25
0
ファイル: httpapifs.py プロジェクト: pombreda/httpapifs
    def open(self, path, mode="r"):

        path = normpath(path)
        mode = mode.lower()        
        if self.isdir(path):
            raise ResourceInvalidError(path)        
        if 'a' in mode or '+' in mode:
            raise UnsupportedError('write')
            
        if 'r' in mode:
            if not self.isfile(path):
                raise ResourceNotFoundError(path)

        f = HttpApiFSFile(self, normpath(path), mode) 
        return f 
コード例 #26
0
ファイル: httpapifs.py プロジェクト: pombreda/httpapifs
    def open(self, path, mode="r"):

        path = normpath(path)
        mode = mode.lower()
        if self.isdir(path):
            raise ResourceInvalidError(path)
        if 'a' in mode or '+' in mode:
            raise UnsupportedError('write')

        if 'r' in mode:
            if not self.isfile(path):
                raise ResourceNotFoundError(path)

        f = HttpApiFSFile(self, normpath(path), mode)
        return f
コード例 #27
0
 def _encode(self, path):
     path = relpath(normpath(path))
     path = path.replace(":", "__colon__")
     if not self.allow_autorun:
         if path.lower().startswith("_autorun."):
             path = path[1:]
     return path
コード例 #28
0
ファイル: __init__.py プロジェクト: Gianfranco753/fs-smb
 def inner_2(fs, *args, **kwargs):
     new_args = []
     for ndx, arg in enumerate(args):
         if ndx < num_paths:
             arg = abspath(normpath(arg))
         new_args.append(arg)
     return func(fs, *new_args, **kwargs)
コード例 #29
0
    def makedir(self, path, recursive=False, allow_recreate=False):
        path = normpath(path)
        if path in ('', '/'):
            return
        def checkdir(path):
            if not self.isdir(path):
                self.clear_dircache(dirname(path))
                try:
                    self.ftp.mkd(_encode(path))
                except error_reply:
                    return
                except error_perm as e:
                    if recursive or allow_recreate:
                        return
                    if str(e).split(' ', 1)[0]=='550':
                        raise DestinationExistsError(path)
                    else:
                        raise
        if recursive:
            for p in recursepath(path):
                checkdir(p)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
            checkdir(path)
コード例 #30
0
ファイル: _s3fs.py プロジェクト: miarec/s3fs
 def __init__(self,
              bucket_name,
              dir_path='/',
              aws_access_key_id=None,
              aws_secret_access_key=None,
              aws_session_token=None,
              endpoint_url=None,
              region=None,
              delimiter='/',
              strict=True):
     _creds = (aws_access_key_id, aws_secret_access_key)
     if any(_creds) and not all(_creds):
         raise ValueError(
             'aws_access_key_id and aws_secret_access_key '
             'must be set together if specified'
         )
     self._bucket_name = bucket_name
     self.dir_path = dir_path
     self._prefix = relpath(normpath(dir_path)).rstrip('/')
     self.aws_access_key_id = aws_access_key_id
     self.aws_secret_access_key = aws_secret_access_key
     self.aws_session_token = aws_session_token
     self.endpoint_url = endpoint_url
     self.region = region
     self.delimiter = delimiter
     self.strict = strict
     self._tlocal = threading.local()
     super(S3FS, self).__init__()
コード例 #31
0
ファイル: riakfs.py プロジェクト: jaydoane/python-riakfs
    def removedir(self, path, recursive=False, force=False):
        path = normpath(path)
        dir_entry = self._get_dir_entry(path)

        if dir_entry is None:
            raise ResourceNotFoundError(path)
        if not dir_entry.isdir():
            raise ResourceInvalidError(path, msg="Can't remove resource, its not a directory: %(path)s")

        if dir_entry.contents and not force:
            raise DirectoryNotEmptyError(path)

        if recursive:
            rpathname = path
            while rpathname:
                rpathname, dirname = pathsplit(rpathname)
                parent_dir = self._get_dir_entry(rpathname)
                parent_dir.remove(dirname)
                # del parent_dir.contents[dirname]
        else:
            pathname, dirname = pathsplit(path)
            parent_dir = self._get_dir_entry(pathname)
            parent_dir.remove(dirname)
            # del parent_dir.contents[dirname]
        self.dirty = True
コード例 #32
0
ファイル: __init__.py プロジェクト: dmitry-viskov/smbfs
    def makedir(self, path, recursive=False, allow_recreate=False):
        path = normpath(path)
        if path in ('', '/'):
            return

        if recursive:
            created = False
            for path_part in recursepath(path):
                if not self.isdir(path_part):
                    self.conn.mkdir(self.smb_path(path_part))
                    created = True
                else:
                    if self.isfile(path_part):
                        raise ResourceInvalidError(path_part)

            if not created and not allow_recreate:
                raise DestinationExistsError(path)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
                self.conn.mkdir(self.smb_path(path))
            else:
                if not self.isdir(path):
                    self.conn.mkdir(self.smb_path(path))
コード例 #33
0
    def removedir(self, path, recursive=False, force=False):
        path = normpath(path)
        if path in ('', '/'):
            raise RemoveRootError(path)
        dir_entry = self._get_dir_entry(path)

        if dir_entry is None:
            raise ResourceNotFoundError(path)
        if not dir_entry.isdir():
            raise ResourceInvalidError(path, msg="Can't remove resource, its not a directory: %(path)s" )

        if dir_entry.contents and not force:
            raise DirectoryNotEmptyError(path)

        if recursive:
            rpathname = path
            while rpathname:
                rpathname, dirname = pathsplit(rpathname)
                parent_dir = self._get_dir_entry(rpathname)
                if not dirname:
                    raise RemoveRootError(path)
                del parent_dir.contents[dirname]
                # stop recursing if the directory has other contents
                if parent_dir.contents:
                    break
        else:
            pathname, dirname = pathsplit(path)
            parent_dir = self._get_dir_entry(pathname)
            if not dirname:
                raise RemoveRootError(path)
            del parent_dir.contents[dirname]
コード例 #34
0
ファイル: dropboxfs.py プロジェクト: SCOAP3/invenio
    def listdir(self, path="/", wildcard=None, full=False, absolute=False,
                dirs_only=False, files_only=False):
        """List the the files and directories under a given path.

        The directory contents are returned as a list of unicode paths

        :param path: path to the folder to list
        :type path: string
        :param wildcard: Only returns paths that match this wildcard
        :type wildcard: string containing a wildcard, or a callable
            that accepts a path and returns a boolean
        :param full: returns full paths (relative to the root)
        :type full: bool
        :param absolute: returns absolute paths
            (paths beginning with /)
        :type absolute: bool
        :param dirs_only: if True, only return directories
        :type dirs_only: bool
        :param files_only: if True, only return files
        :type files_only: bool
        :return: a list of unicode paths
        """
        path = abspath(normpath(path))
        children = self.client.children(path)
        return self._listdir_helper(path, children, wildcard, full, absolute,
                                    dirs_only, files_only)
コード例 #35
0
ファイル: dropboxfs.py プロジェクト: SCOAP3/invenio
    def open(self, path, mode="rb", **kwargs):
        """Open the named file in the given mode.

        This method downloads the file contents into a local temporary
        file so that it can be worked on efficiently.  Any changes
        made to the file are only sent back to cloud storage when
        the file is flushed or closed.

        :param path: Path to the file to be opened
        :param mode: In which mode to open the file
        :raise ResourceNotFoundError: If given path doesn't exist and
            'w' is not in mode
        :return: RemoteFileBuffer object
        """
        path = abspath(normpath(path))
        spooled_file = SpooledTemporaryFile(mode=mode, bufsize=MAX_BUFFER)

        if "w" in mode:
            # Truncate the file if requested
            self.client.put_file(path, "", True)
        else:
            # Try to write to the spooled file, if path doesn't exist create it
            # if 'w' is in mode
            try:
                spooled_file.write(self.client.get_file(path).read())
                spooled_file.seek(0, 0)
            except:
                if "w" not in mode:
                    raise ResourceNotFoundError(path)
                else:
                    self.createfile(path, True)
        #  This will take care of closing the socket when it's done.
        return RemoteFileBuffer(self, path, mode, spooled_file)
コード例 #36
0
 def _path_to_key(self, path):
     """Converts an fs path to a s3 key."""
     _path = relpath(normpath(path))
     _key = (
         "{}/{}".format(self._prefix, _path).lstrip("/").replace("/", self.delimiter)
     )
     return _key
コード例 #37
0
 def _path_to_dir_key(self, path):
     """Converts an fs path to a s3 key."""
     _path = relpath(normpath(path))
     _key = forcedir("{}/{}".format(self._prefix,
                                    _path)).lstrip('/').replace(
                                        '/', self.delimiter)
     return _key
コード例 #38
0
 def check_template(self, template_path):
     """Check if a template exists"""
     template_path = abspath(normpath(template_path))
     if template_path in self.templates:
         return
     if not self.template_fs.exists(template_path):
         raise MissingTemplateError(template_path)
コード例 #39
0
ファイル: sizefs.py プロジェクト: jjw-itinnov/sizefs
    def open(self, path, mode="r", **kwargs):
        """

        """
        path = normpath(path)
        file_path, file_name = pathsplit(path)
        parent_dir_entry = self._get_dir_entry(file_path)

        if parent_dir_entry is None or not parent_dir_entry.isdir():
            raise ResourceNotFoundError(path)

        if 'r' in mode:

            if file_name in parent_dir_entry.contents:
                file_dir_entry = parent_dir_entry.contents[file_name]
                if file_dir_entry.isdir():
                    raise ResourceInvalidError(path)

                file_dir_entry.accessed_time = datetime.datetime.now()
                return file_dir_entry.mem_file
            else:
                size = _get_size(file_name)
                mem_file = SizeFile(path, size, filler=parent_dir_entry.filler)
                return mem_file

        elif 'w' in mode or 'a' in mode:
            raise NotImplementedError
コード例 #40
0
    def _readdir(self, path):
        path = abspath(normpath(path))
        if self.dircache.count:
            cached_dirlist = self.dircache.get(path)
            if cached_dirlist is not None:
                return cached_dirlist
        dirlist = {}

        parser = FTPListDataParser()

        def on_line(line):
            if not isinstance(line, unicode):
                line = line.decode('utf-8')
            info = parser.parse_line(line)
            if info:
                info = info.__dict__
                if info['name'] not in ('.', '..'):
                    dirlist[info['name']] = info

        try:
            self.ftp.dir(_encode(path), on_line)
        except error_reply:
            pass
        self.dircache[path] = dirlist

        return dirlist
コード例 #41
0
ファイル: memoryfs.py プロジェクト: Liryna/pyfilesystem
    def removedir(self, path, recursive=False, force=False):
        path = normpath(path)
        if path in ('', '/'):
            raise RemoveRootError(path)
        dir_entry = self._get_dir_entry(path)

        if dir_entry is None:
            raise ResourceNotFoundError(path)
        if not dir_entry.isdir():
            raise ResourceInvalidError(path, msg="Can't remove resource, its not a directory: %(path)s" )

        if dir_entry.contents and not force:
            raise DirectoryNotEmptyError(path)

        if recursive:
            rpathname = path
            while rpathname:
                rpathname, dirname = pathsplit(rpathname)
                parent_dir = self._get_dir_entry(rpathname)
                if not dirname:
                    raise RemoveRootError(path)
                del parent_dir.contents[dirname]
                # stop recursing if the directory has other contents
                if parent_dir.contents:
                    break
        else:
            pathname, dirname = pathsplit(path)
            parent_dir = self._get_dir_entry(pathname)
            if not dirname:
                raise RemoveRootError(path)
            del parent_dir.contents[dirname]
コード例 #42
0
ファイル: dropboxfs.py プロジェクト: mhellmic/b2share
 def desc(self, path):
     """
     @return: The title for the given path.
     """
     path = abspath(normpath(path))
     info = self.getinfo(path)
     return info["title"]
コード例 #43
0
ファイル: ftpfs.py プロジェクト: pombreda/pyfilesystem-4
 def realpath(self, path):
     path = normpath(path)
     link_target = self.get_link_target(path)
     if link_target is None:
         return path
     else:
         return deref_link(path, link_target)
コード例 #44
0
    def listdir(self,
                path="/",
                wildcard=None,
                full=False,
                absolute=False,
                dirs_only=False,
                files_only=False):
        """List the the files and directories under a given path.

        The directory contents are returned as a list of unicode paths

        :param path: path to the folder to list
        :type path: string
        :param wildcard: Only returns paths that match this wildcard
        :type wildcard: string containing a wildcard, or a callable
            that accepts a path and returns a boolean
        :param full: returns full paths (relative to the root)
        :type full: bool
        :param absolute: returns absolute paths
            (paths beginning with /)
        :type absolute: bool
        :param dirs_only: if True, only return directories
        :type dirs_only: bool
        :param files_only: if True, only return files
        :type files_only: bool
        :return: a list of unicode paths
        """
        path = abspath(normpath(path))
        children = self.client.children(path)
        return self._listdir_helper(path, children, wildcard, full, absolute,
                                    dirs_only, files_only)
コード例 #45
0
ファイル: environment.py プロジェクト: chrmorais/moya
 def check_template(self, template_path):
     """Check if a template exists"""
     template_path = abspath(normpath(template_path))
     if template_path in self.templates:
         return
     if not self.template_fs.exists(template_path):
         raise MissingTemplateError(template_path)
コード例 #46
0
ファイル: ftpfs.py プロジェクト: offlinehacker/pyfilesystem
 def _check_path(self, path):
     path = normpath(path)
     base, fname = pathsplit(abspath(path))
     dirlist = self._readdir(base)
     if fname and fname not in dirlist:
         raise ResourceNotFoundError(path)
     return dirlist, fname
コード例 #47
0
 def _isfile(self, path):
     path = normpath(path)
     filedir = dirname(path)
     filename = basename(path)
     dirid = self._get_dir_id(filedir)
     return (dirid is not None
             and self._get_file_id(dirid, filename) is not None)
コード例 #48
0
    def listdir(self,
                path="./",
                wildcard=None,
                full=False,
                absolute=False,
                dirs_only=False,
                files_only=False):
        if not path:
            raise PathError(path)

        path = normpath(path)

        item = self._get_item_by_path(path)
        if not item:
            raise ResourceNotFoundError(path)
        if item['type'] != _ITEM_TYPE_FOLDER:
            raise ResourceInvalidError(path)

        item_children = self._get_children_items(item['id'])
        result = []
        for child in item_children.values():
            child_type = child['type']
            if dirs_only and child_type != _ITEM_TYPE_FOLDER:
                continue
            if files_only and child_type != _ITEM_TYPE_FILE:
                continue

            child_path = child['name']
            if full:
                child_path = pathjoin(path, child_path)

            result.append(child_path)

        return result
コード例 #49
0
    def remove(self, path):
        self._initdb()
        path = normpath(path)
        if (self.isdir(path) == True):
            #path is actually a directory
            raise ResourceInvalidError(path)

        filedir = dirname(path)
        filename = basename(path)
        dirid = self._get_dir_id(filedir)
        fileid = self._get_file_id(dirid, filename)
        if (fileid == None):
            raise ResourceNotFoundError(path)

        content_id = self._get_file_contentid(fileid)

        self._updatecur.execute("DELETE FROM FsFileMetaData where ROWID=?",
                                (fileid, ))
        #check there is any other file pointing to same location. If not
        #delete the content as well.
        self._querycur.execute(
            'SELECT count(*) FROM FsFileMetaData where fileid=?',
            (content_id, ))
        row = fetchone(self._querycur)
        if (row == None or row[0] == 0):
            self._updatecur.execute("DELETE FROM FsFileTable where ROWID=?",
                                    (content_id, ))
コード例 #50
0
ファイル: ftpfs.py プロジェクト: devs1991/test_edx_docmode
 def _check_path(self, path):
     path = normpath(path)
     base, fname = pathsplit(abspath(path))
     dirlist = self._readdir(base)
     if fname and fname not in dirlist:
         raise ResourceNotFoundError(path)
     return dirlist, fname
コード例 #51
0
ファイル: __init__.py プロジェクト: pombreda/fs-smb
 def inner_2(fs, *args, **kwargs):
     new_args = []
     for ndx, arg in enumerate(args):
         if ndx < num_paths:
             arg = abspath(normpath(arg))
         new_args.append(arg)
     return func(fs, *new_args, **kwargs)
コード例 #52
0
ファイル: ftpfs.py プロジェクト: devs1991/test_edx_docmode
 def getcontents(self, path):
     path = normpath(path)
     contents = StringIO()
     self.ftp.retrbinary('RETR %s' % _encode(path),
                         contents.write,
                         blocksize=1024 * 64)
     return contents.getvalue()
コード例 #53
0
ファイル: __init__.py プロジェクト: pombreda/fs-smb
 def _listPath(self, path, list_contents=False):
     """ Path listing with SMB errors converted. """
     # Explicitly convert the SMB errors to be able to catch the
     # PyFilesystem error while listing the path.
     if list_contents:
         try:
             # List all contents of a directory.
             return _conv_smb_errors(self.conn.listPath)(self.share,
                                                         normpath(path))
         except ResourceNotFoundError:
             if self.isfile(path):
                 raise ResourceInvalidError(path)
             raise
     else:
         # List a specific path (file or directory) by listing the contents
         # of the containing directory and comparing the filename.
         pathdir = dirname(path)
         searchpath = basename(path)
         for i in _conv_smb_errors(self.conn.listPath)(self.share, pathdir):
             if i.filename == '..':
                 continue
             elif ((i.filename == '.' and searchpath == '')
                   or i.filename == searchpath):
                 return i
         raise ResourceNotFoundError(path)
コード例 #54
0
ファイル: __init__.py プロジェクト: Gianfranco753/fs-smb
 def _listPath(self, path, list_contents=False):
     """ Path listing with SMB errors converted. """
     # Explicitly convert the SMB errors to be able to catch the
     # PyFilesystem error while listing the path.
     if list_contents:
         try:
             # List all contents of a directory.
             return _conv_smb_errors(self.conn.listPath)(
                 self.share, normpath(path))
         except ResourceNotFoundError:
             if self.isfile(path):
                 raise ResourceInvalidError(path)
             raise
     else:
         # List a specific path (file or directory) by listing the contents
         # of the containing directory and comparing the filename.
         pathdir = dirname(path)
         searchpath = basename(path)
         for i in _conv_smb_errors(self.conn.listPath)(self.share, pathdir):
             if i.filename == '..':
                 continue
             elif ((i.filename == '.' and searchpath == '') or
                   i.filename == searchpath):
                 return i
         raise ResourceNotFoundError(path)
コード例 #55
0
    def listdir(self, path='/', wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
        path = normpath(path)
        dirid = self._get_dir_id(path)
        if( dirid == None):
            raise ResourceInvalidError(path)

        dirlist = self._get_dir_list(dirid, path,full)
        if( dirs_only):
            pathlist = dirlist
        else:
            filelist = self._get_file_list(path, full)

            if( files_only == True):
                pathlist = filelist
            else:
                pathlist = filelist + dirlist


        if( wildcard and dirs_only == False):
            pass

        if( absolute == False):
            pathlist = map(lambda dpath:frombase(path,dpath), pathlist)

        return(pathlist)
コード例 #56
0
 def _decode(self, path):
     path = relpath(normpath(path))
     path = path.replace("__colon__", ":")
     if not self.allow_autorun:
         if path.lower().startswith("autorun."):
             path = "_" + path
     return path
コード例 #57
0
ファイル: sqlitefs.py プロジェクト: Liryna/pyfilesystem
    def listdir(self, path='/', wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
        path = normpath(path)
        dirid = self._get_dir_id(path)
        if( dirid == None):
            raise ResourceInvalidError(path)

        dirlist = self._get_dir_list(dirid, path,full)
        if( dirs_only):
            pathlist = dirlist
        else:
            filelist = self._get_file_list(path, full)

            if( files_only == True):
                pathlist = filelist
            else:
                pathlist = filelist + dirlist


        if( wildcard and dirs_only == False):
            pass

        if( absolute == False):
            pathlist = map(lambda dpath:frombase(path,dpath), pathlist)

        return(pathlist)
コード例 #58
0
ファイル: __init__.py プロジェクト: dmitry-viskov/smbfs
 def getsize(self, path):
     try:
         path = normpath(path)
         st = self.conn.stat(self.smb_path(path))
         return st[stat.ST_SIZE]
     except smbc.NoEntryError:
         raise ResourceNotFoundError(path)
コード例 #59
0
ファイル: ftpfs.py プロジェクト: atty303/pyfilesystem
    def _readdir(self, path):
        path = abspath(normpath(path))
        if self.dircache.count:
            cached_dirlist = self.dircache.get(path)
            if cached_dirlist is not None:
                return cached_dirlist
        dirlist = {}

        parser = FTPListDataParser()

        def on_line(line):
            if not isinstance(line, unicode):
                line = line.decode('utf-8')                
            info = parser.parse_line(line)
            if info:
                info = info.__dict__
                if info['name'] not in ('.', '..'):
                    dirlist[info['name']] = info
        try:
            self.ftp.dir(_encode(path), on_line)
        except error_reply:
            pass
        self.dircache[path] = dirlist

        return dirlist