Exemple #1
0
    def read(self, path, size, offset, fh=None):
        path_split = path.split('/')
        path_len = len(path_split)

        if path_split[1] == 'r' and path_len >= 4:
            # Get the post or comment
            post_id = path_split[-2].split(' ')[-1]
            post = reddit.get_submission(submission_id=post_id)

            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_sub_content(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_submission(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'thumbnail' and post.thumbnail != '' and \
                    post.thumbnail != 'self':
                f = urllib2.urlopen(post.thumbnail)
                if f.getcode() == 200:
                    formatted = f.read
            return formatted[offset:offset+size]
        if path.split('/')[1] == 'u':
            # TODO user handling
            pass

        return -errno.ENOSYS
Exemple #2
0
    def read(self, path, size, offset, fh=None):
        path_split = path.split('/')
        path_len = len(path_split)

        if path_split[1] == 'r' and path_len >= 4:
            # Get the post or comment
            post_id = path_split[-2].split(' ')[-1]
            post = reddit.get_submission(submission_id=post_id)

            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_sub_content(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_submission(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'thumbnail' and post.thumbnail != '' and \
                    post.thumbnail != 'self':
                f = urllib2.urlopen(post.thumbnail)
                if f.getcode() == 200:
                    formatted = f.read
            return formatted[offset:offset + size]
        if path.split('/')[1] == 'u':
            # TODO user handling
            pass

        return -errno.ENOSYS
Exemple #3
0
    def read(self, path, size, offset, fh=None):
        """
        Is used to get contents of posts, comments, etc from reddit to the end
        user.
        """
        path_split = path.split('/')
        path_len = len(path_split)

        if path_split[1] == 'r' and path_len == 5:
            # Get the post
            post_id = path_split[3].split(' ')[-1]
            post = reddit.get_submission(submission_id=post_id)

            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_sub_content(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_submission(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif (path_split[-1] == 'thumbnail' and post.thumbnail != ''
                  and post.thumbnail != 'self'
                  and post.thumbnail != 'default'):
                f = urllib2.urlopen(post.thumbnail)
                if f.getcode() == 200:
                    formatted = f.read()
            elif path_split[-1] == 'raw_content' and post.selftext:
                formatted = post.selftext.encode('ascii', 'ignore')
            elif path_split[-1] == 'raw_content' and post.url:
                formatted = post.url.encode('ascii', 'ignore')
            elif path_split[-1] == 'link_content' and post.url:
                f = urllib2.urlopen(post.url)
                if f.getcode() == 200:
                    formatted = f.read()
            return formatted[offset:offset + size]
        elif path_split[1] == 'r' and path_len > 5:
            # Get the comment
            post = get_comment_obj(path)
            if path_split[-1] == 'content':
                formatted = format.format_comment(post, recursive=False)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_comment(post, recursive=True)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'raw_content':
                formatted = post.body.encode('ascii', 'ignore')
            return formatted[offset:offset + size]

        return -errno.ENOSYS
Exemple #4
0
    def read(self, path, size, offset, fh=None):
        """
        Is used to get contents of posts, comments, etc from reddit to the end
        user.
        """
        path_split = path.split('/')
        path_len = len(path_split)

        if path_split[1] == 'r' and path_len == 5:
            # Get the post
            post_id = path_split[3].split(' ')[-1]
            post = reddit.get_submission(submission_id=post_id)

            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_sub_content(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_submission(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif (path_split[-1] == 'thumbnail' and post.thumbnail != '' and
                    post.thumbnail != 'self' and post.thumbnail != 'default'):
                f = urllib2.urlopen(post.thumbnail)
                if f.getcode() == 200:
                    formatted = f.read()
            elif path_split[-1] == 'raw_content' and post.selftext:
                formatted = post.selftext.encode('ascii', 'ignore')
            elif path_split[-1] == 'raw_content' and post.url:
                formatted = post.url.encode('ascii', 'ignore')
            elif path_split[-1] == 'link_content' and post.url:
                f = urllib2.urlopen(post.url)
                if f.getcode() == 200:
                    formatted = f.read()
            return formatted[offset:offset+size]
        elif path_split[1] == 'r' and path_len > 5:
            # Get the comment
            post = get_comment_obj(path)
            if path_split[-1] == 'content':
                formatted = format.format_comment(post, recursive=False)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_comment(post, recursive=True)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'raw_content':
                formatted = post.body.encode('ascii', 'ignore')
            return formatted[offset:offset+size]

        return -errno.ENOSYS
Exemple #5
0
    def getattr(self, path):
        """
        Returns stat info for file, such as permissions and access times.
        """

        # default nlink and time info
        st = fuse.Stat()
        st.st_nlink = 2
        st.st_atime = int(time.time())
        st.st_mtime = st.st_atime
        st.st_ctime = st.st_atime

        # everything defaults to being a normal file unless explicitly set
        # otherwise
        st.st_mode = stat.S_IFREG | 0444

        # useful information
        path_split = path.split('/')
        path_len = len(path_split)

        # "." and ".."
        if path_split[-1] == '.' or path_split[-1] == '..':
            # . and ..
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # top-level directories
        if path in ['/', '/u', '/r']:
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/ - subreddits
        if path_split[1] == 'r' and path_len == 3:
            # check for .sub directories for subscribing
            if reddit.is_logged_in():
                if path.split('/')[-1:][0][-4:] == '.sub':
                    my_subs = [
                        sub.display_name.lower()
                        for sub in reddit.get_my_subreddits()
                    ]
                    if (path.split('/')[-1:][0][:-4]).lower() not in my_subs:
                        st = -2
                    else:
                        st.st_mode = stat.S_IFDIR | 0555
                else:
                    st.st_mode = stat.S_IFDIR | 0555
            else:
                # normal subreddit
                st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/* - submissions
        if path_split[1] == 'r' and path_len == 4:
            if path_split[-1] == 'post':
                # file to post a submission
                st.st_mode = stat.S_IFREG | 0666
            else:
                # submission
                st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/*/[vote, etc] - content stuff in submission
        if (path_split[1] == 'r' and path_len == 5
                and path_split[-1] in content_stuff):
            st.st_mode = stat.S_IFREG | 0444
            post_id = path_split[3].split(' ')[-1]
            post = reddit.get_submission(submission_id=post_id)
            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_sub_content(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_submission(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif (path_split[-1] == 'thumbnail' and 'thumbnail' in dir(post)
                  and post.thumbnail != '' and post.thumbnail != 'self'
                  and post.thumbnail != 'default'):
                f = urllib2.urlopen(post.thumbnail)
                if f.getcode() == 200:
                    formatted = f.read()
            elif path_split[-1] == 'reply':
                st.st_mode = stat.S_IFREG | 0666
            elif path_split[-1] == 'raw_content' and post.selftext:
                st.st_mode = stat.S_IFREG | 0666
                formatted = post.selftext.encode('ascii', 'ignore')
            elif path_split[-1] == 'raw_content' and post.url:
                st.st_mode = stat.S_IFREG | 0666
                formatted = post.url.encode('ascii', 'ignore')
            elif path_split[-1] == 'link_content' and post.url:
                f = urllib2.urlopen(post.url)
                if f.getcode() == 200:
                    formatted = f.read()
            st.st_size = len(formatted)
            return st

        # r/*/*/** - comment post
        if (path_split[1] == 'r' and path_len > 4
                and path_split[-1] not in content_stuff
                and path.split('/')[-1:][0][-1:] != '_'):
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # user link
        if (path_split[1] == 'r' and path_len > 4
                and path_split[-1] not in content_stuff
                and path.split('/')[-1:][0][-1:] == '_'):
            st.st_mode = stat.S_IFLNK | 0777
            return st

        # r/*/*/** - comment directory
        if (path_split[1] == 'r' and path_len > 5
                and path_split[-1] not in content_stuff):
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/*/** - comment stuff
        if (path_split[1] == 'r' and path_len > 5
                and path_split[-1] in content_stuff):
            st.st_mode = stat.S_IFREG | 0444
            post = get_comment_obj(path)
            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_comment(post, recursive=False)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_comment(post, recursive=True)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'reply':
                st.st_mode = stat.S_IFREG | 0666
            elif path_split[-1] == 'raw_content':
                st.st_mode = stat.S_IFREG | 0666
                formatted = post.body.encode('ascii', 'ignore')
            st.st_size = len(formatted)
            return st

        # u/* - user
        if path_split[1] == 'u' and path_len == 3:
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # u/*/* - user stuff (comments, submitted, etc)
        if path_split[1] == 'u' and path_len == 4:
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # u/*/*/* - links (comment, submitted, etc)
        elif (path_split[1] == 'u' and path_len == 5):
            st.st_mode = stat.S_IFLNK | 0777
            return st
Exemple #6
0
    def getattr(self, path):
        """
        Returns stat info for file, such as permissions and access times.
        """

        # default nlink and time info
        st = fuse.Stat()
        st.st_nlink = 2
        st.st_atime = int(time.time())
        st.st_mtime = st.st_atime
        st.st_ctime = st.st_atime

        # everything defaults to being a normal file unless explicitly set
        # otherwise
        st.st_mode = stat.S_IFREG | 0444

        # useful information
        path_split = path.split('/')
        path_len = len(path_split)

        # "." and ".."
        if path_split[-1] == '.' or path_split[-1] == '..':
            # . and ..
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # top-level directories
        if path in ['/', '/u', '/r']:
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/ - subreddits
        if path_split[1] == 'r' and path_len == 3:
            # check for .sub directories for subscribing
            if reddit.is_logged_in():
                if path.split('/')[-1:][0][-4:] == '.sub':
                    my_subs = [sub.display_name.lower() for sub in
                               reddit.get_my_subreddits()]
                    if (path.split('/')[-1:][0][:-4]).lower() not in my_subs:
                        st = -2
                    else:
                        st.st_mode = stat.S_IFDIR | 0555
                else:
                    st.st_mode = stat.S_IFDIR | 0555
            else:
                # normal subreddit
                st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/* - submissions
        if path_split[1] == 'r' and path_len == 4:
            if path_split[-1] == 'post':
                # file to post a submission
                st.st_mode = stat.S_IFREG | 0666
            else:
                # submission
                st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/*/[vote, etc] - content stuff in submission
        if (path_split[1] == 'r' and path_len == 5 and path_split[-1] in
                content_stuff):
            st.st_mode = stat.S_IFREG | 0444
            post_id = path_split[3].split(' ')[-1]
            post = reddit.get_submission(submission_id=post_id)
            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_sub_content(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_submission(post)
                formatted = formatted.encode('ascii', 'ignore')
            elif (path_split[-1] == 'thumbnail' and 'thumbnail' in dir(post)
                    and post.thumbnail != '' and post.thumbnail != 'self'
                    and post.thumbnail != 'default'):
                f = urllib2.urlopen(post.thumbnail)
                if f.getcode() == 200:
                    formatted = f.read()
            elif path_split[-1] == 'reply':
                st.st_mode = stat.S_IFREG | 0666
            elif path_split[-1] == 'raw_content' and post.selftext:
                st.st_mode = stat.S_IFREG | 0666
                formatted = post.selftext.encode('ascii', 'ignore')
            elif path_split[-1] == 'raw_content' and post.url:
                st.st_mode = stat.S_IFREG | 0666
                formatted = post.url.encode('ascii', 'ignore')
            elif path_split[-1] == 'link_content' and post.url:
                f = urllib2.urlopen(post.url)
                if f.getcode() == 200:
                    formatted = f.read()
            st.st_size = len(formatted)
            return st

        # r/*/*/** - comment post
        if (path_split[1] == 'r' and path_len > 4 and path_split[-1] not in
                content_stuff and path.split('/')[-1:][0][-1:] != '_'):
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # user link
        if (path_split[1] == 'r' and path_len > 4 and path_split[-1] not in
                content_stuff and path.split('/')[-1:][0][-1:] == '_'):
            st.st_mode = stat.S_IFLNK | 0777
            return st

        # r/*/*/** - comment directory
        if (path_split[1] == 'r' and path_len > 5 and path_split[-1] not in
                content_stuff):
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # r/*/*/** - comment stuff
        if (path_split[1] == 'r' and path_len > 5 and path_split[-1] in
                content_stuff):
            st.st_mode = stat.S_IFREG | 0444
            post = get_comment_obj(path)
            formatted = ''
            if path_split[-1] == 'content':
                formatted = format.format_comment(post, recursive=False)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'votes':
                formatted = str(post.score) + '\n'
            elif path_split[-1] == 'flat':
                formatted = format.format_comment(post, recursive=True)
                formatted = formatted.encode('ascii', 'ignore')
            elif path_split[-1] == 'reply':
                st.st_mode = stat.S_IFREG | 0666
            elif path_split[-1] == 'raw_content':
                st.st_mode = stat.S_IFREG | 0666
                formatted = post.body.encode('ascii', 'ignore')
            st.st_size = len(formatted)
            return st

        # u/* - user
        if path_split[1] == 'u' and path_len == 3:
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # u/*/* - user stuff (comments, submitted, etc)
        if path_split[1] == 'u' and path_len == 4:
            st.st_mode = stat.S_IFDIR | 0555
            return st

        # u/*/*/* - links (comment, submitted, etc)
        elif (path_split[1] == 'u' and path_len == 5):
            st.st_mode = stat.S_IFLNK | 0777
            return st