Пример #1
0
def get_by_path(raw_path):
    try:
        result = split_path(raw_path, path_resolver)
        (parent_clause, path, filename, mime_type, is_hidden) = result
    except:
        print("Could not process file-path [%s]." % (raw_path))
        exit()

    filepath = build_filepath(path, filename)

    path_relations = PathRelations.get_instance()

    try:
        entry_clause = path_relations.get_clause_from_path(filepath)
    except GdNotFoundError:
        print("Could not retrieve clause for non-existent file-path [%s]." %
              (filepath))
        exit()
    except:
        print("Could not retrieve clause for path [%s]. " % (filepath))
        exit()

    if not entry_clause:
        print("Path [%s] does not exist for stat()." % (filepath))
        exit()

    return entry_clause[CLAUSE_ENTRY]
Пример #2
0
    def __get_entry_or_raise(self, raw_path):
        try:
            result = split_path(raw_path, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except:
            self.__log.exception("Could not process file-path [%s]." %
                                 (raw_path))
            raise FuseOSError(EIO)

        filepath = build_filepath(path, filename)
        path_relations = PathRelations.get_instance()

        try:
            entry_clause = path_relations.get_clause_from_path(filepath)
        except GdNotFoundError:
            self.__log.exception("Could not retrieve clause for non-existent "
                                 "file-path [%s]." % (filepath))
            raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not retrieve clause for path [%s]. " %
                                 (filepath))
            raise FuseOSError(EIO)

        if not entry_clause:
            self.__log.debug("Path [%s] does not exist for stat()." %
                             (filepath))
            raise FuseOSError(ENOENT)

        return (entry_clause[CLAUSE_ENTRY], path, filename)
Пример #3
0
def get_by_path(raw_path):
    try:
        result = split_path(raw_path, path_resolver)
        (parent_clause, path, filename, mime_type, is_hidden) = result
    except:
        print("Could not process file-path [%s]." % (raw_path))
        exit()

    filepath = build_filepath(path, filename)
    
    path_relations = PathRelations.get_instance()

    try:
        entry_clause = path_relations.get_clause_from_path(filepath)
    except GdNotFoundError:
        print("Could not retrieve clause for non-existent file-path [%s]." % 
              (filepath))
        exit()
    except:
        print("Could not retrieve clause for path [%s]. " % (filepath))
        exit()

    if not entry_clause:
        print("Path [%s] does not exist for stat()." % (filepath))
        exit()

    return entry_clause[CLAUSE_ENTRY]
Пример #4
0
    def __create(self, filepath, mode=None):
        """Create a new file.
                
        We don't implement "mode" (permissions) because the model doesn't agree 
        with GD.
        """

