Exemplo n.º 1
0
Arquivo: fs.py Projeto: licshire/xnote
    def list_directory(self, path):
        try:
            if xutils.is_windows() and path == "/":
                # return self.list_win_drives()
                filelist = get_win_drives()
            else:
                filelist = list_abs_dir(path)
        except OSError:
            return "No permission to list directory"

        # filelist中路径均不带/
        # 排序:文件夹优先,按字母顺序排列
        # filelist.sort(key=lambda a: a.lower())
        # filelist.sort(key=lambda a: not os.path.isdir(os.path.join(path,a)))
        filelist = [FileItem(item) for item in filelist]
        filelist.sort()

        # SAE上遇到中文出错
        # Fix bad filenames,修改不生效
        # filelist = list(map(lambda x: xutils.decode_bytes(x.encode("utf-8", errors='surrogateescape')), filelist))

        # Fix, some `file` in *nix is not file either directory. os.stat方法报错
        path = path.replace("\\", "/")
        kw = get_filesystem_kw()
        kw["filelist"] = filelist
        kw["path"] = path
        kw["fspathlist"] = xutils.splitpath(path)
        kw["token"] = xauth.get_current_user().token

        return xtemplate.render("fs/fs.html", **kw)
Exemplo n.º 2
0
Arquivo: fs.py Projeto: ydx2099/xnote
def process_file_list(pathlist, parent=None):
    filelist = [FileItem(fpath, parent, merge=True) for fpath in pathlist]
    for item in filelist:
        assemble_file_object(item)

    filelist.sort()
    return filelist
Exemplo n.º 3
0
Arquivo: fs.py Projeto: licshire/xnote
def getpathlist2(path):
    if not path.endswith("/"):
        path += "/"
    pathsplit = path.split("/")
    pathlist = []
    for i in range(len(pathsplit)):
        path = "/".join(pathsplit[:i])
        if "" != os.path.basename(path):
            # pathlist.append(path)
            pathlist.append(FileItem(path))
    return pathlist
Exemplo n.º 4
0
    def list_directory(self, path):
        try:
            if xutils.is_windows() and path == "/":
                # return self.list_win_drives()
                filelist = get_win_drives()
            else:
                filelist = list_abs_dir(path)
        except OSError:
            return xtemplate.render("fs/fs.html",
                                    show_aside=True,
                                    path=path,
                                    filelist=[],
                                    error="No permission to list directory")

        # filelist中路径均不带/
        # 排序:文件夹优先,按字母顺序排列
        # filelist.sort(key=lambda a: a.lower())
        # filelist.sort(key=lambda a: not os.path.isdir(os.path.join(path,a)))
        filelist = [FileItem(item) for item in filelist]
        filelist.sort()

        # SAE上遇到中文出错
        # Fix bad filenames,修改不生效
        # filelist = list(map(lambda x: xutils.decode_bytes(x.encode("utf-8", errors='surrogateescape')), filelist))
        # Fix, some `file` in *nix is not file either directory. os.stat方法报错
        path = path.replace("\\", "/")
        kw = get_filesystem_kw()
        kw["filelist"] = filelist
        kw["path"] = path
        kw["token"] = xauth.get_current_user().token
        kw["parent_path"] = get_parent_path(path)
        kw["search_action"] = "/fs_find"
        kw["show_aside"] = True

        mode = xutils.get_argument("mode", xconfig.FS_VIEW_MODE)
        kw["fs_mode"] = mode
        if mode == "grid":
            return xtemplate.render("fs/fs_grid.html", **kw)
        elif mode == "shell":
            return xtemplate.render("fs/fs_shell.html", **kw)
        elif mode == "sidebar":
            kw["show_aside"] = False
            return xtemplate.render("fs/fs_sidebar.html", **kw)
        else:
            return xtemplate.render("fs/fs.html", **kw)
Exemplo n.º 5
0
def process_file_list(pathlist, parent=None):
    filelist = [FileItem(fpath, parent, merge=True) for fpath in pathlist]
    for item in filelist:
        item.encoded_path = xutils.encode_uri_component(item.path)
        item.icon = "fa-file-o"

        if item.type == "dir":
            item.icon = "fa-folder orange"
        elif item.ext in xconfig.FS_VIDEO_EXT_LIST:
            item.icon = "fa-file-video-o"
        elif item.ext in xconfig.FS_CODE_EXT_LIST:
            item.icon = "fa-file-code-o"
        elif item.ext in xconfig.FS_AUDIO_EXT_LIST:
            item.icon = "fa-file-audio-o"
        elif item.ext in xconfig.FS_ZIP_EXT_LIST:
            item.icon = "fa-file-zip-o"
        elif xutils.is_text_file(item.path):
            item.icon = "fa-file-text-o"
        elif xutils.is_img_file(item.path):
            item.icon = "fa-file-image-o"

    filelist.sort()
    return filelist
Exemplo n.º 6
0
Arquivo: fs.py Projeto: ydx2099/xnote
def get_parent_file_object(fpath):
    fpath = os.path.abspath(fpath)
    parent_path = os.path.dirname(fpath)
    file_object = FileItem(parent_path)
    file_object.name = u"[上级目录]"
    return assemble_file_object(file_object)