# TODO: Fail if it already exists.

        try:
            result = split_path(filepath, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            _logger.exception("Could not process [%s] (i-create).", filepath)
            raise FuseOSError(ENOENT)
        except:
            _logger.exception("Could not split path [%s] (i-create).",
                              filepath)
            raise FuseOSError(EIO)

        distilled_filepath = build_filepath(path, filename)

        # Try to guess at a mime-type, if not otherwise given.
        if mime_type is None:
            (mimetype_guess, _) = guess_type(filename, True)
            
            if mimetype_guess is not None:
                mime_type = mimetype_guess
            else:
                mime_type = Conf.get('default_mimetype')

        gd = get_gdrive()

        try:
            entry = gd.create_file(
                        filename, 
                        [parent_clause[3]], 
                        mime_type,
                        is_hidden=is_hidden)
        except:
            _logger.exception("Could not create empty file [%s] under "
                              "parent with ID [%s].",
                              filename, parent_clause[3])

            raise FuseOSError(EIO)

        path_relations = PathRelations.get_instance()

        try:
            path_relations.register_entry(entry)
        except:
            _logger.exception("Could not register created file in cache.")
            raise FuseOSError(EIO)

        _logger.info("Inner-create of [%s] completed.", distilled_filepath)

        return (entry, path, filename, mime_type)
Пример #5
0
    def __create(self, filepath, mode=None):
        """Create a new file.
                
        We don't implement "mode" (permissions) because the model doesn't agree 
        with GD.
        """

        # TODO: Fail if it already exists.

        try:
            result = split_path(filepath, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            _logger.exception("Could not process [%s] (i-create).", filepath)
            raise FuseOSError(ENOENT)
        except:
            _logger.exception("Could not split path [%s] (i-create).",
                              filepath)
            raise FuseOSError(EIO)

        distilled_filepath = build_filepath(path, filename)

        # Try to guess at a mime-type, if not otherwise given.
        if mime_type is None:
            (mimetype_guess, _) = guess_type(filename, True)

            if mimetype_guess is not None:
                mime_type = mimetype_guess
            else:
                mime_type = Conf.get('default_mimetype')

        gd = get_gdrive()

        try:
            entry = gd.create_file(filename, [parent_clause[3]],
                                   mime_type,
                                   is_hidden=is_hidden)
        except:
            _logger.exception(
                "Could not create empty file [%s] under "
                "parent with ID [%s].", filename, parent_clause[3])

            raise FuseOSError(EIO)

        path_relations = PathRelations.get_instance()

        try:
            path_relations.register_entry(entry)
        except:
            _logger.exception("Could not register created file in cache.")
            raise FuseOSError(EIO)

        _logger.info("Inner-create of [%s] completed.", distilled_filepath)

        return (entry, path, filename, mime_type)
Пример #6
0
    def __create(self, filepath, mode=None):
        """Create a new file.
                
        We don't implement "mode" (permissions) because the model doesn't agree 
        with GD.
        """

# TODO: Fail if it already exists.

        try:
            result = split_path(filepath, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            _logger.exception("Could not process [%s] (i-create).", filepath)
            raise FuseOSError(ENOENT)
        except:
            _logger.exception("Could not split path [%s] (i-create).",
                              filepath)
            raise FuseOSError(EIO)

        if mime_type is None:
            _, ext = os.path.splitext(filename)
            if ext != '':
                ext = ext[1:]

            mime_type = utility.get_first_mime_type_by_extension(ext)

        distilled_filepath = build_filepath(path, filename)

        gd = get_gdrive()

        try:
            entry = gd.create_file(
                        filename, 
                        [parent_clause[3]], 
                        mime_type,
                        is_hidden=is_hidden)
        except:
            _logger.exception("Could not create empty file [%s] under "
                              "parent with ID [%s].",
                              filename, parent_clause[3])

            raise FuseOSError(EIO)

        path_relations = PathRelations.get_instance()

        try:
            path_relations.register_entry(entry)
        except:
            _logger.exception("Could not register created file in cache.")
            raise FuseOSError(EIO)

        _logger.info("Inner-create of [%s] completed.", distilled_filepath)

        return (entry, path, filename, mime_type)
Пример #7
0
    def __create(self, filepath, mode=None):
        """Create a new file.
                
        We don't implement "mode" (permissions) because the model doesn't agree 
        with GD.
        """

        # TODO: Fail if it already exists.

        try:
            result = split_path(filepath, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            _logger.exception("Could not process [%s] (i-create).", filepath)
            raise FuseOSError(ENOENT)
        except:
            _logger.exception("Could not split path [%s] (i-create).",
                              filepath)
            raise FuseOSError(EIO)

        if mime_type is None:
            _, ext = os.path.splitext(filename)
            if ext != '':
                ext = ext[1:]

            mime_type = utility.get_first_mime_type_by_extension(ext)

        distilled_filepath = build_filepath(path, filename)

        gd = get_gdrive()

        try:
            entry = gd.create_file(filename, [parent_clause[3]],
                                   mime_type,
                                   is_hidden=is_hidden)
        except:
            _logger.exception(
                "Could not create empty file [%s] under "
                "parent with ID [%s].", filename, parent_clause[3])

            raise FuseOSError(EIO)

        path_relations = PathRelations.get_instance()

        try:
            path_relations.register_entry(entry)
        except:
            _logger.exception("Could not register created file in cache.")
            raise FuseOSError(EIO)

        _logger.info("Inner-create of [%s] completed.", distilled_filepath)

        return (entry, path, filename, mime_type)
Пример #8
0
    def __get_entry_or_raise(self, raw_path, allow_normal_for_missing=False):
        try:
            result = split_path(raw_path, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            self.__log.exception("Could not retrieve clause for non-existent "
                                 "file-path [%s] (parent does not exist)." % 
                                 (raw_path))

            if allow_normal_for_missing is True:
                raise
            else:
                raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not process file-path [%s]." % 
                                 (raw_path))
            raise FuseOSError(EIO)

        filepath = build_filepath(path, filename)
        path_relations = PathRelations.get_instance()

        try:
            entry_clause = path_relations.get_clause_from_path(filepath)
        except GdNotFoundError:
            self.__log.exception("Could not retrieve clause for non-existent "
                                 "file-path [%s] (parent exists)." % 
                                 (filepath))

            if allow_normal_for_missing is True:
                raise
            else:
                raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not retrieve clause for path [%s]. " %
                                 (filepath))
            raise FuseOSError(EIO)

        if not entry_clause:
            self.__log.debug("Path [%s] does not exist for stat()." % (filepath))

            if allow_normal_for_missing is True:
                raise GdNotFoundError()
            else:
                raise FuseOSError(ENOENT)

        return (entry_clause[CLAUSE_ENTRY], path, filename)
Пример #9
0
def get_entry_or_raise(raw_path, allow_normal_for_missing=False):
    try:
        result = split_path(raw_path, path_resolver)
        (parent_clause, path, filename, mime_type, is_hidden) = result
    except GdNotFoundError:
        _logger.exception("Could not retrieve clause for non-existent "
                          "file-path [%s] (parent does not exist)." %
                          (raw_path))

        if allow_normal_for_missing is True:
            raise
        else:
            raise FuseOSError(ENOENT)
    except:
        _logger.exception("Could not process file-path [%s]." % (raw_path))
        raise FuseOSError(EIO)

    filepath = build_filepath(path, filename)
    path_relations = PathRelations.get_instance()

    try:
        entry_clause = path_relations.get_clause_from_path(filepath)
    except GdNotFoundError:
        _logger.exception("Could not retrieve clause for non-existent "
                          "file-path [%s] (parent exists)." % (filepath))

        if allow_normal_for_missing is True:
            raise
        else:
            raise FuseOSError(ENOENT)
    except:
        _logger.exception("Could not retrieve clause for path [%s]. " %
                          (filepath))
        raise FuseOSError(EIO)

    if not entry_clause:
        if allow_normal_for_missing is True:
            raise GdNotFoundError()
        else:
            raise FuseOSError(ENOENT)

    return (entry_clause[CLAUSE_ENTRY], path, filename)
Пример #10
0
    def __create(self, filepath, mode=None):
        """Create a new file.
                
        We don't implement "mode" (permissions) because the model doesn't agree 
        with GD.
        """
# TODO: Fail if it already exists.

        self.__log.debug("Splitting file-path [%s] for inner create." % 
                         (filepath))

        try:
            result = split_path(filepath, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            self.__log.exception("Could not process [%s] (i-create).")
            raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not split path [%s] (i-create)." % 
                              (filepath))
            raise FuseOSError(EIO)

        distilled_filepath = build_filepath(path, filename)

        self.__log.debug("Acquiring file-handle.")

        # Try to guess at a mime-type, if not otherwise given.
        if mime_type is None:
            (mimetype_guess, _) = guess_type(filename, True)
            
            if mimetype_guess is not None:
                mime_type = mimetype_guess
            else:
                mime_type = Conf.get('default_mimetype')

        self.__log.debug("Creating empty file [%s] under parent with ID "
                         "[%s]." % (filename, parent_clause[3]))

        try:
            entry = drive_proxy('create_file', filename=filename, 
                                data_filepath='/dev/null', 
                                parents=[parent_clause[3]], 
                                mime_type=mime_type,
                                is_hidden=is_hidden)
        except:
            self.__log.exception("Could not create empty file [%s] under "
                                 "parent with ID [%s]." % (filename, 
                                                           parent_clause[3]))
            raise FuseOSError(EIO)

        self.__log.debug("Registering created file in cache.")

        path_relations = PathRelations.get_instance()

        try:
            path_relations.register_entry(entry)
        except:
            self.__log.exception("Could not register created file in cache.")
            raise FuseOSError(EIO)

        self.__log.info("Inner-create of [%s] completed." % 
                        (distilled_filepath))

        return (entry, path, filename, mime_type)
Пример #11
0
def create_for_existing_filepath(filepath):
    """Process the file/path that was requested (potential export-type 
    directive, dot-prefix, etc..), and build an opened-file object using 
    the information.
    """

    _logger.debug("Creating OpenedFile for [%s].", filepath)

    # Process/distill the requested file-path.

    try:
        result = split_path(filepath, path_resolver)
    except GdNotFoundError:
        _logger.exception("Could not process [%s] (create_for_requested).",
                          filepath)

        raise fuse.FuseOSError(ENOENT)

    (parent_clause, path, filename, mime_type, is_hidden) = result
    distilled_filepath = build_filepath(path, filename)

    # Look-up the requested entry.

    path_relations = PathRelations.get_instance()

    try:
        entry_clause = path_relations.get_clause_from_path(
                        distilled_filepath)
    except:
        _logger.exception("Could not try to get clause from path [%s] "
                          "(OpenedFile).", distilled_filepath)

        raise fuse.FuseOSError(EIO)

    if not entry_clause:
        _logger.debug("Path [%s] does not exist for stat().", path)
        raise fuse.FuseOSError(ENOENT)

    entry = entry_clause[CLAUSE_ENTRY]

    # Normalize the mime-type by considering what's available for download. 
    # We're going to let the requests that didn't provide a mime-type fail 
    # right here. It will give us the opportunity to try a few options to 
    # get the file.

    try:
        final_mimetype = entry.normalize_download_mimetype(mime_type)
    except ExportFormatError:
        _logger.exception("There was an export-format error "
                          "(create_for_requested_filesystem).")

        raise fuse.FuseOSError(ENOENT)
    except:
        _logger.exception("Could not normalize mime-type [%s] for entry"
                          "[%s].", mime_type, entry)

        raise fuse.FuseOSError(EIO)

    if final_mimetype != mime_type:
        _logger.info("Entry being opened will be opened as [%s] rather "
                     "than [%s].", final_mimetype, mime_type)

    # Build the object.

    return OpenedFile(
            entry_clause[CLAUSE_ID], 
            path, 
            filename, 
            is_hidden, 
            final_mimetype)
Пример #12
0
    def file_path(self):
        """The GD filepath of the requested file."""

        return build_filepath(self.__path, self.__filename)
Пример #13
0
 def file_path(self):
     return build_filepath(self.__path, self.__filename)
Пример #14
0
    def file_path(self):
        """The GD filepath of the requested file."""

        return build_filepath(self.__path, self.__filename)
Пример #15
0
    def __create(self, filepath, mode=None):
        """Create a new file.
                
        We don't implement "mode" (permissions) because the model doesn't agree 
        with GD.
        """
        # TODO: Fail if it already exists.

        self.__log.debug("Splitting file-path [%s] for inner create." %
                         (filepath))

        try:
            result = split_path(filepath, path_resolver)
            (parent_clause, path, filename, mime_type, is_hidden) = result
        except GdNotFoundError:
            self.__log.exception("Could not process [%s] (i-create).")
            raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not split path [%s] (i-create)." %
                                 (filepath))
            raise FuseOSError(EIO)

        distilled_filepath = build_filepath(path, filename)

        self.__log.debug("Acquiring file-handle.")

        # Try to guess at a mime-type, if not otherwise given.
        if mime_type is None:
            (mimetype_guess, _) = guess_type(filename, True)

            if mimetype_guess is not None:
                mime_type = mimetype_guess
            else:
                mime_type = Conf.get('default_mimetype')

        self.__log.debug("Creating empty file [%s] under parent with ID "
                         "[%s]." % (filename, parent_clause[3]))

        try:
            entry = drive_proxy('create_file',
                                filename=filename,
                                data_filepath='/dev/null',
                                parents=[parent_clause[3]],
                                mime_type=mime_type,
                                is_hidden=is_hidden)
        except:
            self.__log.exception("Could not create empty file [%s] under "
                                 "parent with ID [%s]." %
                                 (filename, parent_clause[3]))
            raise FuseOSError(EIO)

        self.__log.debug("Registering created file in cache.")

        path_relations = PathRelations.get_instance()

        try:
            path_relations.register_entry(entry)
        except:
            self.__log.exception("Could not register created file in cache.")
            raise FuseOSError(EIO)

        self.__log.info("Inner-create of [%s] completed." %
                        (distilled_filepath))

        return (entry, path, filename, mime_type)
Пример #16
0
 def file_path(self):
     return build_filepath(self.__path, self.__filename)